Bug fix: Word Companion Create Scene buttons are still disabled after Phase 10J.

This commit is contained in:
Nick Beckley 2026-06-14 09:37:48 +01:00
parent f01232de49
commit 867d536f82

View File

@ -1520,23 +1520,24 @@
}
if (detectedChapterAnchorId) {
const anchoredChapterScene = await findSceneInBookStructure(
book.bookId,
(chapter, scene) => chapter.chapterId === detectedChapterAnchorId
&& normalizeTitleForResolve(scene.title, "scene").toLocaleLowerCase() === requestSceneTitle.toLocaleLowerCase()
);
const chapters = await getBookStructureChapters(book.bookId);
const anchoredChapter = chapters.find((chapter) => chapter.chapterId === detectedChapterAnchorId);
const anchoredChapterScene = anchoredChapter
? (Array.isArray(anchoredChapter.scenes) ? anchoredChapter.scenes : [])
.find((scene) => normalizeTitleForResolve(scene.title, "scene").toLocaleLowerCase() === requestSceneTitle.toLocaleLowerCase())
: null;
if (anchoredChapterScene) {
setResolveDiagnostics({
result: "Matched",
chapterId: anchoredChapterScene.chapter.chapterId,
sceneId: anchoredChapterScene.scene.sceneId
chapterId: anchoredChapter.chapterId,
sceneId: anchoredChapterScene.sceneId
});
await loadResolvedCompanionData(book.bookId, anchoredChapterScene.scene.sceneId, anchoredChapterScene.chapter.chapterId, "Anchor", "ChapterID Anchor");
await loadResolvedCompanionData(book.bookId, anchoredChapterScene.sceneId, anchoredChapter.chapterId, "Anchor", "ChapterID Anchor");
return true;
}
if (!detectedSceneAnchorId) {
if (anchoredChapter && !detectedSceneAnchorId) {
currentResolutionAnchorType = "ChapterID Anchor";
setResolvedScene(null, detectedChapterAnchorId, "Chapter anchor");
setResolveDiagnostics({
@ -1544,6 +1545,16 @@
chapterId: detectedChapterAnchorId,
sceneId: null
});
} else if (!detectedSceneAnchorId) {
storedAnchorInvalid = true;
currentResolutionAnchorType = "ChapterID Anchor";
setPlotDirectorSceneStatus("Not found in PlotDirector");
setDocumentMessage("Stored PlotDirector ID is invalid.");
setResolveDiagnostics({
result: "Error",
chapterId: detectedChapterAnchorId,
sceneId: null
});
}
}
@ -1555,11 +1566,13 @@
if (!resolveResponse?.matched || !resolveResponse.sceneId) {
const hadInvalidAnchor = storedAnchorInvalid;
const matchedChapterId = Number.parseInt(resolveResponse?.chapterId || "", 10);
const chapterMatched = !!resolveResponse?.chapterMatched || (Number.isInteger(matchedChapterId) && matchedChapterId > 0);
const anchorChapterId = Number.isInteger(resolvedChapterId) && resolvedChapterId > 0 ? resolvedChapterId : null;
const unmatchedChapterId = Number.isInteger(matchedChapterId) && matchedChapterId > 0 ? matchedChapterId : anchorChapterId;
const chapterMatched = !!resolveResponse?.chapterMatched || !!unmatchedChapterId;
resetPlotDirectorScene("Not found in PlotDirector");
storedAnchorInvalid = hadInvalidAnchor;
if (chapterMatched) {
setResolvedScene(null, matchedChapterId, "Chapter title");
setResolvedScene(null, unmatchedChapterId, unmatchedChapterId === anchorChapterId ? "Chapter anchor" : "Chapter title");
setPlotDirectorSceneStatus("Scene not found in PlotDirector.");
}
setDocumentMessage(hadInvalidAnchor
@ -1569,7 +1582,7 @@
: "This chapter does not exist in PlotDirector. Create or link the chapter first.");
setResolveDiagnostics({
result: "Not matched",
chapterId: chapterMatched ? matchedChapterId : resolveResponse?.chapterId,
chapterId: chapterMatched ? unmatchedChapterId : resolveResponse?.chapterId,
sceneId: resolveResponse?.sceneId
});
if (!hadInvalidAnchor) {