Mode plat : seulement quand l'arc et le chapitre uniques sont vides
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 38s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 1m4s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Failing after 1m52s
Qualité & Sécurité / Web (ESLint · angular-eslint + sonarjs) (push) Successful in 38s
Qualité & Sécurité / Trivy (CVE dépendances Maven / pip / npm) (push) Failing after 1m4s
Qualité & Sécurité / MegaLinter (PMD · Ruff · Bandit · gitleaks · hadolint) (push) Failing after 1m52s
Une méthode guidée lancée dans une campagne vide crée un arc et un chapitre qui portent le contenu écrit (titre, accroche, enjeux, vérité cachée ou plan du méchant en notes MJ). Le mode plat les masquait : ce contenu devenait introuvable derrière le nœud « Scènes ». - Règle commune (flat-structure.ts) : un seul arc linéaire, un seul chapitre, et aucun contenu d'écriture dans l'un ou l'autre (les noms ne comptent pas, « Arc principal » / « Chapitre 1 » étant créés d'office). - Appliquée au volet de gauche, à la page de la campagne (cartes d'arc visibles dès qu'il y a du contenu) et au livret PDF (en-têtes d'arc et de chapitre conservés ; un arc HUB n'est plus jamais mis à plat). Vérifié : core clean verify (1289 tests, dont livret plat / non plat), web build + 860 vitest (règle du mode plat), lint sans erreur. À redéployer : core + web (aucune migration).
This commit is contained in:
@@ -5,6 +5,7 @@ import com.loremind.domain.campaigncontext.bestiary.NpcStory;
|
||||
import com.loremind.domain.campaigncontext.quest.NodeType;
|
||||
import com.loremind.domain.campaigncontext.quest.Prerequisite;
|
||||
import com.loremind.domain.campaigncontext.quest.QuestNodeRef;
|
||||
import com.loremind.domain.campaigncontext.structure.ArcType;
|
||||
import com.loremind.domain.campaigncontext.structure.Room;
|
||||
import com.loremind.domain.campaigncontext.structure.RoomBranch;
|
||||
import com.loremind.domain.campaigncontext.structure.SceneBranch;
|
||||
@@ -540,11 +541,12 @@ public class PdfExportService {
|
||||
List<ArcJpaEntity> arcs = st.visibleArcs;
|
||||
if (arcs.isEmpty()) return;
|
||||
|
||||
// Mode plat (miroir de l'UI Niveau 0) : 1 arc d'UN SEUL chapitre → on masque les
|
||||
// niveaux Arc/Chapitre et on présente les scènes À PLAT (cohérent avec la sidebar).
|
||||
if (arcs.size() == 1) {
|
||||
// Mode plat (miroir de l'UI Niveau 0) : 1 arc linéaire d'UN SEUL chapitre, tous deux
|
||||
// VIDES (créés d'office) → on masque les niveaux Arc/Chapitre et on présente les
|
||||
// scènes À PLAT. Un arc ou un chapitre écrit (méthode guidée…) garde ses en-têtes.
|
||||
if (arcs.size() == 1 && arcs.get(0).getType() != ArcType.HUB) {
|
||||
List<ChapterJpaEntity> only = st.chaptersByArc.get(arcs.get(0).getId());
|
||||
if (only.size() == 1) {
|
||||
if (only.size() == 1 && isBare(arcs.get(0)) && isBare(only.get(0))) {
|
||||
narrativeFlat(ctx, st, arcs.get(0), only.get(0));
|
||||
return;
|
||||
}
|
||||
@@ -561,6 +563,28 @@ public class PdfExportService {
|
||||
ctx.endColumns();
|
||||
}
|
||||
|
||||
/** Aucun contenu d'ecriture dans l'arc (son nom ne compte pas : « Arc principal » est cree d'office). */
|
||||
static boolean isBare(ArcJpaEntity arc) {
|
||||
return allBlank(arc.getDescription(), arc.getThemes(), arc.getStakes(), arc.getRewards(),
|
||||
arc.getResolution(), arc.getGmNotes(), arc.getHiddenTruth(), arc.getHooks())
|
||||
&& isEmpty(arc.getIllustrationImageIds());
|
||||
}
|
||||
|
||||
/** Aucun contenu d'ecriture dans le chapitre (son nom ne compte pas : « Chapitre 1 » est cree d'office). */
|
||||
static boolean isBare(ChapterJpaEntity ch) {
|
||||
return allBlank(ch.getDescription(), ch.getPlayerObjectives(), ch.getNarrativeStakes(), ch.getGmNotes())
|
||||
&& isEmpty(ch.getIllustrationImageIds());
|
||||
}
|
||||
|
||||
private static boolean allBlank(String... values) {
|
||||
for (String v : values) if (notBlank(v)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isEmpty(List<String> list) {
|
||||
return list == null || list.isEmpty();
|
||||
}
|
||||
|
||||
/** Arborescence des signets Arc -> Chapitre pour la partie narrative complete (mode non plat). */
|
||||
private void narrativeBookmarks(Ctx ctx, Structure st, List<ArcJpaEntity> arcs) {
|
||||
StringBuilder arcBms = new StringBuilder();
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.loremind.infrastructure.transfer.pdf;
|
||||
|
||||
import com.loremind.infrastructure.persistence.entity.*;
|
||||
import com.loremind.infrastructure.persistence.jpa.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Mode plat du livret : un seul arc d'un seul chapitre n'est présenté « à plat » que si
|
||||
* ces deux conteneurs sont vides. Un chapitre écrit (méthode guidée…) garde ses en-têtes.
|
||||
*/
|
||||
@SpringBootTest
|
||||
@Transactional
|
||||
class PdfExportFlatModeTest {
|
||||
|
||||
@Autowired private PdfExportService service;
|
||||
@Autowired private CampaignJpaRepository campaignRepo;
|
||||
@Autowired private ArcJpaRepository arcRepo;
|
||||
@Autowired private ChapterJpaRepository chapterRepo;
|
||||
@Autowired private SceneJpaRepository sceneRepo;
|
||||
|
||||
private String campaign(String chapterGmNotes) {
|
||||
CampaignJpaEntity camp = campaignRepo.save(CampaignJpaEntity.builder().name("C").arcsCount(1).build());
|
||||
ArcJpaEntity arc = arcRepo.save(ArcJpaEntity.builder().name("Arc principal").campaignId(camp.getId()).order(0).build());
|
||||
ChapterJpaEntity ch = chapterRepo.save(ChapterJpaEntity.builder().name("L'héritage empoisonné")
|
||||
.arcId(arc.getId()).order(0).gmNotes(chapterGmNotes).build());
|
||||
sceneRepo.save(SceneJpaEntity.builder().name("L'arrestation").chapterId(ch.getId()).order(0).build());
|
||||
return String.valueOf(camp.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void bareArcAndChapter_areFlattened() {
|
||||
String x = service.xhtml(campaign(null), PdfExportOptions.defaults());
|
||||
assertTrue(x.contains("id=\"part-narrative\">Scènes</h1>"));
|
||||
assertFalse(x.contains("L'héritage empoisonné</div>"), "en-tête de chapitre masqué");
|
||||
}
|
||||
|
||||
@Test
|
||||
void writtenChapter_keepsItsHeaders() {
|
||||
String x = service.xhtml(campaign("Le notaire est coupable."), PdfExportOptions.defaults());
|
||||
assertTrue(x.contains("id=\"part-narrative\">Structure narrative</h1>"));
|
||||
assertTrue(x.contains("L'héritage empoisonné"), "le chapitre de la méthode guidée reste visible");
|
||||
assertTrue(x.contains("Le notaire est coupable."));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user