Checkpoint current UI and ink integration state
This commit is contained in:
@@ -214,7 +214,7 @@ class SocketClientModule extends BaseModule {
|
||||
this.receivedParagraphCounter = 0;
|
||||
}
|
||||
|
||||
const globalTags = Array.isArray(data.globalTags) ? data.globalTags : [];
|
||||
const globalTags = Array.isArray(data.globalTags) ? [...data.globalTags] : [];
|
||||
const endState = data.gameState?.endState || null;
|
||||
if (endState && !globalTags.some((tag) => tag?.key === 'score' || tag?.key === 'error')) {
|
||||
globalTags.push({
|
||||
@@ -227,8 +227,9 @@ class SocketClientModule extends BaseModule {
|
||||
document.dispatchEvent(new CustomEvent('story:global-tags', {
|
||||
detail: globalTags
|
||||
}));
|
||||
this.dispatchTurnTags(globalTags, null);
|
||||
this.dispatchTurnTags(globalTags.filter(tag => !this.isDeferredPopupTag(tag)), null);
|
||||
}
|
||||
const deferredGlobalTags = globalTags.filter(tag => this.isDeferredPopupTag(tag));
|
||||
|
||||
document.dispatchEvent(new CustomEvent('story:turn-start', {
|
||||
detail: { turnId, turn: data }
|
||||
@@ -244,11 +245,22 @@ class SocketClientModule extends BaseModule {
|
||||
pendingParagraph = result.pendingParagraph;
|
||||
turnBlocks.push(...result.blocks);
|
||||
});
|
||||
if (deferredGlobalTags.length > 0) {
|
||||
const targetBlock = [...turnBlocks].reverse().find(block => block?.type === 'paragraph' || block?.type === 'heading');
|
||||
if (targetBlock) {
|
||||
targetBlock.deferredTags = [
|
||||
...(Array.isArray(targetBlock.deferredTags) ? targetBlock.deferredTags : []),
|
||||
...deferredGlobalTags
|
||||
];
|
||||
} else {
|
||||
this.dispatchTurnTags(deferredGlobalTags, null);
|
||||
}
|
||||
}
|
||||
|
||||
await this.storeAndQueueBlocks(turnBlocks);
|
||||
|
||||
const choices = Array.isArray(data.choices) ? data.choices : [];
|
||||
const inputMode = data.inputMode || (choices.length > 0 ? 'choice' : 'text');
|
||||
const inputMode = data.inputMode || (choices.length > 0 ? 'choice' : 'none');
|
||||
this.dispatchChoices(choices);
|
||||
this.dispatchInputMode(inputMode);
|
||||
if (turnBlocks.length === 0 && choices.length > 0) {
|
||||
@@ -282,7 +294,7 @@ class SocketClientModule extends BaseModule {
|
||||
}
|
||||
|
||||
dispatchInputMode(inputMode) {
|
||||
const mode = ['text', 'choice', 'end'].includes(inputMode) ? inputMode : 'text';
|
||||
const mode = ['text', 'choice', 'end', 'none'].includes(inputMode) ? inputMode : 'none';
|
||||
document.dispatchEvent(new CustomEvent('story:input-mode', {
|
||||
detail: mode
|
||||
}));
|
||||
@@ -296,7 +308,12 @@ class SocketClientModule extends BaseModule {
|
||||
const { blocks, paragraphRole } = this.blocksFromTags(tags, turnId);
|
||||
const text = String(paragraph?.text || '').trim();
|
||||
const cueTags = tags.filter(tag => this.isTimedCueTag(tag));
|
||||
const immediateTags = tags.filter(tag => !this.isStructuralTag(tag) && !this.isTimedCueTag(tag));
|
||||
const deferredTags = tags.filter(tag => this.isDeferredPopupTag(tag));
|
||||
const immediateTags = tags.filter(tag =>
|
||||
!this.isStructuralTag(tag) &&
|
||||
!this.isTimedCueTag(tag) &&
|
||||
!this.isDeferredPopupTag(tag)
|
||||
);
|
||||
|
||||
this.dispatchTurnTags(immediateTags, paragraph);
|
||||
if (!text) {
|
||||
@@ -307,6 +324,10 @@ class SocketClientModule extends BaseModule {
|
||||
cueTags: [
|
||||
...(Array.isArray(pending.cueTags) ? pending.cueTags : []),
|
||||
...cueTags
|
||||
],
|
||||
deferredTags: [
|
||||
...(Array.isArray(pending.deferredTags) ? pending.deferredTags : []),
|
||||
...deferredTags
|
||||
]
|
||||
}
|
||||
};
|
||||
@@ -325,6 +346,10 @@ class SocketClientModule extends BaseModule {
|
||||
text,
|
||||
layoutText: paragraph.layoutText || text,
|
||||
cueMarkers,
|
||||
deferredTags: [
|
||||
...(Array.isArray(pending.deferredTags) ? pending.deferredTags : []),
|
||||
...deferredTags
|
||||
],
|
||||
role,
|
||||
isFirstParagraphInChapter: role === 'chapter-first' || role === 'textblock-first',
|
||||
dropCap: role === 'chapter-first',
|
||||
@@ -332,7 +357,7 @@ class SocketClientModule extends BaseModule {
|
||||
turnId
|
||||
});
|
||||
|
||||
return { blocks, pendingParagraph: { role: null, cueTags: [] } };
|
||||
return { blocks, pendingParagraph: { role: null, cueTags: [], deferredTags: [] } };
|
||||
}
|
||||
|
||||
async storeAndQueueBlocks(blocks = []) {
|
||||
@@ -388,6 +413,11 @@ class SocketClientModule extends BaseModule {
|
||||
return ['sfx', 'sound', 'audio'].includes(key);
|
||||
}
|
||||
|
||||
isDeferredPopupTag(tag) {
|
||||
const key = String(tag?.key || '').toLowerCase();
|
||||
return ['alert', 'achievement', 'score', 'error'].includes(key);
|
||||
}
|
||||
|
||||
cueMarkersFromTags(tags) {
|
||||
if (!Array.isArray(tags)) return [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user