Skip to content

Commit

Permalink
refactor ws func
Browse files Browse the repository at this point in the history
  • Loading branch information
MakinoharaShoko authored and ClodLingxi committed Dec 20, 2024
1 parent 5e27a17 commit 18d7cc2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
21 changes: 7 additions & 14 deletions packages/webgal/src/Core/util/syncWithEditor/webSocketFunc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '../logger';
import { syncWithOrigine } from '@/Core/util/syncWithEditor/syncWithOrigine';
import { DebugCommand, IDebugMessage } from '@/types/debugProtocol';
import { DebugCommand, IComponentVisibilityCommand, IDebugMessage } from '@/types/debugProtocol';
import { WebGAL } from '@/Core/WebGAL';
import { webgalStore } from '@/store/store';
import { sceneParser, WebgalParser } from '@/Core/parser/sceneParser';
Expand Down Expand Up @@ -76,19 +76,12 @@ export const webSocketFunc = () => {
WebGAL.events.styleUpdate.emit();
}
if (message.command === DebugCommand.SET_COMPONENT_VISIBILITY) {
const commands = message.message;
// handle SET_COMPONENT_VISIBILITY message
const parse = (commands: string): ({ component: any; visibility: boolean } | undefined)[] => {
const command = commands.split(';');
return command.map((item) => {
const temp = item.split(':');
if (temp.length > 1) return { component: temp[0], visibility: Boolean(temp[1]) };
return undefined;
});
};
const command = parse(commands);
command.forEach((item) => {
if (item !== undefined) {
const command = message.message;

const commandData = JSON.parse(command) as IComponentVisibilityCommand[];
commandData.forEach((item) => {
if (item) {
webgalStore.dispatch(setVisibility({ component: item.component, visibility: item.visibility }));
}
});
Expand All @@ -99,7 +92,7 @@ export const webSocketFunc = () => {
WebGAL.sceneManager.sceneData.currentScene = sceneParser(command, 'temp', './temp.txt');
webgalStore.dispatch(setVisibility({ component: 'showTitle', visibility: false }));
webgalStore.dispatch(setVisibility({ component: 'showMenuPanel', visibility: false }));
// webgalStore.dispatch(setVisibility({ component: 'showPanicOverlay', visibility: false }));
webgalStore.dispatch(setVisibility({ component: 'showPanicOverlay', visibility: false }));
setTimeout(() => {
nextSentence();
}, 100);
Expand Down
22 changes: 21 additions & 1 deletion packages/webgal/src/types/debugProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export enum DebugCommand {
EXE_COMMAND,
// 重新拉取模板样式文件
REFETCH_TEMPLATE_FILES,
// 返回标题页面
// 返回主界面
SET_COMPONENT_VISIBILITY,
// 临时场景
TEMP_SCENE,
Expand All @@ -29,3 +29,23 @@ export interface IDebugMessage {
stageSyncMsg: IStageState;
};
}

export interface IComponentsVisibility {
showStarter: boolean; // 是否显示初始界面(用于使得bgm可以播放)
showTitle: boolean; // 是否显示标题界面
showMenuPanel: boolean; // 是否显示Menu界面
showTextBox: boolean;
showControls: boolean;
controlsVisibility: boolean;
showBacklog: boolean;
showExtra: boolean;
showGlobalDialog: boolean;
showPanicOverlay: boolean;
isEnterGame: boolean;
isShowLogo: boolean;
}

export interface IComponentVisibilityCommand {
component: keyof IComponentsVisibility;
visibility: boolean;
}

0 comments on commit 18d7cc2

Please sign in to comment.