Co-MJ v1 : quêtes de première classe, guidage de préparation, assistant IA,
Build & Push Images / build (brain) (push) Successful in 1m38s
Build & Push Images / build (web) (push) Successful in 1m53s
Build & Push Images / build (core) (push) Successful in 3m40s
Build & Push Images / build-switcher (push) Successful in 16s

mode séance, battlemaps multiples et export Foundry ciblé

- Quêtes (Niveau 1) : entité Quest orthogonale à l'arbre, rattachée à un arc HUB
  ou libre (migrations V9-V12, V18, V20 ; réconciliation des jumeaux V10).
  Fusion quête/conteneur dans la sidebar, progression par partie (statuts
  disponible/en cours/terminée), et quêtes libres avec espace de scènes créé
  automatiquement (arc technique « Quêtes libres », V21 : levée de la
  contrainte arcs.type héritée du baseline).
- Guidage (Pilier B) : bilan de préparation 100 % dérivé (règles arc/chapitre/
  scène/quête), panneau « Prochaines étapes » avec boutons « Corriger », et
  pastilles détaillées (tooltip des manques) dans l'arbre.
- Assistant IA (Pilier A) : étoffage champ par champ (scène, chapitre, arc) et
  brouillons de scènes en propose→applique (brain : narrative-fields,
  scene-drafts).
- Horloges & menaces (V15-V17) : clocks à segments avec déclencheurs, fronts.
- Mode séance : préparation de séance (readiness + quêtes dispo), scène
  épinglée (V19), récap « précédemment » (brain : session-recap), onglet
  « Partie » du panneau de référence, graphe amélioré (pan/zoom, éditeur de
  liens).
- Perf : endpoint agrégé GET /api/campaigns/{id}/tree — la sidebar charge en
  1 requête au lieu de ~15.
- Battlemaps multiples par scène (variantes jour/nuit, étages…) : liste JSON
  étiquetée (V22, reprise automatique de la carte existante), rendu PDF avec
  légendes, export/import rétro-compatible.
- Export Foundry ciblé : modale de périmètre (cartes+ennemis / journaux /
  tables), bundle filtré côté serveur (zip allégé), module Foundry à jour
  (respect du périmètre + une Scene Foundry par variante de carte,
  rétro-compatible anciens bundles).
