diff --git a/packages/webgal/src/Core/Modules/gamePlay.ts b/packages/webgal/src/Core/Modules/gamePlay.ts index e8e8c9f5e..83d0b3cef 100644 --- a/packages/webgal/src/Core/Modules/gamePlay.ts +++ b/packages/webgal/src/Core/Modules/gamePlay.ts @@ -12,6 +12,7 @@ export class Gameplay { public autoTimeout: ReturnType | null = null; public pixiStage: PixiStage | null = null; public performController = new PerformController(); + public isFastPreview = false; /* 有图标状态需求 */ private _isAuto = false; @@ -34,6 +35,7 @@ export class Gameplay { public resetGamePlay() { this.isAuto = false; this.isFast = false; + this.isFastPreview = false; const autoInterval = this.autoInterval; if (autoInterval !== null) clearInterval(autoInterval); this.autoInterval = null; diff --git a/packages/webgal/src/Core/gameScripts/choose/index.tsx b/packages/webgal/src/Core/gameScripts/choose/index.tsx index b7813c4cc..6b48a1758 100644 --- a/packages/webgal/src/Core/gameScripts/choose/index.tsx +++ b/packages/webgal/src/Core/gameScripts/choose/index.tsx @@ -14,6 +14,7 @@ import useEscape from '@/hooks/useEscape'; import useApplyStyle from '@/hooks/useApplyStyle'; import { Provider } from 'react-redux'; import { useFontFamily } from '@/hooks/useFontFamily'; +import { getNumberArgByKey } from '@/Core/util/getSentenceArg'; class ChooseOption { /** @@ -58,6 +59,8 @@ class ChooseOption { export const choose = (sentence: ISentence): IPerform => { const chooseOptionScripts = sentence.content.split(/(? ChooseOption.parse(e.trim())); + const defaultChoose = getNumberArgByKey(sentence, 'defaultChoose'); + const previewChoice = getDefaultPreviewChoice(chooseOptions, defaultChoose); // eslint-disable-next-line react/no-deprecated ReactDOM.render( @@ -66,6 +69,12 @@ export const choose = (sentence: ISentence): IPerform => { , document.getElementById('chooseContainer'), ); + if (previewChoice) { + setTimeout(() => { + selectChooseOption(previewChoice); + WebGAL.gameplay.performController.unmountPerform('choose'); + }, 0); + } return { performName: 'choose', duration: 1000 * 60 * 60 * 24, @@ -80,6 +89,26 @@ export const choose = (sentence: ISentence): IPerform => { }; }; +function getDefaultPreviewChoice(chooseOptions: ChooseOption[], defaultChoose: number | null): ChooseOption | null { + if (!WebGAL.gameplay.isFastPreview || defaultChoose === null) { + return null; + } + const chooseIndex = Math.floor(defaultChoose) - 1; + if (chooseIndex < 0) { + return null; + } + const defaultOption = chooseOptions[chooseIndex]; + return defaultOption ?? null; +} + +function selectChooseOption(option: ChooseOption) { + if (option.jumpToScene) { + changeScene(option.jump, option.text); + } else { + jmp(option.jump); + } +} + function Choose(props: { chooseOptions: ChooseOption[] }) { const font = useFontFamily(); const { playSeEnter, playSeClick } = useSEByWebgalStore(); @@ -96,11 +125,7 @@ function Choose(props: { chooseOptions: ChooseOption[] }) { const onClick = enable ? () => { playSeClick(); - if (e.jumpToScene) { - changeScene(e.jump, e.text); - } else { - jmp(e.jump); - } + selectChooseOption(e); WebGAL.gameplay.performController.unmountPerform('choose'); } : () => {}; diff --git a/packages/webgal/src/Core/util/syncWithEditor/syncWithOrigine.ts b/packages/webgal/src/Core/util/syncWithEditor/syncWithOrigine.ts index 3f1d39750..c666bfbc6 100644 --- a/packages/webgal/src/Core/util/syncWithEditor/syncWithOrigine.ts +++ b/packages/webgal/src/Core/util/syncWithEditor/syncWithOrigine.ts @@ -15,6 +15,7 @@ let syncFastTimeout: ReturnType | undefined; export const syncWithOrigine = (sceneName: string, sentenceId: number, expermental = false) => { logger.warn('正在跳转到' + sceneName + ':' + sentenceId); + WebGAL.gameplay.isFastPreview = false; const dispatch = webgalStore.dispatch; dispatch(setVisibility({ component: 'showTitle', visibility: false })); dispatch(setVisibility({ component: 'showMenuPanel', visibility: false })); @@ -27,26 +28,32 @@ export const syncWithOrigine = (sceneName: string, sentenceId: number, experment // 重新获取场景 const sceneUrl: string = assetSetter(sceneName, fileType.scene); // 场景写入到运行时 - sceneFetcher(sceneUrl).then((rawScene) => { - // 等等,先检查一下能不能恢复场景 - const lastSameSentence = findLastSameSentence(pastScene, WebGAL.sceneManager.sceneData.currentScene, sentenceId); - const lastRecoverySentenceId = Math.min(sentenceId, lastSameSentence); - const recId = findLastAvailableBacklog(lastRecoverySentenceId, sceneName); - const isCanRec = recId >= 0 && expermental; - resetStage(!isCanRec); - WebGAL.sceneManager.sceneData.currentScene = sceneParser(rawScene, sceneName, sceneUrl); - // 开始快进到指定语句 - const currentSceneName = WebGAL.sceneManager.sceneData.currentScene.sceneName; - WebGAL.gameplay.isFast = true; - if (isCanRec) { - jumpFromBacklog(recId, false); - } - if (syncFastTimeout) { - // 之前发生的跳转要清理掉 - clearTimeout(syncFastTimeout); - } - syncFast(sentenceId, currentSceneName); - }); + sceneFetcher(sceneUrl) + .then((rawScene) => { + // 等等,先检查一下能不能恢复场景 + const lastSameSentence = findLastSameSentence(pastScene, WebGAL.sceneManager.sceneData.currentScene, sentenceId); + const lastRecoverySentenceId = Math.min(sentenceId, lastSameSentence); + const recId = findLastAvailableBacklog(lastRecoverySentenceId, sceneName); + const isCanRec = recId >= 0 && expermental; + resetStage(!isCanRec); + WebGAL.sceneManager.sceneData.currentScene = sceneParser(rawScene, sceneName, sceneUrl); + // 开始快进到指定语句 + const currentSceneName = WebGAL.sceneManager.sceneData.currentScene.sceneName; + WebGAL.gameplay.isFast = true; + WebGAL.gameplay.isFastPreview = true; + if (isCanRec) { + jumpFromBacklog(recId, false); + } + if (syncFastTimeout) { + // 之前发生的跳转要清理掉 + clearTimeout(syncFastTimeout); + } + syncFast(sentenceId, currentSceneName); + }) + .catch((e) => { + WebGAL.gameplay.isFastPreview = false; + logger.error('快速预览跳转错误', e); + }); }; export function syncFast(sentenceId: number, currentSceneName: string) { @@ -58,6 +65,7 @@ export function syncFast(sentenceId: number, currentSceneName: string) { syncFastTimeout = setTimeout(() => syncFast(sentenceId, currentSceneName), 2); } else { WebGAL.gameplay.isFast = false; + WebGAL.gameplay.isFastPreview = false; } }