Queue WebGL book reveal masks

This commit is contained in:
2026-06-07 13:52:07 +02:00
parent 7fc083fb58
commit 9434950826
31 changed files with 383 additions and 73 deletions
+50 -3
View File
@@ -68,6 +68,8 @@ class UIDisplayHandlerModule extends BaseModule {
'applyGameConfig',
'applyTranslations',
'renderSentence',
'isWebGLMode',
'prepareWebGLBookReveal',
'renderStoryBlock',
'prepareRenderableBlock',
'prepareTextRenderable',
@@ -986,12 +988,14 @@ class UIDisplayHandlerModule extends BaseModule {
if (!isCurrent()) return null;
this.rebuildLayoutExclusions(this.renderedItems);
this.layoutFlowLine = this.getFlowLineFromItems(this.renderedItems);
const useWebGLBookReveal = this.isWebGLMode() && (sentence.kind === 'paragraph' || sentence.kind === 'heading');
const element = await this.renderStoryBlock(sentence, {
animate: true,
playback: true,
placement: 'append',
token: this.renderWindowToken,
generation
generation,
deferRenderedMark: useWebGLBookReveal
});
if (!element) return null;
if (!isCurrent()) {
@@ -1008,7 +1012,13 @@ class UIDisplayHandlerModule extends BaseModule {
if (sentence.kind === 'image') {
this.revealImageBlock(element);
} else if (sentence.kind === 'paragraph' || sentence.kind === 'heading') {
if (useWebGLBookReveal) {
await this.prepareWebGLBookReveal(sentence);
}
await this.playbackCoordinator.play(sentence);
if (useWebGLBookReveal && sentence.blockId != null) {
this.markBlockRendered(sentence.blockId);
}
} else if (sentence.kind === 'music') {
console.log('UIDisplayHandler: Music block started', sentence.metadata || {});
}
@@ -1028,6 +1038,42 @@ class UIDisplayHandlerModule extends BaseModule {
}
}
isWebGLMode() {
return document.body?.dataset?.webglUiMode === '3d'
|| document.body?.classList?.contains('webgl-mode');
}
async prepareWebGLBookReveal(sentence) {
const bookPagination = this.getModule('book-pagination');
const bookTextureRenderer = this.getModule('book-texture-renderer');
if (!bookPagination || !bookTextureRenderer || sentence.blockId == null) return;
if (typeof bookPagination.preparePendingBlock === 'function') {
await bookPagination.preparePendingBlock(sentence);
} else {
document.dispatchEvent(new CustomEvent('book-pagination:prepare-block', {
detail: {
block: sentence
}
}));
}
const revealDetail = {
id: sentence.id,
blockId: sentence.blockId,
wordTimings: sentence.animation?.wordTimings || [],
cueTimings: sentence.animation?.cueTimings || [],
totalDuration: sentence.animation?.totalDuration || 0
};
if (typeof bookTextureRenderer.prepareRevealBlock === 'function') {
bookTextureRenderer.prepareRevealBlock(revealDetail);
} else {
document.dispatchEvent(new CustomEvent('book-texture:prepare-reveal-block', {
detail: revealDetail
}));
}
}
async rerenderStory() {
if (!this.paragraphContainer || this.renderedItems.length === 0) return;
console.log('UIDisplayHandler: Re-typesetting story after page resize');
@@ -1097,7 +1143,8 @@ class UIDisplayHandlerModule extends BaseModule {
renderedItemsTarget = this.renderedItems,
token = null,
recordMetrics = true,
generation = this.displayGeneration
generation = this.displayGeneration,
deferRenderedMark = false
} = options;
if (!item || !this.paragraphContainer) return null;
const renderable = await this.prepareRenderableBlock(item);
@@ -1144,7 +1191,7 @@ class UIDisplayHandlerModule extends BaseModule {
}
if (item.blockId != null) {
element.dataset.storyBlockId = String(item.blockId);
this.markBlockRendered(item.blockId);
if (!deferRenderedMark) this.markBlockRendered(item.blockId);
}
element.dataset.lineStart = String(renderable.lineStart);
element.dataset.lineCount = String(renderable.lineCount);