Méthodes guidées : « Enquête en nœuds » et « Plan du méchant »
- Page de choix de méthode (/campaigns/:id/guided) : les boutons « Méthode guidée » de la campagne y mènent ; une carte par méthode avec son principe et le nombre de scènes créées. - Enquête en nœuds : vérité cachée (notes MJ du chapitre), accroche, trois pistes de natures variées, conclusion, scène de relance. Les 6 scènes sont reliées en réseau (12 liens) : l'accroche ouvre les trois pistes, chaque piste renvoie à une autre et donne un indice vers la conclusion, la relance ramène aux trois pistes. Ni chemin unique ni passage obligé : la relecture d'éditeur ne signale rien sur la structure générée. - Plan du méchant : l'adversaire, ce qu'il veut et ce qui arrive s'il réussit, puis six étapes (trois discrètes, trois visibles) avec ce que les joueurs peuvent remarquer. Plan complet en notes MJ, scènes non chaînées (c'est l'adversaire qui avance), et au choix une horloge de 6 segments créée dans chaque partie de la campagne. - Squelette guidé : notes MJ du chapitre, liens explicites typés (piste, indice) et horloge ; le Donjon en 5 salles est inchangé. Vérifié : core clean verify (1268 tests, dont liens, index décalés par une scène ignorée, horloge par partie), web build + vitest (textes fr/en de chaque étape, structure des deux méthodes), lint sans erreur, parcours complet des deux assistants dans le navigateur. À redéployer : core + web (aucune migration).
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.loremind.application.campaigncontext;
|
||||
|
||||
import com.loremind.domain.campaigncontext.structure.LinkType;
|
||||
import com.loremind.domain.campaigncontext.structure.SceneType;
|
||||
|
||||
import java.util.List;
|
||||
@@ -20,6 +21,9 @@ import java.util.List;
|
||||
* @param scenes les scènes, dans l'ordre (au moins une avec un nom)
|
||||
* @param linkSequentially relier chaque scène à la suivante par une sortie
|
||||
* @param linkLabel libellé de ces sorties (rédigé dans la langue du MJ par le front)
|
||||
* @param links liens explicites entre scènes (indices dans {@code scenes}), ou {@code null} :
|
||||
* une enquête en nœuds relie ses pistes en réseau, pas en chaîne
|
||||
* @param clock horloge à créer dans chaque partie de la campagne (plan du méchant), ou {@code null}
|
||||
*/
|
||||
public record GuidedSkeleton(
|
||||
String arcId,
|
||||
@@ -27,10 +31,44 @@ public record GuidedSkeleton(
|
||||
ChapterSpec chapter,
|
||||
List<SceneSpec> scenes,
|
||||
boolean linkSequentially,
|
||||
String linkLabel
|
||||
String linkLabel,
|
||||
List<LinkSpec> links,
|
||||
ClockSpec clock
|
||||
) {
|
||||
|
||||
public record ChapterSpec(String name, String description, String playerObjectives, String narrativeStakes) {
|
||||
/** Squelette sans liens explicites ni horloge (Donjon en 5 salles). */
|
||||
public GuidedSkeleton(String arcId, String newArcName, ChapterSpec chapter, List<SceneSpec> scenes,
|
||||
boolean linkSequentially, String linkLabel) {
|
||||
this(arcId, newArcName, chapter, scenes, linkSequentially, linkLabel, null, null);
|
||||
}
|
||||
|
||||
/** @param gmNotes notes réservées au MJ (vérité cachée d'une enquête, plan complet du méchant) */
|
||||
public record ChapterSpec(String name, String description, String playerObjectives, String narrativeStakes,
|
||||
String gmNotes) {
|
||||
public ChapterSpec(String name, String description, String playerObjectives, String narrativeStakes) {
|
||||
this(name, description, playerObjectives, narrativeStakes, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lien d'une scène vers une autre, par position dans {@code scenes}.
|
||||
*
|
||||
* @param from index de la scène de départ
|
||||
* @param to index de la scène d'arrivée
|
||||
* @param label libellé du lien (langue du MJ)
|
||||
* @param kind nature du lien (sortie, piste, indice) ; {@code null} = sortie
|
||||
*/
|
||||
public record LinkSpec(int from, int to, String label, LinkType kind) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Horloge de progression à créer dans chaque partie (Playthrough) de la campagne.
|
||||
*
|
||||
* @param name nom de l'horloge
|
||||
* @param description ce qui arrive quand elle est pleine
|
||||
* @param segments nombre de segments (une étape du plan = un segment)
|
||||
*/
|
||||
public record ClockSpec(String name, String description, int segments) {
|
||||
}
|
||||
|
||||
public record SceneSpec(
|
||||
@@ -38,7 +76,14 @@ public record GuidedSkeleton(
|
||||
String choicesConsequences, String gmSecretNotes, String enemies) {
|
||||
}
|
||||
|
||||
/** Ce qui a été créé, pour que le front ouvre directement le chapitre. */
|
||||
public record Result(String arcId, String chapterId, List<String> sceneIds) {
|
||||
/**
|
||||
* Ce qui a été créé, pour que le front ouvre directement le chapitre.
|
||||
*
|
||||
* @param clocks nombre d'horloges créées (une par partie de la campagne)
|
||||
*/
|
||||
public record Result(String arcId, String chapterId, List<String> sceneIds, int clocks) {
|
||||
public Result(String arcId, String chapterId, List<String> sceneIds) {
|
||||
this(arcId, chapterId, sceneIds, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+69
-9
@@ -10,6 +10,10 @@ import com.loremind.domain.campaigncontext.structure.LinkType;
|
||||
import com.loremind.domain.campaigncontext.structure.Scene;
|
||||
import com.loremind.domain.campaigncontext.structure.SceneBranch;
|
||||
import com.loremind.domain.campaigncontext.structure.SceneType;
|
||||
import com.loremind.application.playcontext.ClockService;
|
||||
import com.loremind.domain.playcontext.ClockTrigger;
|
||||
import com.loremind.domain.playcontext.Playthrough;
|
||||
import com.loremind.domain.playcontext.ports.PlaythroughRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -33,19 +37,25 @@ public class GuidedSkeletonService {
|
||||
private final ArcService arcService;
|
||||
private final ChapterService chapterService;
|
||||
private final SceneService sceneService;
|
||||
private final PlaythroughRepository playthroughRepository;
|
||||
private final ClockService clockService;
|
||||
|
||||
public GuidedSkeletonService(ArcRepository arcRepository,
|
||||
ChapterRepository chapterRepository,
|
||||
SceneRepository sceneRepository,
|
||||
ArcService arcService,
|
||||
ChapterService chapterService,
|
||||
SceneService sceneService) {
|
||||
SceneService sceneService,
|
||||
PlaythroughRepository playthroughRepository,
|
||||
ClockService clockService) {
|
||||
this.arcRepository = arcRepository;
|
||||
this.chapterRepository = chapterRepository;
|
||||
this.sceneRepository = sceneRepository;
|
||||
this.arcService = arcService;
|
||||
this.chapterService = chapterService;
|
||||
this.sceneService = sceneService;
|
||||
this.playthroughRepository = playthroughRepository;
|
||||
this.clockService = clockService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,17 +65,19 @@ public class GuidedSkeletonService {
|
||||
@Transactional
|
||||
public GuidedSkeleton.Result create(String campaignId, GuidedSkeleton skeleton) {
|
||||
validate(skeleton);
|
||||
List<GuidedSkeleton.SceneSpec> specs = skeleton.scenes().stream()
|
||||
.filter(s -> s != null && !isBlank(s.name()))
|
||||
.toList();
|
||||
|
||||
String arcId = resolveArc(campaignId, skeleton);
|
||||
Chapter chapter = createChapter(arcId, skeleton.chapter());
|
||||
|
||||
// Une scène sans nom est ignorée ; byIndex garde la position d'origine pour les liens.
|
||||
List<Scene> scenes = new ArrayList<>();
|
||||
List<Scene> byIndex = new ArrayList<>();
|
||||
int order = 0;
|
||||
for (GuidedSkeleton.SceneSpec spec : specs) {
|
||||
scenes.add(sceneService.createScene(Scene.builder()
|
||||
for (GuidedSkeleton.SceneSpec spec : skeleton.scenes()) {
|
||||
if (spec == null || isBlank(spec.name())) {
|
||||
byIndex.add(null);
|
||||
continue;
|
||||
}
|
||||
Scene created = sceneService.createScene(Scene.builder()
|
||||
.name(spec.name().trim())
|
||||
.description(blankToNull(spec.description()))
|
||||
.type(Objects.requireNonNullElse(spec.type(), SceneType.GENERIC))
|
||||
@@ -75,14 +87,61 @@ public class GuidedSkeletonService {
|
||||
.enemies(blankToNull(spec.enemies()))
|
||||
.chapterId(chapter.getId())
|
||||
.order(order++)
|
||||
.build()));
|
||||
.build());
|
||||
scenes.add(created);
|
||||
byIndex.add(created);
|
||||
}
|
||||
|
||||
if (skeleton.linkSequentially()) {
|
||||
linkInChain(scenes, isBlank(skeleton.linkLabel()) ? "→" : skeleton.linkLabel().trim());
|
||||
}
|
||||
if (skeleton.links() != null && !skeleton.links().isEmpty()) {
|
||||
linkExplicitly(byIndex, skeleton.links());
|
||||
}
|
||||
int clocks = createClocks(campaignId, skeleton.clock());
|
||||
|
||||
return new GuidedSkeleton.Result(arcId, chapter.getId(), scenes.stream().map(Scene::getId).toList());
|
||||
return new GuidedSkeleton.Result(arcId, chapter.getId(), scenes.stream().map(Scene::getId).toList(), clocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Liens explicites (réseau d'une enquête) : ajoutés aux sorties existantes. Un lien vers
|
||||
* ou depuis une scène ignorée (sans nom), hors limites ou en boucle sur soi est écarté.
|
||||
*/
|
||||
private void linkExplicitly(List<Scene> byIndex, List<GuidedSkeleton.LinkSpec> links) {
|
||||
java.util.Map<String, Scene> touched = new java.util.LinkedHashMap<>();
|
||||
for (GuidedSkeleton.LinkSpec link : links) {
|
||||
if (link == null || link.from() == link.to()) continue;
|
||||
Scene from = at(byIndex, link.from());
|
||||
Scene to = at(byIndex, link.to());
|
||||
if (from == null || to == null) continue;
|
||||
List<SceneBranch> branches = from.getBranches() == null ? new ArrayList<>() : new ArrayList<>(from.getBranches());
|
||||
String label = isBlank(link.label()) ? to.getName() : link.label().trim();
|
||||
branches.add(new SceneBranch(label, to.getId(), null,
|
||||
Objects.requireNonNullElse(link.kind(), LinkType.EXIT)));
|
||||
from.setBranches(branches);
|
||||
touched.put(from.getId(), from);
|
||||
}
|
||||
touched.values().forEach(sceneRepository::save);
|
||||
}
|
||||
|
||||
private static Scene at(List<Scene> byIndex, int index) {
|
||||
return index >= 0 && index < byIndex.size() ? byIndex.get(index) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Horloge du plan (méthode « Plan du méchant ») : créée dans chaque partie de la campagne,
|
||||
* car une horloge est de l'état de partie. Aucune partie : rien n'est créé (le MJ la
|
||||
* créera quand il lancera une partie).
|
||||
*/
|
||||
private int createClocks(String campaignId, GuidedSkeleton.ClockSpec clock) {
|
||||
if (clock == null || isBlank(clock.name())) return 0;
|
||||
int count = 0;
|
||||
for (Playthrough p : playthroughRepository.findByCampaignId(campaignId)) {
|
||||
clockService.create(p.getId(), clock.name().trim(), blankToNull(clock.description()),
|
||||
clock.segments(), ClockTrigger.NONE, null, null);
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private static void validate(GuidedSkeleton skeleton) {
|
||||
@@ -132,6 +191,7 @@ public class GuidedSkeletonService {
|
||||
.description(blankToNull(spec.description()))
|
||||
.playerObjectives(blankToNull(spec.playerObjectives()))
|
||||
.narrativeStakes(blankToNull(spec.narrativeStakes()))
|
||||
.gmNotes(blankToNull(spec.gmNotes()))
|
||||
.arcId(arcId)
|
||||
.order(nextOrder)
|
||||
.build());
|
||||
|
||||
+76
@@ -1,13 +1,18 @@
|
||||
package com.loremind.application.campaigncontext;
|
||||
|
||||
import com.loremind.application.playcontext.ClockService;
|
||||
import com.loremind.domain.campaigncontext.ports.ArcRepository;
|
||||
import com.loremind.domain.campaigncontext.ports.ChapterRepository;
|
||||
import com.loremind.domain.campaigncontext.ports.SceneRepository;
|
||||
import com.loremind.domain.campaigncontext.structure.Arc;
|
||||
import com.loremind.domain.campaigncontext.structure.ArcType;
|
||||
import com.loremind.domain.campaigncontext.structure.Chapter;
|
||||
import com.loremind.domain.campaigncontext.structure.LinkType;
|
||||
import com.loremind.domain.campaigncontext.structure.Scene;
|
||||
import com.loremind.domain.campaigncontext.structure.SceneType;
|
||||
import com.loremind.domain.playcontext.ClockTrigger;
|
||||
import com.loremind.domain.playcontext.Playthrough;
|
||||
import com.loremind.domain.playcontext.ports.PlaythroughRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -45,6 +50,8 @@ class GuidedSkeletonServiceTest {
|
||||
@Mock private ArcService arcService;
|
||||
@Mock private ChapterService chapterService;
|
||||
@Mock private SceneService sceneService;
|
||||
@Mock private PlaythroughRepository playthroughRepository;
|
||||
@Mock private ClockService clockService;
|
||||
|
||||
@InjectMocks private GuidedSkeletonService service;
|
||||
|
||||
@@ -196,4 +203,73 @@ class GuidedSkeletonServiceTest {
|
||||
assertThrows(IllegalArgumentException.class, () -> service.create(CAMP, noChapterName));
|
||||
assertThrows(IllegalArgumentException.class, () -> service.create(CAMP, noScene));
|
||||
}
|
||||
|
||||
// --- Liens explicites (Enquête en nœuds) et horloge (Plan du méchant) ---
|
||||
|
||||
private static GuidedSkeleton withLinks(List<GuidedSkeleton.SceneSpec> scenes, List<GuidedSkeleton.LinkSpec> links,
|
||||
GuidedSkeleton.ClockSpec clock) {
|
||||
return new GuidedSkeleton(null, "Arc",
|
||||
new GuidedSkeleton.ChapterSpec("Enquête", "Accroche", null, null, "Le notaire est coupable"),
|
||||
scenes, false, null, links, clock);
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitLinks_areAddedWithTheirKind_andIndexesSurviveSkippedScenes() {
|
||||
when(arcRepository.findByCampaignId(CAMP)).thenReturn(List.of());
|
||||
// La scène d'index 1 n'a pas de nom : ignorée, mais les index des liens restent ceux d'origine.
|
||||
List<GuidedSkeleton.SceneSpec> scenes = List.of(
|
||||
room("Accroche", SceneType.EVENT), room(" ", SceneType.LOCATION),
|
||||
room("Piste", SceneType.NPC), room("Conclusion", SceneType.REVELATION));
|
||||
|
||||
service.create(CAMP, withLinks(scenes, List.of(
|
||||
new GuidedSkeleton.LinkSpec(0, 2, "Piste", LinkType.LEAD),
|
||||
new GuidedSkeleton.LinkSpec(2, 3, "Indice", LinkType.CLUE),
|
||||
new GuidedSkeleton.LinkSpec(0, 1, "Vers la scène ignorée", LinkType.LEAD),
|
||||
new GuidedSkeleton.LinkSpec(3, 3, "Boucle sur soi", LinkType.EXIT),
|
||||
new GuidedSkeleton.LinkSpec(0, 9, "Hors limites", LinkType.EXIT)), null));
|
||||
|
||||
Scene hook = createdScenes.get(0);
|
||||
Scene lead = createdScenes.get(1);
|
||||
Scene end = createdScenes.get(2);
|
||||
assertEquals(1, hook.getBranches().size(), "seul le lien valide de l'accroche est gardé");
|
||||
assertEquals(lead.getId(), hook.getBranches().get(0).targetSceneId());
|
||||
assertEquals(LinkType.LEAD, hook.getBranches().get(0).kind());
|
||||
assertEquals(end.getId(), lead.getBranches().get(0).targetSceneId());
|
||||
assertEquals(LinkType.CLUE, lead.getBranches().get(0).kind());
|
||||
assertTrue(end.getBranches() == null || end.getBranches().isEmpty());
|
||||
verify(sceneRepository, times(2)).save(any(Scene.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void chapterGmNotes_arePersisted() {
|
||||
when(arcRepository.findByCampaignId(CAMP)).thenReturn(List.of());
|
||||
service.create(CAMP, withLinks(List.of(room("S", SceneType.EVENT)), null, null));
|
||||
|
||||
ArgumentCaptor<Chapter> chapter = ArgumentCaptor.forClass(Chapter.class);
|
||||
verify(chapterService).createChapter(chapter.capture());
|
||||
assertEquals("Le notaire est coupable", chapter.getValue().getGmNotes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clock_isCreatedInEveryPlaythroughOfTheCampaign() {
|
||||
when(arcRepository.findByCampaignId(CAMP)).thenReturn(List.of());
|
||||
when(playthroughRepository.findByCampaignId(CAMP)).thenReturn(List.of(
|
||||
Playthrough.builder().id("p1").campaignId(CAMP).build(),
|
||||
Playthrough.builder().id("p2").campaignId(CAMP).build()));
|
||||
|
||||
GuidedSkeleton.Result result = service.create(CAMP, withLinks(List.of(room("Étape 1", SceneType.EVENT)), null,
|
||||
new GuidedSkeleton.ClockSpec(" La régence ", "La loi martiale", 6)));
|
||||
|
||||
assertEquals(2, result.clocks());
|
||||
verify(clockService).create("p1", "La régence", "La loi martiale", 6, ClockTrigger.NONE, null, null);
|
||||
verify(clockService).create("p2", "La régence", "La loi martiale", 6, ClockTrigger.NONE, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noClock_whenNotRequested() {
|
||||
when(arcRepository.findByCampaignId(CAMP)).thenReturn(List.of());
|
||||
GuidedSkeleton.Result result = service.create(CAMP, skeleton(null, "Arc", false));
|
||||
assertEquals(0, result.clocks());
|
||||
verify(clockService, never()).create(any(), any(), any(), org.mockito.ArgumentMatchers.anyInt(), any(), any(), any());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user