This commit is contained in:
2026-07-03 15:29:23 +02:00
parent 268f4721ce
commit b2c3800bf8
278 changed files with 15570 additions and 1451 deletions
@@ -26,93 +26,17 @@
<form [formGroup]="form" (ngSubmit)="submit()" class="edit-form">
<!-- Illustrations (galerie editable, rendu editorial) -->
<div class="field">
<label>{{ 'sceneEdit.illustrationsLabel' | translate }}</label>
<app-image-gallery
[imageIds]="illustrationImageIds"
[editable]="true"
[layout]="'EDITORIAL'"
(imageIdsChange)="illustrationImageIds = $event">
</app-image-gallery>
<small class="field-hint">{{ 'sceneEdit.illustrationsHint' | translate }}</small>
</div>
<!-- Tout est optionnel sauf le titre : on n'affiche que l'identité, le reste
est dans des sections repliables avec pastille « rempli ». -->
<p class="optional-hint">{{ 'sceneEdit.optionalHint' | translate }}</p>
<!-- Battlemap Foundry : selon la source (Dungeon Alchemist = media + .json,
DungeonDraft = .dd2vtt unique). Non affichee dans l'appli (export only). -->
<div class="field">
<label>{{ 'sceneEdit.battlemapLabel' | translate }}</label>
<small class="field-hint">{{ 'sceneEdit.battlemapHint' | translate }}</small>
<div class="battlemap-source" role="group" [attr.aria-label]="'sceneEdit.battlemapSourceLabel' | translate">
<button type="button" [class.active]="battlemapSource === 'DUNGEON_ALCHEMIST'"
(click)="setBattlemapSource('DUNGEON_ALCHEMIST')">
{{ 'sceneEdit.battlemapSourceDA' | translate }}
</button>
<button type="button" [class.active]="battlemapSource === 'DUNGEONDRAFT'"
(click)="setBattlemapSource('DUNGEONDRAFT')">
{{ 'sceneEdit.battlemapSourceDD' | translate }}
</button>
</div>
@if (battlemapSource === 'DUNGEON_ALCHEMIST') {
<div class="battlemap-slot"
appFileDrop [dropDisabled]="battlemapUploadingMedia"
(filesDropped)="onBattlemapMediaDropped($event)">
<span class="battlemap-slot-label">{{ 'sceneEdit.battlemapMedia' | translate }}</span>
@if (battlemapMediaFileId) {
<span class="battlemap-file">{{ battlemapMediaName || ('sceneEdit.battlemapAttached' | translate) }}</span>
<button type="button" class="battlemap-remove" (click)="removeBattlemapMedia()">
{{ 'sceneEdit.battlemapRemove' | translate }}
</button>
} @else {
<label class="battlemap-pick">
{{ (battlemapUploadingMedia ? 'sceneEdit.battlemapUploading' : 'sceneEdit.battlemapChoose') | translate }}
<input type="file" accept="image/*,video/mp4,video/webm" hidden (change)="onBattlemapMediaSelected($event)" />
</label>
}
</div>
<div class="battlemap-slot"
appFileDrop [dropDisabled]="battlemapUploadingData"
(filesDropped)="onBattlemapDataDropped($event)">
<span class="battlemap-slot-label">{{ 'sceneEdit.battlemapData' | translate }}</span>
@if (battlemapDataFileId) {
<span class="battlemap-file">{{ battlemapDataName || ('sceneEdit.battlemapAttached' | translate) }}</span>
<button type="button" class="battlemap-remove" (click)="removeBattlemapData()">
{{ 'sceneEdit.battlemapRemove' | translate }}
</button>
} @else {
<label class="battlemap-pick">
{{ (battlemapUploadingData ? 'sceneEdit.battlemapUploading' : 'sceneEdit.battlemapChoose') | translate }}
<input type="file" accept=".json,.dd2vtt,.uvtt,application/json" hidden (change)="onBattlemapDataSelected($event)" />
</label>
}
</div>
} @else {
<div class="battlemap-slot"
appFileDrop [dropDisabled]="battlemapUploadingData"
(filesDropped)="onDd2vttDropped($event)">
<span class="battlemap-slot-label">{{ 'sceneEdit.battlemapDd2vttSlot' | translate }}</span>
@if (battlemapDataFileId) {
<span class="battlemap-file">{{ battlemapDataName || ('sceneEdit.battlemapAttached' | translate) }}</span>
<button type="button" class="battlemap-remove" (click)="removeDd2vtt()">
{{ 'sceneEdit.battlemapRemove' | translate }}
</button>
} @else {
<label class="battlemap-pick">
{{ (battlemapUploadingData ? 'sceneEdit.battlemapUploading' : 'sceneEdit.battlemapChoose') | translate }}
<input type="file" accept=".dd2vtt,.uvtt,application/json" hidden (change)="onDd2vttSelected($event)" />
</label>
}
</div>
@if (battlemapDd2vttNoImage) {
<small class="field-hint battlemap-warn">{{ 'sceneEdit.battlemapDd2vttNoImage' | translate }}</small>
}
<small class="field-hint">{{ 'sceneEdit.battlemapDd2vttHint' | translate }}</small>
}
</div>
<!-- Co-création (Pilier A) : le co-MJ propose, l'utilisateur valide champ par champ.
Les champs retenus remplissent le formulaire ; rien n'est enregistré avant la sauvegarde. -->
<app-entity-assist-panel
[entityType]="'scene'" [entityId]="sceneId" [campaignId]="campaignId"
(applied)="onAssistApplied($event)"></app-entity-assist-panel>
<!-- Identité -->
<div class="field">
<label for="scene-edit-name">{{ 'sceneEdit.nameLabel' | translate }}</label>
<input
@@ -139,8 +63,122 @@
<app-icon-picker [options]="campaignIconOptions" [(selected)]="selectedIcon"></app-icon-picker>
</div>
<!-- Type narratif du nœud (Niveau 2 — graphe de nœuds typés) -->
<div class="field">
<label for="scene-edit-type">{{ 'sceneEdit.nodeTypeLabel' | translate }}</label>
<select id="scene-edit-type" formControlName="type">
@for (opt of sceneTypeOptions; track opt) {
<option [value]="opt">{{ 'sceneType.' + opt | translate }}</option>
}
</select>
<small class="field-hint">{{ 'sceneEdit.nodeTypeHint' | translate }}</small>
</div>
<!-- Illustrations (galerie editable, rendu editorial) -->
<app-expandable-section [title]="'sceneEdit.illustrationsLabel' | translate" icon="🖼️" [filled]="illustrationsFilled">
<app-image-gallery
[imageIds]="illustrationImageIds"
[editable]="true"
[layout]="'EDITORIAL'"
(imageIdsChange)="illustrationImageIds = $event">
</app-image-gallery>
<small class="field-hint">{{ 'sceneEdit.illustrationsHint' | translate }}</small>
</app-expandable-section>
<!-- Battlemaps Foundry : LISTE de variantes (Jour/Nuit, étages…), chacune selon
sa source (Dungeon Alchemist = media + .json, DungeonDraft = .dd2vtt unique).
Non affichées dans l'appli (export only). -->
<app-expandable-section [title]="'sceneEdit.battlemapLabel' | translate" icon="🗺️" [filled]="battlemapFilled">
<small class="field-hint">{{ 'sceneEdit.battlemapHint' | translate }}</small>
@for (bm of battlemaps; track $index; let i = $index) {
<div class="battlemap-card">
<div class="battlemap-card-head">
<input class="battlemap-label-input" type="text" [value]="bm.label"
(input)="updateBattlemapLabel(i, $any($event.target).value)"
[placeholder]="'sceneEdit.battlemapLabelPlaceholder' | translate" />
<button type="button" class="battlemap-remove" (click)="removeBattlemap(i)">
{{ 'sceneEdit.battlemapRemoveMap' | translate }}
</button>
</div>
<div class="battlemap-source" role="group" [attr.aria-label]="'sceneEdit.battlemapSourceLabel' | translate">
<button type="button" [class.active]="bm.source === 'DUNGEON_ALCHEMIST'"
(click)="setBattlemapSource(bm, 'DUNGEON_ALCHEMIST')">
{{ 'sceneEdit.battlemapSourceDA' | translate }}
</button>
<button type="button" [class.active]="bm.source === 'DUNGEONDRAFT'"
(click)="setBattlemapSource(bm, 'DUNGEONDRAFT')">
{{ 'sceneEdit.battlemapSourceDD' | translate }}
</button>
</div>
@if (bm.source === 'DUNGEON_ALCHEMIST') {
<div class="battlemap-slot"
appFileDrop [dropDisabled]="bm.uploadingMedia"
(filesDropped)="onBattlemapMediaDropped(bm, $event)">
<span class="battlemap-slot-label">{{ 'sceneEdit.battlemapMedia' | translate }}</span>
@if (bm.mediaFileId) {
<span class="battlemap-file">{{ bm.mediaName || ('sceneEdit.battlemapAttached' | translate) }}</span>
<button type="button" class="battlemap-remove" (click)="removeBattlemapMedia(bm)">
{{ 'sceneEdit.battlemapRemove' | translate }}
</button>
} @else {
<label class="battlemap-pick">
{{ (bm.uploadingMedia ? 'sceneEdit.battlemapUploading' : 'sceneEdit.battlemapChoose') | translate }}
<input type="file" accept="image/*,video/mp4,video/webm" hidden (change)="onBattlemapMediaSelected(bm, $event)" />
</label>
}
</div>
<div class="battlemap-slot"
appFileDrop [dropDisabled]="bm.uploadingData"
(filesDropped)="onBattlemapDataDropped(bm, $event)">
<span class="battlemap-slot-label">{{ 'sceneEdit.battlemapData' | translate }}</span>
@if (bm.dataFileId) {
<span class="battlemap-file">{{ bm.dataName || ('sceneEdit.battlemapAttached' | translate) }}</span>
<button type="button" class="battlemap-remove" (click)="removeBattlemapData(bm)">
{{ 'sceneEdit.battlemapRemove' | translate }}
</button>
} @else {
<label class="battlemap-pick">
{{ (bm.uploadingData ? 'sceneEdit.battlemapUploading' : 'sceneEdit.battlemapChoose') | translate }}
<input type="file" accept=".json,.dd2vtt,.uvtt,application/json" hidden (change)="onBattlemapDataSelected(bm, $event)" />
</label>
}
</div>
} @else {
<div class="battlemap-slot"
appFileDrop [dropDisabled]="bm.uploadingData"
(filesDropped)="onDd2vttDropped(bm, $event)">
<span class="battlemap-slot-label">{{ 'sceneEdit.battlemapDd2vttSlot' | translate }}</span>
@if (bm.dataFileId) {
<span class="battlemap-file">{{ bm.dataName || ('sceneEdit.battlemapAttached' | translate) }}</span>
<button type="button" class="battlemap-remove" (click)="removeDd2vtt(bm)">
{{ 'sceneEdit.battlemapRemove' | translate }}
</button>
} @else {
<label class="battlemap-pick">
{{ (bm.uploadingData ? 'sceneEdit.battlemapUploading' : 'sceneEdit.battlemapChoose') | translate }}
<input type="file" accept=".dd2vtt,.uvtt,application/json" hidden (change)="onDd2vttSelected(bm, $event)" />
</label>
}
</div>
@if (bm.dd2vttNoImage) {
<small class="field-hint battlemap-warn">{{ 'sceneEdit.battlemapDd2vttNoImage' | translate }}</small>
}
<small class="field-hint">{{ 'sceneEdit.battlemapDd2vttHint' | translate }}</small>
}
</div>
}
<button type="button" class="battlemap-add" (click)="addBattlemap()">
+ {{ 'sceneEdit.battlemapAdd' | translate }}
</button>
</app-expandable-section>
<!-- Section : Contexte et ambiance -->
<app-expandable-section [title]="'sceneEdit.contextSectionTitle' | translate" icon="📍" [initiallyOpen]="true">
<app-expandable-section [title]="'sceneEdit.contextSectionTitle' | translate" icon="📍" [initiallyOpen]="true" [filled]="contextFilled">
<div class="field-row">
<div class="field">
<label for="scene-edit-location">{{ 'sceneEdit.locationLabel' | translate }}</label>
@@ -163,7 +201,7 @@
</app-expandable-section>
<!-- Section : Narration pour les joueurs -->
<app-expandable-section [title]="'sceneEdit.narrationSectionTitle' | translate" icon="📖">
<app-expandable-section [title]="'sceneEdit.narrationSectionTitle' | translate" icon="📖" [filled]="narrationFilled">
<div class="field">
<textarea
formControlName="playerNarration"
@@ -175,7 +213,7 @@
</app-expandable-section>
<!-- Section : Notes et secrets du MJ (privé) -->
<app-expandable-section [title]="'sceneEdit.gmNotesSectionTitle' | translate" icon="🔒" variant="private">
<app-expandable-section [title]="'sceneEdit.gmNotesSectionTitle' | translate" icon="🔒" variant="private" [filled]="gmNotesFilled">
<div class="field">
<textarea
formControlName="gmSecretNotes"
@@ -187,7 +225,7 @@
</app-expandable-section>
<!-- Section : Choix et conséquences -->
<app-expandable-section [title]="'sceneEdit.choicesSectionTitle' | translate" icon="🔀">
<app-expandable-section [title]="'sceneEdit.choicesSectionTitle' | translate" icon="🔀" [filled]="choicesFilled">
<div class="field">
<textarea
formControlName="choicesConsequences"
@@ -198,7 +236,7 @@
</app-expandable-section>
<!-- Section : Branches narratives (graphe intra-chapitre) -->
<app-expandable-section [title]="'sceneEdit.branchesSectionTitle' | translate" icon="🌿">
<app-expandable-section [title]="'sceneEdit.branchesSectionTitle' | translate" icon="🌿" [initiallyOpen]="focusSection === 'branches'" [filled]="branchesFilled">
@if (siblingScenes.length === 0) {
<div class="branches-hint">
<small class="field-hint">
@@ -221,7 +259,11 @@
</div>
<div class="field">
<label>{{ 'sceneEdit.branchTargetLabel' | translate }}</label>
@if (isBranchTargetBroken(branch)) {
<small class="branch-broken">⚠ {{ 'sceneEdit.branchTargetBroken' | translate }}</small>
}
<select
[class.invalid]="isBranchTargetBroken(branch)"
(change)="updateBranchTarget(i, $any($event.target).value)">
<option value="" [selected]="!branch.targetSceneId">{{ 'sceneEdit.branchTargetPlaceholder' | translate }}</option>
@for (s of siblingScenes; track s) {
@@ -239,6 +281,14 @@
(input)="updateBranchCondition(i, $any($event.target).value)"
[placeholder]="'sceneEdit.branchConditionPlaceholder' | translate" />
</div>
<div class="field">
<label>{{ 'sceneEdit.branchKindLabel' | translate }}</label>
<select (change)="updateBranchKind(i, $any($event.target).value)">
@for (opt of linkTypeOptions; track opt) {
<option [value]="opt" [selected]="opt === (branch.kind || 'EXIT')">{{ 'linkType.' + opt | translate }}</option>
}
</select>
</div>
<button type="button" class="btn-remove-branch" (click)="removeBranch(i)"
[title]="'sceneEdit.branchRemoveTitle' | translate">
<lucide-icon [img]="Trash2" [size]="14"></lucide-icon>
@@ -257,7 +307,7 @@
</app-expandable-section>
<!-- Section : Combat ou rencontre -->
<app-expandable-section [title]="'sceneEdit.combatSectionTitle' | translate" icon="⚔️">
<app-expandable-section [title]="'sceneEdit.combatSectionTitle' | translate" icon="⚔️" [initiallyOpen]="focusSection === 'combat'" [filled]="combatFilled">
<div class="field">
<label for="scene-edit-combat-difficulty">{{ 'sceneEdit.combatDifficultyLabel' | translate }}</label>
<input id="scene-edit-combat-difficulty" type="text" formControlName="combatDifficulty" [placeholder]="'sceneEdit.combatDifficultyPlaceholder' | translate" />
@@ -287,7 +337,7 @@
<!-- Section : Pages Lore associées (B2 cross-context) -->
@if (loreId) {
<app-expandable-section [title]="'sceneEdit.loreSectionTitle' | translate" icon="🔗">
<app-expandable-section [title]="'sceneEdit.loreSectionTitle' | translate" icon="🔗" [filled]="loreFilled">
<div class="field">
<app-lore-link-picker
[value]="relatedPageIds"
@@ -311,7 +361,7 @@
}
<!-- Lieu explorable : pièces / donjon -->
<app-expandable-section [title]="'sceneEdit.dungeonSectionTitle' | translate" icon="🏰" [initiallyOpen]="rooms.length > 0">
<app-expandable-section [title]="'sceneEdit.dungeonSectionTitle' | translate" icon="🏰" [initiallyOpen]="rooms.length > 0 || focusSection === 'rooms'" [filled]="dungeonFilled">
<small class="field-hint">
{{ 'sceneEdit.dungeonHint' | translate }}
</small>
@@ -3,6 +3,57 @@
max-width: 760px;
}
// Carte d'UNE battlemap (variante Jour/Nuit, étage…) : libellé + source + slots.
.battlemap-card {
border: 1px solid #2a2a3d;
border-radius: 8px;
padding: 0.65rem 0.75rem;
margin: 0.6rem 0;
.battlemap-card-head {
display: flex;
align-items: center;
gap: 0.75rem;
.battlemap-label-input {
flex: 1;
background: #1a1a2e;
border: 1px solid #2a2a3d;
border-radius: 6px;
color: inherit;
padding: 0.4rem 0.6rem;
font-size: 0.88rem;
&::placeholder { opacity: 0.55; }
}
.battlemap-remove {
background: none;
border: none;
color: inherit;
opacity: 0.7;
cursor: pointer;
text-decoration: underline;
font-size: 0.85rem;
white-space: nowrap;
}
}
}
// Ajout d'une nouvelle carte à la liste.
.battlemap-add {
background: none;
border: 1px dashed #2a2a3d;
border-radius: 6px;
color: #9ca3af;
padding: 0.45rem 0.8rem;
font-size: 0.85rem;
cursor: pointer;
transition: color 0.15s, border-color 0.15s;
&:hover { color: #d1d5db; border-color: #6c63ff; }
}
// Sélecteur de source de carte (Dungeon Alchemist / DungeonDraft).
.battlemap-source {
display: inline-flex;
@@ -96,6 +147,17 @@
gap: 1.5rem;
}
// Bandeau « tout est optionnel sauf le titre » en tête du formulaire.
.optional-hint {
margin: 0;
padding: 0.6rem 0.85rem;
background: rgba(108, 99, 255, 0.08);
border: 1px solid rgba(108, 99, 255, 0.25);
border-radius: 8px;
color: #a5b4fc;
font-size: 0.85rem;
}
// Override local : bouton Supprimer poussé à droite (voir _buttons.scss pour la base).
.btn-danger {
display: inline-flex;
@@ -122,6 +184,14 @@
gap: 0.75rem;
}
// Destination de branche morte (scène supprimée) : avertissement ambre + select marqué.
.branch-broken {
display: block;
margin-bottom: 0.25rem;
color: #b45309;
font-size: 0.8rem;
}
.btn-add-branch {
align-self: flex-start;
padding: 0.5rem 0.9rem;
@@ -14,7 +14,7 @@ import { EnemyService } from '../../../services/enemy.service';
import { PageService } from '../../../services/page.service';
import { LayoutService } from '../../../services/layout.service';
import { PageTitleService } from '../../../services/page-title.service';
import { Scene, SceneBranch, Room } from '../../../services/campaign.model';
import { Scene, SceneBattlemap, SceneBranch, Room, SceneType, LinkType } from '../../../services/campaign.model';
import { Page } from '../../../services/page.model';
import { Enemy } from '../../../services/enemy.model';
import { loadCampaignTreeData, buildCampaignSidebarConfig } from '../../campaign-tree.helper';
@@ -25,17 +25,44 @@ import { AiChatDrawerComponent } from '../../../shared/ai-chat-drawer/ai-chat-dr
import { ImageGalleryComponent } from '../../../shared/image-gallery/image-gallery.component';
import { IconPickerComponent } from '../../../shared/icon-picker/icon-picker.component';
import { RoomsEditorComponent } from '../../../shared/rooms-editor/rooms-editor.component';
import { EntityAssistPanelComponent } from '../../../shared/entity-assist-panel/entity-assist-panel.component';
import { FieldProposal } from '../../../services/entity-assist.model';
import { FileDropDirective } from '../../../shared/file-drop.directive';
import { CAMPAIGN_ICON_OPTIONS } from '../../campaign-icons';
import { ConfirmDialogService } from '../../../shared/confirm-dialog/confirm-dialog.service';
/**
* État d'édition d'UNE battlemap de la scène (une carte par variante : Jour, Nuit,
* étage…). Enveloppe locale de SceneBattlemap + méta d'UI (noms de fichiers résolus,
* source du fichier, uploads en cours) — seuls label/mediaFileId/dataFileId persistent.
*/
interface BattlemapEdit {
label: string;
mediaFileId: string | null;
dataFileId: string | null;
mediaName: string | null;
dataName: string | null;
/**
* Source de CETTE carte :
* - 'DUNGEON_ALCHEMIST' : export Foundry = image/video + .json (2 fichiers).
* - 'DUNGEONDRAFT' : .dd2vtt unique (Universal VTT, image embarquee) ;
* on extrait l'image a l'upload -> media, et on range le .dd2vtt en donnees.
* Non persistee : deduite au chargement de l'extension du fichier de donnees.
*/
source: 'DUNGEON_ALCHEMIST' | 'DUNGEONDRAFT';
/** Le .dd2vtt deposse ne contenait pas d'image embarquee (carte sans fond). */
dd2vttNoImage: boolean;
uploadingMedia: boolean;
uploadingData: boolean;
}
/**
* Écran de détail/modification d'une Scène.
* Route : /campaigns/:campaignId/arcs/:arcId/chapters/:chapterId/scenes/:sceneId
*/
@Component({
selector: 'app-scene-edit',
imports: [ReactiveFormsModule, LucideAngularModule, ExpandableSectionComponent, LoreLinkPickerComponent, EnemyLinkPickerComponent, AiChatDrawerComponent, ImageGalleryComponent, IconPickerComponent, RoomsEditorComponent, FileDropDirective, TranslatePipe],
imports: [ReactiveFormsModule, LucideAngularModule, ExpandableSectionComponent, LoreLinkPickerComponent, EnemyLinkPickerComponent, AiChatDrawerComponent, ImageGalleryComponent, IconPickerComponent, RoomsEditorComponent, EntityAssistPanelComponent, FileDropDirective, TranslatePipe],
templateUrl: './scene-edit.component.html',
styleUrls: ['./scene-edit.component.scss']
})
@@ -43,6 +70,8 @@ export class SceneEditComponent implements OnInit, OnDestroy {
readonly Trash2 = Trash2;
readonly Sparkles = Sparkles;
readonly campaignIconOptions = CAMPAIGN_ICON_OPTIONS;
readonly sceneTypeOptions: SceneType[] = ['GENERIC', 'LOCATION', 'ENCOUNTER', 'NPC', 'EVENT', 'REVELATION'];
readonly linkTypeOptions: LinkType[] = ['EXIT', 'CLUE', 'LEAD'];
selectedIcon: string | null = null;
/** État drawer chat IA (b5.7 — intégration Campagne). */
@@ -64,6 +93,12 @@ export class SceneEditComponent implements OnInit, OnDestroy {
sceneId = '';
scene: Scene | null = null;
/**
* Section à déplier d'office (query param `?focus=combat|branches|rooms`) — posé par
* le bouton « Corriger » du guidage pour atterrir directement sur l'outil fautif.
*/
focusSection: string | null = null;
availablePages: Page[] = [];
loreId: string | null = null;
relatedPageIds: string[] = [];
@@ -72,24 +107,11 @@ export class SceneEditComponent implements OnInit, OnDestroy {
enemyIds: string[] = [];
illustrationImageIds: string[] = [];
/** Battlemap Foundry : paire { media + sidecar JSON Universal VTT }. Non affichee. */
battlemapMediaFileId: string | null = null;
battlemapDataFileId: string | null = null;
battlemapMediaName: string | null = null;
battlemapDataName: string | null = null;
battlemapUploadingMedia = false;
battlemapUploadingData = false;
/**
* Source de carte choisie pour CETTE scene :
* - 'DUNGEON_ALCHEMIST' : export Foundry = image/video + .json (2 fichiers).
* - 'DUNGEONDRAFT' : .dd2vtt unique (Universal VTT, image embarquee) ;
* on extrait l'image a l'upload -> media, et on range le .dd2vtt en donnees.
* Non persistee : deduite au chargement de l'extension du fichier de donnees.
* Battlemaps Foundry de la scene : une entree par variante (Jour/Nuit, etage…).
* Non affichees dans l'appli — transportees a l'export Foundry.
*/
battlemapSource: 'DUNGEON_ALCHEMIST' | 'DUNGEONDRAFT' = 'DUNGEON_ALCHEMIST';
/** Le .dd2vtt deposse ne contenait pas d'image embarquee (carte sans fond). */
battlemapDd2vttNoImage = false;
battlemaps: BattlemapEdit[] = [];
/** Scènes du chapitre courant (hors scène éditée) — alimente le dropdown des cibles. */
siblingScenes: Scene[] = [];
@@ -101,6 +123,39 @@ export class SceneEditComponent implements OnInit, OnDestroy {
onRoomsChange(next: Room[]): void { this.rooms = next; }
/**
* Applique au FORMULAIRE les champs étoffés retenus par l'utilisateur (Pilier A).
* Non destructif : ne touche que les contrôles proposés ; l'utilisateur enregistre
* ensuite normalement (rien n'est persisté par ce geste).
*/
onAssistApplied(fields: FieldProposal[]): void {
const patch: Record<string, string> = {};
for (const f of fields) {
if (this.form.get(f.key)) patch[f.key] = f.proposedValue;
}
this.form.patchValue(patch);
}
// ─────────────── État « rempli » par section (pastille de l'en-tête) ───────────────
// Tout est optionnel sauf le titre : ces getters signalent visuellement ce qui
// contient déjà du contenu, pour ne pas donner l'impression qu'il faut tout remplir.
get illustrationsFilled(): boolean { return this.illustrationImageIds.length > 0; }
get battlemapFilled(): boolean { return this.battlemaps.some(b => !!b.mediaFileId || !!b.dataFileId); }
get contextFilled(): boolean {
const v = this.form.value;
return !!(v.location || v.timing || v.atmosphere);
}
get narrationFilled(): boolean { return !!this.form.value.playerNarration; }
get gmNotesFilled(): boolean { return !!this.form.value.gmSecretNotes; }
get choicesFilled(): boolean { return !!this.form.value.choicesConsequences; }
get branchesFilled(): boolean { return this.branches.length > 0; }
get combatFilled(): boolean {
const v = this.form.value;
return !!(v.combatDifficulty || v.enemies) || this.enemyIds.length > 0;
}
get loreFilled(): boolean { return this.relatedPageIds.length > 0; }
get dungeonFilled(): boolean { return this.rooms.length > 0; }
constructor(
private fb: FormBuilder,
private route: ActivatedRoute,
@@ -118,6 +173,7 @@ export class SceneEditComponent implements OnInit, OnDestroy {
) {
this.form = this.fb.group({
name: ['', Validators.required],
type: ['GENERIC'],
description: [''],
// Contexte et ambiance
location: [''],
@@ -152,6 +208,7 @@ export class SceneEditComponent implements OnInit, OnDestroy {
this.arcId = newArcId;
this.chapterId = newChapterId;
this.sceneId = newSceneId;
this.focusSection = this.route.snapshot.queryParamMap.get('focus');
this.loadAll();
}
});
@@ -180,31 +237,37 @@ export class SceneEditComponent implements OnInit, OnDestroy {
this.enemyIds = [...(scene.enemyIds ?? [])];
this.selectedIcon = scene.icon ?? null;
this.illustrationImageIds = [...(scene.illustrationImageIds ?? [])];
this.battlemapMediaFileId = scene.battlemapMediaFileId ?? null;
this.battlemapDataFileId = scene.battlemapDataFileId ?? null;
this.battlemapMediaName = null;
this.battlemapDataName = null;
this.battlemapSource = 'DUNGEON_ALCHEMIST';
this.battlemapDd2vttNoImage = false;
if (this.battlemapMediaFileId) {
this.storedFileService.getById(this.battlemapMediaFileId)
.subscribe({ next: f => this.battlemapMediaName = f.filename, error: () => {} });
}
if (this.battlemapDataFileId) {
this.storedFileService.getById(this.battlemapDataFileId).subscribe({
next: f => {
this.battlemapDataName = f.filename;
// Deduit la source : un .dd2vtt/.uvtt => DungeonDraft.
if (/\.(dd2vtt|uvtt)$/i.test(f.filename)) this.battlemapSource = 'DUNGEONDRAFT';
},
error: () => {}
});
}
this.battlemaps = (scene.battlemaps ?? []).map(bm => {
const entry: BattlemapEdit = {
label: bm.label ?? '',
mediaFileId: bm.mediaFileId ?? null,
dataFileId: bm.dataFileId ?? null,
mediaName: null, dataName: null,
source: 'DUNGEON_ALCHEMIST', dd2vttNoImage: false,
uploadingMedia: false, uploadingData: false
};
if (entry.mediaFileId) {
this.storedFileService.getById(entry.mediaFileId)
.subscribe({ next: f => entry.mediaName = f.filename, error: () => {} });
}
if (entry.dataFileId) {
this.storedFileService.getById(entry.dataFileId).subscribe({
next: f => {
entry.dataName = f.filename;
// Deduit la source : un .dd2vtt/.uvtt => DungeonDraft.
if (/\.(dd2vtt|uvtt)$/i.test(f.filename)) entry.source = 'DUNGEONDRAFT';
},
error: () => {}
});
}
return entry;
});
this.siblingScenes = chapterScenes.filter(s => s.id !== this.sceneId);
this.branches = (scene.branches ?? []).map(b => ({ ...b }));
this.rooms = (scene.rooms ?? []).map(r => ({ ...r, branches: [...(r.branches ?? [])] }));
this.form.patchValue({
name: scene.name,
type: scene.type ?? 'GENERIC',
description: scene.description ?? '',
location: scene.location ?? '',
timing: scene.timing ?? '',
@@ -224,6 +287,7 @@ export class SceneEditComponent implements OnInit, OnDestroy {
if (this.form.invalid || !this.scene) return;
this.campaignService.updateScene(this.sceneId, {
name: this.form.value.name,
type: this.form.value.type,
description: this.form.value.description,
chapterId: this.chapterId,
order: this.scene.order ?? 1,
@@ -238,8 +302,11 @@ export class SceneEditComponent implements OnInit, OnDestroy {
enemyIds: this.enemyIds,
relatedPageIds: this.relatedPageIds,
illustrationImageIds: this.illustrationImageIds,
battlemapMediaFileId: this.battlemapMediaFileId,
battlemapDataFileId: this.battlemapDataFileId,
// Seules les cartes portant au moins un fichier sont persistees (une entree
// ajoutee puis laissee vide n'est pas une carte).
battlemaps: this.battlemaps
.filter(b => b.mediaFileId || b.dataFileId)
.map(b => ({ label: b.label.trim(), mediaFileId: b.mediaFileId, dataFileId: b.dataFileId } as SceneBattlemap)),
branches: this.branches,
rooms: this.rooms,
icon: this.selectedIcon
@@ -272,8 +339,18 @@ export class SceneEditComponent implements OnInit, OnDestroy {
// ─────────────── Gestion des branches narratives ───────────────
/**
* Destination de branche morte : renseignée mais ne résolvant vers aucune scène sœur
* (scène supprimée). Sans ce signal, la branche est invisible (le <select> affiche le
* placeholder) alors que le guidage la signale « cassée » ET que la sauvegarde serait
* refusée par le backend — incompréhensible pour l'utilisateur.
*/
isBranchTargetBroken(branch: SceneBranch): boolean {
return !!branch.targetSceneId && !this.siblingScenes.some(s => s.id === branch.targetSceneId);
}
addBranch(): void {
this.branches.push({ label: '', targetSceneId: '', condition: '' });
this.branches.push({ label: '', targetSceneId: '', condition: '', kind: 'EXIT' });
}
removeBranch(index: number): void {
@@ -292,98 +369,120 @@ export class SceneEditComponent implements OnInit, OnDestroy {
this.branches[index].condition = value;
}
// ─────────────── Battlemap Foundry (media + sidecar JSON) ───────────────
updateBranchKind(index: number, value: string): void {
this.branches[index].kind = value as LinkType;
}
// ─────────────── Battlemaps Foundry (liste de variantes) ───────────────
// On NE supprime PAS le binaire au "retirer" (juste la reference locale) :
// si l'utilisateur annule le formulaire, la scene garde son fichier intact.
// Le binaire orphelin eventuel est inoffensif (nettoyage ulterieur possible).
onBattlemapMediaSelected(event: Event): void {
const input = event.target as HTMLInputElement;
const file = input.files?.[0];
if (file) this.uploadBattlemapMedia(file);
input.value = '';
}
onBattlemapMediaDropped(files: File[]): void {
if (files[0]) this.uploadBattlemapMedia(files[0]);
}
private uploadBattlemapMedia(file: File): void {
this.battlemapUploadingMedia = true;
this.storedFileService.upload(file).subscribe({
next: f => {
this.battlemapMediaFileId = f.id;
this.battlemapMediaName = f.filename;
this.battlemapUploadingMedia = false;
},
error: () => { this.battlemapUploadingMedia = false; }
/** Ajoute une carte vierge (variante Jour/Nuit, etage…). */
addBattlemap(): void {
this.battlemaps.push({
label: '', mediaFileId: null, dataFileId: null, mediaName: null, dataName: null,
source: 'DUNGEON_ALCHEMIST', dd2vttNoImage: false,
uploadingMedia: false, uploadingData: false
});
}
onBattlemapDataSelected(event: Event): void {
/** Retire la carte entiere (references locales seulement, binaires conserves). */
removeBattlemap(index: number): void {
this.battlemaps.splice(index, 1);
}
updateBattlemapLabel(index: number, value: string): void {
this.battlemaps[index].label = value;
}
onBattlemapMediaSelected(bm: BattlemapEdit, event: Event): void {
const input = event.target as HTMLInputElement;
const file = input.files?.[0];
if (file) this.uploadBattlemapData(file);
if (file) this.uploadBattlemapMedia(bm, file);
input.value = '';
}
onBattlemapDataDropped(files: File[]): void {
if (files[0]) this.uploadBattlemapData(files[0]);
onBattlemapMediaDropped(bm: BattlemapEdit, files: File[]): void {
if (files[0]) this.uploadBattlemapMedia(bm, files[0]);
}
private uploadBattlemapData(file: File): void {
this.battlemapUploadingData = true;
private uploadBattlemapMedia(bm: BattlemapEdit, file: File): void {
bm.uploadingMedia = true;
this.storedFileService.upload(file).subscribe({
next: f => {
this.battlemapDataFileId = f.id;
this.battlemapDataName = f.filename;
this.battlemapUploadingData = false;
bm.mediaFileId = f.id;
bm.mediaName = f.filename;
bm.uploadingMedia = false;
},
error: () => { this.battlemapUploadingData = false; }
error: () => { bm.uploadingMedia = false; }
});
}
removeBattlemapMedia(): void {
this.battlemapMediaFileId = null;
this.battlemapMediaName = null;
onBattlemapDataSelected(bm: BattlemapEdit, event: Event): void {
const input = event.target as HTMLInputElement;
const file = input.files?.[0];
if (file) this.uploadBattlemapData(bm, file);
input.value = '';
}
removeBattlemapData(): void {
this.battlemapDataFileId = null;
this.battlemapDataName = null;
onBattlemapDataDropped(bm: BattlemapEdit, files: File[]): void {
if (files[0]) this.uploadBattlemapData(bm, files[0]);
}
private uploadBattlemapData(bm: BattlemapEdit, file: File): void {
bm.uploadingData = true;
this.storedFileService.upload(file).subscribe({
next: f => {
bm.dataFileId = f.id;
bm.dataName = f.filename;
bm.uploadingData = false;
},
error: () => { bm.uploadingData = false; }
});
}
removeBattlemapMedia(bm: BattlemapEdit): void {
bm.mediaFileId = null;
bm.mediaName = null;
}
removeBattlemapData(bm: BattlemapEdit): void {
bm.dataFileId = null;
bm.dataName = null;
}
// ─────────────── Source de carte (Dungeon Alchemist / DungeonDraft) ──────────
/** Change la source ; repart d'une carte vierge (les deux formats diffèrent). */
setBattlemapSource(src: 'DUNGEON_ALCHEMIST' | 'DUNGEONDRAFT'): void {
if (src === this.battlemapSource) return;
this.battlemapSource = src;
this.battlemapMediaFileId = null;
this.battlemapMediaName = null;
this.battlemapDataFileId = null;
this.battlemapDataName = null;
this.battlemapDd2vttNoImage = false;
/** Change la source de CETTE carte ; repart d'une carte vierge (les deux formats diffèrent). */
setBattlemapSource(bm: BattlemapEdit, src: 'DUNGEON_ALCHEMIST' | 'DUNGEONDRAFT'): void {
if (src === bm.source) return;
bm.source = src;
bm.mediaFileId = null;
bm.mediaName = null;
bm.dataFileId = null;
bm.dataName = null;
bm.dd2vttNoImage = false;
}
/** Retire la carte DungeonDraft (data + media dérivé). */
removeDd2vtt(): void {
this.battlemapMediaFileId = null;
this.battlemapMediaName = null;
this.battlemapDataFileId = null;
this.battlemapDataName = null;
this.battlemapDd2vttNoImage = false;
removeDd2vtt(bm: BattlemapEdit): void {
bm.mediaFileId = null;
bm.mediaName = null;
bm.dataFileId = null;
bm.dataName = null;
bm.dd2vttNoImage = false;
}
onDd2vttSelected(event: Event): void {
onDd2vttSelected(bm: BattlemapEdit, event: Event): void {
const input = event.target as HTMLInputElement;
const file = input.files?.[0];
if (file) void this.uploadDd2vtt(file);
if (file) void this.uploadDd2vtt(bm, file);
input.value = '';
}
onDd2vttDropped(files: File[]): void {
if (files[0]) void this.uploadDd2vtt(files[0]);
onDd2vttDropped(bm: BattlemapEdit, files: File[]): void {
if (files[0]) void this.uploadDd2vtt(bm, files[0]);
}
/**
@@ -392,40 +491,40 @@ export class SceneEditComponent implements OnInit, OnDestroy {
* sidecar (murs/lumieres/grille, SANS l'image pour ne pas dupliquer le binaire)
* comme fichier de donnees.
*/
private async uploadDd2vtt(file: File): Promise<void> {
this.battlemapUploadingData = true;
this.battlemapDd2vttNoImage = false;
private async uploadDd2vtt(bm: BattlemapEdit, file: File): Promise<void> {
bm.uploadingData = true;
bm.dd2vttNoImage = false;
try {
const json = JSON.parse(await file.text());
const { image, ...sidecar } = json ?? {};
// Sidecar allégé (sans l'image embarquée) ; on garde le nom .dd2vtt.
const dataFile = new File([JSON.stringify(sidecar)], file.name, { type: 'application/json' });
const storedData = await firstValueFrom(this.storedFileService.upload(dataFile));
this.battlemapDataFileId = storedData.id;
this.battlemapDataName = storedData.filename;
bm.dataFileId = storedData.id;
bm.dataName = storedData.filename;
if (typeof image === 'string' && image.length > 0) {
const blob = this.base64ToImageBlob(image);
const imgName = this.baseName(file.name) + this.extForType(blob.type);
const imgFile = new File([blob], imgName, { type: blob.type });
const storedMedia = await firstValueFrom(this.storedFileService.upload(imgFile));
this.battlemapMediaFileId = storedMedia.id;
this.battlemapMediaName = storedMedia.filename;
bm.mediaFileId = storedMedia.id;
bm.mediaName = storedMedia.filename;
} else {
this.battlemapMediaFileId = null;
this.battlemapMediaName = null;
this.battlemapDd2vttNoImage = true;
bm.mediaFileId = null;
bm.mediaName = null;
bm.dd2vttNoImage = true;
}
} catch {
// JSON illisible : on stocke le fichier brut comme données, sans image.
try {
const stored = await firstValueFrom(this.storedFileService.upload(file));
this.battlemapDataFileId = stored.id;
this.battlemapDataName = stored.filename;
this.battlemapDd2vttNoImage = true;
bm.dataFileId = stored.id;
bm.dataName = stored.filename;
bm.dd2vttNoImage = true;
} catch { /* upload échoué : on ignore */ }
} finally {
this.battlemapUploadingData = false;
bm.uploadingData = false;
}
}