Correction de plusieurs anomalies : problème de switch entre 2 templates (par exemple si on était sur un template 1 et qu'on voulait passer directement au 2, ce dernier ne chargeait pas) ; correction du soucis d'apparition de la sidebar à gauche qui disparaissait sans explication ; problème de redirection : lorsqu'on terminait de créer un PJ / PNJ ; on arrivait sur l'accueil de la campagne au lieu de voir le résultat de la création. Problème de redirection également lors du clique sur un PNJ / PJ sur le coté : on arrivait sur l'édition au lieu de la présentation. Correction de la première lettre stylisée : tout est au même style comme ça plus de probleme de lecture. Nouveautées : stylisation des modales (notamment suppression, warning.....) avec en prime l'ajout d'un warning lors du changement de système pour avertir que les fiches persos ne sont pas conservées. Ajout d'une option pour créer un game system directement à la création d'une campagne afin de faciliter la mise en place de cette dernière. Ajout d'un bouton pour créer un nouveau template directement lorsqu'on créer une page : ça permet de créer un template et de revenir sur la page qu'on était en train de créer sans perdre le titre. Passage en bêta 0.8.4
162 lines
5.5 KiB
TypeScript
162 lines
5.5 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { LucideAngularModule, Save, ArrowLeft, Drama, Trash2, Sparkles } from 'lucide-angular';
|
|
import { NpcService } from '../../../services/npc.service';
|
|
import { CampaignService } from '../../../services/campaign.service';
|
|
import { GameSystemService } from '../../../services/game-system.service';
|
|
import { CampaignSidebarService } from '../../../services/campaign-sidebar.service';
|
|
import { TemplateField } from '../../../services/template.model';
|
|
import { AiChatDrawerComponent } from '../../../shared/ai-chat-drawer/ai-chat-drawer.component';
|
|
import { DynamicFieldsFormComponent } from '../../../shared/dynamic-fields-form/dynamic-fields-form.component';
|
|
import { SingleImagePickerComponent } from '../../../shared/single-image-picker/single-image-picker.component';
|
|
import { ConfirmDialogService } from '../../../shared/confirm-dialog/confirm-dialog.service';
|
|
|
|
/**
|
|
* Editeur plein ecran d'une fiche de PNJ.
|
|
* Refonte 2026-04-30 : meme principe que CharacterEditComponent — markdown
|
|
* libre remplace par un formulaire dynamique pilote par le npcTemplate du
|
|
* GameSystem associe a la campagne.
|
|
*/
|
|
@Component({
|
|
selector: 'app-npc-edit',
|
|
standalone: true,
|
|
imports: [CommonModule, FormsModule, LucideAngularModule, AiChatDrawerComponent, DynamicFieldsFormComponent, SingleImagePickerComponent],
|
|
templateUrl: './npc-edit.component.html',
|
|
styleUrls: ['./npc-edit.component.scss']
|
|
})
|
|
export class NpcEditComponent implements OnInit {
|
|
readonly Save = Save;
|
|
readonly ArrowLeft = ArrowLeft;
|
|
readonly Drama = Drama;
|
|
readonly Trash2 = Trash2;
|
|
readonly Sparkles = Sparkles;
|
|
|
|
chatOpen = false;
|
|
readonly chatQuickSuggestions = [
|
|
'Propose une apparence et une posture marquantes',
|
|
'Suggere 2 motivations et un secret pour ce PNJ',
|
|
'Imagine 3 repliques signatures qui le caracterisent'
|
|
];
|
|
|
|
toggleChat(): void { this.chatOpen = !this.chatOpen; }
|
|
|
|
campaignId: string | null = null;
|
|
npcId: string | null = null;
|
|
|
|
name = '';
|
|
portraitImageId: string | null = null;
|
|
headerImageId: string | null = null;
|
|
values: Record<string, string> = {};
|
|
imageValues: Record<string, string[]> = {};
|
|
keyValueValues: Record<string, Record<string, string>> = {};
|
|
templateFields: TemplateField[] = [];
|
|
private order = 0;
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private router: Router,
|
|
private service: NpcService,
|
|
private campaignService: CampaignService,
|
|
private gameSystemService: GameSystemService,
|
|
private campaignSidebar: CampaignSidebarService,
|
|
private confirmDialog: ConfirmDialogService
|
|
) {}
|
|
|
|
ngOnInit(): void {
|
|
const params = this.route.snapshot.paramMap;
|
|
this.campaignId = params.get('campaignId');
|
|
this.npcId = params.get('npcId');
|
|
|
|
if (this.campaignId) {
|
|
this.loadTemplateForCampaign(this.campaignId);
|
|
this.campaignSidebar.show(this.campaignId);
|
|
}
|
|
|
|
if (this.npcId) {
|
|
this.service.getById(this.npcId).subscribe({
|
|
next: (n) => {
|
|
this.name = n.name;
|
|
this.portraitImageId = n.portraitImageId ?? null;
|
|
this.headerImageId = n.headerImageId ?? null;
|
|
this.values = n.values ?? {};
|
|
this.imageValues = n.imageValues ?? {};
|
|
this.keyValueValues = n.keyValueValues ?? {};
|
|
this.order = n.order ?? 0;
|
|
},
|
|
error: () => this.back()
|
|
});
|
|
}
|
|
}
|
|
|
|
private loadTemplateForCampaign(campaignId: string): void {
|
|
this.campaignService.getCampaignById(campaignId).subscribe({
|
|
next: (campaign) => {
|
|
if (!campaign.gameSystemId) {
|
|
this.templateFields = [];
|
|
return;
|
|
}
|
|
this.gameSystemService.getById(campaign.gameSystemId).subscribe({
|
|
next: (gs) => { this.templateFields = gs.npcTemplate ?? []; },
|
|
error: () => { this.templateFields = []; }
|
|
});
|
|
},
|
|
error: () => { this.templateFields = []; }
|
|
});
|
|
}
|
|
|
|
|
|
submit(): void {
|
|
if (!this.name.trim() || !this.campaignId) return;
|
|
const payload = {
|
|
name: this.name.trim(),
|
|
portraitImageId: this.portraitImageId,
|
|
headerImageId: this.headerImageId,
|
|
values: this.values,
|
|
imageValues: this.imageValues,
|
|
keyValueValues: this.keyValueValues,
|
|
campaignId: this.campaignId
|
|
};
|
|
const isCreation = !this.npcId;
|
|
const req = this.npcId
|
|
? this.service.update(this.npcId, { ...payload, id: this.npcId, order: this.order })
|
|
: this.service.create(payload);
|
|
req.subscribe({
|
|
next: (saved) => {
|
|
if (isCreation && saved.id) {
|
|
this.router.navigate(['/campaigns', this.campaignId, 'npcs', saved.id]);
|
|
} else {
|
|
this.back();
|
|
}
|
|
},
|
|
error: () => console.error('Erreur sauvegarde Npc')
|
|
});
|
|
}
|
|
|
|
deleteNpc(): void {
|
|
if (!this.npcId) return;
|
|
this.confirmDialog.confirm({
|
|
title: 'Supprimer la fiche ?',
|
|
message: `Supprimer la fiche de "${this.name}" ?`,
|
|
details: ['Cette action est irreversible.'],
|
|
confirmLabel: 'Supprimer',
|
|
variant: 'danger'
|
|
}).then(ok => {
|
|
if (!ok || !this.npcId) return;
|
|
this.service.delete(this.npcId).subscribe({
|
|
next: () => this.back(),
|
|
error: () => console.error('Erreur suppression Npc')
|
|
});
|
|
});
|
|
}
|
|
|
|
back(): void {
|
|
if (this.campaignId) {
|
|
this.router.navigate(['/campaigns', this.campaignId]);
|
|
} else {
|
|
this.router.navigate(['/campaigns']);
|
|
}
|
|
}
|
|
}
|