- Raccourci « Séance en cours » dans le menu principal : visible dès qu'une
séance tourne (liste dépliable s'il y en a plusieurs, la plus récente en
tête), rafraîchi à la navigation et au démarrage/fin d'une séance.
- Hub campagne : bloc « Jouer » sous l'en-tête — reprendre la séance en
cours, sinon démarrer une séance sur la partie la plus récente (menu pour
en choisir une autre), ou créer une partie s'il n'y en a aucune.
- Arbre de campagne : section « Jeu > Parties » avant la narration.
- Onglet « Règles » en séance : sommaire des sections, sections repliables,
recherche instantanée hors ligne (insensible aux accents, à la casse et aux
ligatures, ne garde et ne surligne que les lignes concernées), sections
épinglables (mémorisées par système), « Demander à l'IA » qui bascule sur
l'onglet IA avec la question préremplie ; liens utiles si la campagne n'a
pas de système ou si le système n'a pas de règles.
- Core : GET /api/sessions?active=true (séances en cours sans tout
l'historique) ; l'arbre /campaigns/{id}/tree inclut les parties.
Vérifié : core test-compile + tests, web build + vitest (recherche dans les
règles, bloc « Jouer »), lint sans nouvelle erreur, testé desktop et 375 px.
À redéployer : core (aucune migration) + web.
224 lines
7.7 KiB
TypeScript
224 lines
7.7 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
|
import { Observable } from 'rxjs';
|
|
import { Campaign, CampaignCreate, Arc, ArcCreate, Chapter, ChapterCreate, Scene, SceneCreate, Quest, Playthrough } from './campaign.model';
|
|
import { CampaignReadinessAssessment } from './readiness.model';
|
|
import { Npc } from './npc.model';
|
|
import { RandomTable } from './random-table.model';
|
|
import { Enemy } from './enemy.model';
|
|
|
|
/**
|
|
* Arbre de campagne AGRÉGÉ (une seule requête HTTP) — miroir de CampaignTreeDTO.
|
|
* Remplace la rafale d'appels (~15-20) que la sidebar déclenchait à chaque navigation.
|
|
*/
|
|
export interface CampaignTreeResponse {
|
|
arcs: Arc[];
|
|
chaptersByArc: Record<string, Chapter[]>;
|
|
scenesByChapter: Record<string, Scene[]>;
|
|
npcs: Npc[];
|
|
randomTables: RandomTable[];
|
|
enemies: Enemy[];
|
|
quests: Quest[];
|
|
/** Parties (Playthroughs) de la campagne — nœud « Parties » de l'arbre. */
|
|
playthroughs?: Playthrough[];
|
|
readiness: CampaignReadinessAssessment;
|
|
}
|
|
|
|
/**
|
|
* Périmètre de l'export Foundry (modale) :
|
|
* - maps : Scenes Foundry (battlemaps) + acteurs/tokens des ennemis liés.
|
|
* - journals : journaux narratifs (arcs, chapitres, scènes, PNJ, bestiaire).
|
|
* - tables : tables aléatoires (RollTables).
|
|
*/
|
|
export interface FoundryExportOptions {
|
|
maps: boolean;
|
|
journals: boolean;
|
|
tables: boolean;
|
|
}
|
|
|
|
/** Compte des entités qui seront supprimées en cascade avec la campagne. */
|
|
export interface CampaignDeletionImpact {
|
|
arcs: number;
|
|
chapters: number;
|
|
scenes: number;
|
|
playthroughs: number;
|
|
}
|
|
|
|
/** Compte des entités qui seront supprimées en cascade avec un arc. */
|
|
export interface ArcDeletionImpact {
|
|
chapters: number;
|
|
scenes: number;
|
|
}
|
|
|
|
/** Compte des scènes qui tomberont avec un chapitre. */
|
|
export interface ChapterDeletionImpact {
|
|
scenes: number;
|
|
}
|
|
|
|
/**
|
|
* Service HTTP pour la gestion des Campagnes.
|
|
* Port de sortie vers le Backend Java (Architecture Hexagonale).
|
|
*/
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class CampaignService {
|
|
private apiUrl = '/api/campaigns';
|
|
|
|
constructor(private http: HttpClient) {}
|
|
|
|
getAllCampaigns(): Observable<Campaign[]> {
|
|
return this.http.get<Campaign[]>(this.apiUrl);
|
|
}
|
|
|
|
getCampaignById(id: string): Observable<Campaign> {
|
|
return this.http.get<Campaign>(`${this.apiUrl}/${id}`);
|
|
}
|
|
|
|
/** Sauvegarde la disposition du graphe de campagne (JSON opaque ; '' = disposition auto). */
|
|
updateGraphPositions(id: string, positionsJson: string): Observable<void> {
|
|
return this.http.put<void>(`${this.apiUrl}/${id}/graph-positions`, { positions: positionsJson });
|
|
}
|
|
|
|
/** Bilan de préparation (Pilier B) — alimente les pastilles de l'arbre de la sidebar. */
|
|
getReadiness(id: string): Observable<CampaignReadinessAssessment> {
|
|
return this.http.get<CampaignReadinessAssessment>(`${this.apiUrl}/${id}/readiness`);
|
|
}
|
|
|
|
/** Arbre complet de la campagne en UNE requête (sidebar : structure + quêtes + readiness). */
|
|
getTree(id: string): Observable<CampaignTreeResponse> {
|
|
return this.http.get<CampaignTreeResponse>(`${this.apiUrl}/${id}/tree`);
|
|
}
|
|
|
|
/**
|
|
* Télécharge le bundle d'export Foundry de la campagne (.zip).
|
|
* Périmètre optionnel (tout par défaut) : cartes+ennemis / journaux / tables.
|
|
*/
|
|
exportFoundry(id: string, opts?: FoundryExportOptions): Observable<Blob> {
|
|
let params = new HttpParams();
|
|
if (opts) {
|
|
params = params
|
|
.set('maps', String(opts.maps))
|
|
.set('journals', String(opts.journals))
|
|
.set('tables', String(opts.tables));
|
|
}
|
|
return this.http.get(`${this.apiUrl}/${id}/foundry-export`, { responseType: 'blob', params });
|
|
}
|
|
|
|
/** Génère et télécharge le livret PDF de la campagne. */
|
|
exportPdf(id: string): Observable<Blob> {
|
|
return this.http.get(`${this.apiUrl}/${id}/pdf-export`, { responseType: 'blob' });
|
|
}
|
|
|
|
createCampaign(campaign: CampaignCreate): Observable<Campaign> {
|
|
return this.http.post<Campaign>(this.apiUrl, campaign);
|
|
}
|
|
|
|
updateCampaign(id: string, campaign: CampaignCreate): Observable<Campaign> {
|
|
return this.http.put<Campaign>(`${this.apiUrl}/${id}`, campaign);
|
|
}
|
|
|
|
deleteCampaign(id: string): Observable<void> {
|
|
return this.http.delete<void>(`${this.apiUrl}/${id}`);
|
|
}
|
|
|
|
getCampaignDeletionImpact(id: string): Observable<CampaignDeletionImpact> {
|
|
return this.http.get<CampaignDeletionImpact>(`${this.apiUrl}/${id}/deletion-impact`);
|
|
}
|
|
|
|
// ========== ARC ==========
|
|
getArcs(campaignId: string): Observable<Arc[]> {
|
|
const params = new HttpParams().set('campaignId', campaignId);
|
|
return this.http.get<Arc[]>('/api/arcs', { params });
|
|
}
|
|
|
|
getArcById(id: string): Observable<Arc> {
|
|
return this.http.get<Arc>(`/api/arcs/${id}`);
|
|
}
|
|
|
|
createArc(payload: ArcCreate): Observable<Arc> {
|
|
return this.http.post<Arc>('/api/arcs', payload);
|
|
}
|
|
|
|
updateArc(id: string, payload: ArcCreate): Observable<Arc> {
|
|
return this.http.put<Arc>(`/api/arcs/${id}`, payload);
|
|
}
|
|
|
|
deleteArc(id: string): Observable<void> {
|
|
return this.http.delete<void>(`/api/arcs/${id}`);
|
|
}
|
|
|
|
getArcDeletionImpact(id: string): Observable<ArcDeletionImpact> {
|
|
return this.http.get<ArcDeletionImpact>(`/api/arcs/${id}/deletion-impact`);
|
|
}
|
|
|
|
/** Réordonne les arcs d'une campagne (glisser-déposer) : order = position. */
|
|
reorderArcs(orderedIds: string[]): Observable<void> {
|
|
return this.http.put<void>('/api/arcs/reorder', { orderedIds });
|
|
}
|
|
|
|
// ========== CHAPTER ==========
|
|
/** Liste les chapitres d'un arc (donnée de scénario pure). */
|
|
getChapters(arcId: string): Observable<Chapter[]> {
|
|
const params = new HttpParams().set('arcId', arcId);
|
|
return this.http.get<Chapter[]>('/api/chapters', { params });
|
|
}
|
|
|
|
getChapterById(id: string): Observable<Chapter> {
|
|
return this.http.get<Chapter>(`/api/chapters/${id}`);
|
|
}
|
|
|
|
createChapter(payload: ChapterCreate): Observable<Chapter> {
|
|
return this.http.post<Chapter>('/api/chapters', payload);
|
|
}
|
|
|
|
updateChapter(id: string, payload: ChapterCreate): Observable<Chapter> {
|
|
return this.http.put<Chapter>(`/api/chapters/${id}`, payload);
|
|
}
|
|
|
|
deleteChapter(id: string): Observable<void> {
|
|
return this.http.delete<void>(`/api/chapters/${id}`);
|
|
}
|
|
|
|
getChapterDeletionImpact(id: string): Observable<ChapterDeletionImpact> {
|
|
return this.http.get<ChapterDeletionImpact>(`/api/chapters/${id}/deletion-impact`);
|
|
}
|
|
|
|
/** Réordonne (et déplace) les chapitres d'un arc : order = position, arcId = arc cible. */
|
|
reorderChapters(arcId: string, orderedIds: string[]): Observable<void> {
|
|
return this.http.put<void>('/api/chapters/reorder', { arcId, orderedIds });
|
|
}
|
|
|
|
// ========== SCENE ==========
|
|
getScenes(chapterId: string): Observable<Scene[]> {
|
|
const params = new HttpParams().set('chapterId', chapterId);
|
|
return this.http.get<Scene[]>('/api/scenes', { params });
|
|
}
|
|
|
|
getSceneById(id: string): Observable<Scene> {
|
|
return this.http.get<Scene>(`/api/scenes/${id}`);
|
|
}
|
|
|
|
createScene(payload: SceneCreate): Observable<Scene> {
|
|
return this.http.post<Scene>('/api/scenes', payload);
|
|
}
|
|
|
|
updateScene(id: string, payload: SceneCreate): Observable<Scene> {
|
|
return this.http.put<Scene>(`/api/scenes/${id}`, payload);
|
|
}
|
|
|
|
deleteScene(id: string): Observable<void> {
|
|
return this.http.delete<void>(`/api/scenes/${id}`);
|
|
}
|
|
|
|
/** Réordonne (et déplace) les scènes d'un chapitre : order = position, chapterId = cible. */
|
|
reorderScenes(chapterId: string, orderedIds: string[]): Observable<void> {
|
|
return this.http.put<void>('/api/scenes/reorder', { chapterId, orderedIds });
|
|
}
|
|
|
|
search(q: string): Observable<Campaign[]> {
|
|
const params = new HttpParams().set('q', q);
|
|
return this.http.get<Campaign[]>(`${this.apiUrl}/search`, { params });
|
|
}
|
|
}
|