Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: global setVar #442

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ export const scriptExecutor = () => {
// 同步当前舞台数据
currentStageState = webgalStore.getState().stage;
const allState = {
'currentStageState': currentStageState,
'globalGameVar': webgalStore.getState().userData.globalGameVar
}
currentStageState: currentStageState,
globalGameVar: webgalStore.getState().userData.globalGameVar,
};
logger.debug('本条语句执行结果', allState);
// 保存 backlog
if (isSaveBacklog) {
Expand Down
5 changes: 3 additions & 2 deletions packages/webgal/src/Core/gameScripts/setVar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { compile } from 'angular-expressions';
import { setGlobalVar } from '@/store/userDataReducer';
import { ActionCreatorWithPayload } from '@reduxjs/toolkit';
import { ISetGameVar } from '@/store/stageInterface';
import { syncStorageFast } from '@/Core/controller/storage/storageController';

/**
* 设置变量
* @param sentence
*/
export const setVar = (sentence: ISentence): IPerform => {
let setGlobal: boolean = false;
let setGlobal = false;
sentence.args.forEach((e) => {
if (e.key === 'global') {
setGlobal = true;
Expand Down Expand Up @@ -60,6 +61,7 @@ export const setVar = (sentence: ISentence): IPerform => {
}
if (setGlobal) {
logger.debug('设置全局变量:', { key, value: webgalStore.getState().userData.globalGameVar[key] });
syncStorageFast();
} else {
logger.debug('设置变量:', { key, value: webgalStore.getState().stage.GameVar[key] });
}
Expand All @@ -75,7 +77,6 @@ export const setVar = (sentence: ISentence): IPerform => {
};
};


export function getValueFromState(key: string) {
let ret: number | string | boolean = 0;
if (webgalStore.getState().stage.GameVar.hasOwnProperty(key)) {
Expand Down
6 changes: 3 additions & 3 deletions packages/webgal/src/Core/gameScripts/showVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export const showVars = (sentence: ISentence): IPerform => {
const dispatch = webgalStore.dispatch;
// 设置文本显示
const allVar = {
'stageGameVar': stageState.GameVar,
'globalGameVar': userDataState.globalGameVar
}
stageGameVar: stageState.GameVar,
globalGameVar: userDataState.globalGameVar,
};
dispatch(setStage({ key: 'showText', value: JSON.stringify(allVar) }));
dispatch(setStage({ key: 'showName', value: '展示变量' }));
logger.debug('展示变量:', allVar);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import '../../gameScripts/pixi/performs/cherryBlossoms';
import '../../gameScripts/pixi/performs/rain';
import '../../gameScripts/pixi/performs/snow';
import '../../gameScripts/pixi/performs/snow';
22 changes: 11 additions & 11 deletions packages/webgal/src/Stage/Stage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react';
import React, { FC } from 'react';
import styles from './stage.module.scss';
import { TextBox } from './TextBox/TextBox';
import { AudioContainer } from './AudioContainer/AudioContainer';
Expand All @@ -17,15 +17,17 @@ import { WebGAL } from '@/Core/WebGAL';
// import OldStage from '@/Components/Stage/OldStage/OldStage';

function inTextBox(event: React.MouseEvent) {
const tb = document.getElementById("textBoxMain")
const tb = document.getElementById('textBoxMain');
if (!tb) {
return false
return false;
}
var bounds = tb.getBoundingClientRect();
return event.clientX > bounds.left &&
let bounds = tb.getBoundingClientRect();
return (
event.clientX > bounds.left &&
event.clientX < bounds.right &&
event.clientY > bounds.top &&
event.clientY < bounds.bottom
);
}

export const Stage: FC = () => {
Expand All @@ -37,12 +39,12 @@ export const Stage: FC = () => {

const checkPosition = (event: React.MouseEvent) => {
if (!GUIState.controlsVisibility && inTextBox(event)) {
dispatch(setVisibility({ component: 'controlsVisibility', visibility: true }))
dispatch(setVisibility({ component: 'controlsVisibility', visibility: true }));
}
if (GUIState.controlsVisibility && !inTextBox(event)) {
dispatch(setVisibility({ component: 'controlsVisibility', visibility: false }))
dispatch(setVisibility({ component: 'controlsVisibility', visibility: false }));
}
}
};

return (
<div className={styles.MainStage_main}>
Expand Down Expand Up @@ -70,9 +72,7 @@ export const Stage: FC = () => {
}}
id="FullScreenClick"
style={{ width: '100%', height: '100%', position: 'absolute', zIndex: '12', top: '0' }}
onMouseMove={
(e) => !GUIState.showControls && checkPosition(e)
}
onMouseMove={(e) => !GUIState.showControls && checkPosition(e)}
/>
<IntroContainer />
</div>
Expand Down
17 changes: 7 additions & 10 deletions packages/webgal/src/UI/BottomControlPanel/BottomControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
DoubleDown,
DoubleUp,
Lock,
Unlock
Unlock,
} from '@icon-park/react';
import styles from './bottomControlPanel.module.scss';
import { switchAuto } from '@/Core/controller/gamePlay/autoPlay';
Expand Down Expand Up @@ -77,10 +77,7 @@ export const BottomControlPanel = () => {
// <div className={styles.ToCenter}>
<>
{GUIStore.showTextBox && stageState.enableFilm === '' && (
<div
className={styles.main}
style={{visibility: GUIStore.controlsVisibility ? "visible" : "hidden"}}
>
<div className={styles.main} style={{ visibility: GUIStore.controlsVisibility ? 'visible' : 'hidden' }}>
{GUIStore.showTextBox && (
<span
className={styles.singleButton}
Expand Down Expand Up @@ -307,11 +304,11 @@ export const BottomControlPanel = () => {
}}
onMouseEnter={playSeEnter}
>
{
GUIStore.showControls ?
(<Lock className={styles.button} theme="outline" size={size} fill="#f5f5f7" strokeWidth={strokeWidth} />) :
(<Unlock className={styles.button} theme="outline" size={size} fill="#f5f5f7" strokeWidth={strokeWidth} />)
}
{GUIStore.showControls ? (
<Lock className={styles.button} theme="outline" size={size} fill="#f5f5f7" strokeWidth={strokeWidth} />
) : (
<Unlock className={styles.button} theme="outline" size={size} fill="#f5f5f7" strokeWidth={strokeWidth} />
)}
</span>
</div>
)}
Expand Down
4 changes: 2 additions & 2 deletions packages/webgal/src/hooks/useValue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState} from "react";
import { useState } from 'react';

export function useValue<T>(initialState: T) {
const [value, setValue] = useState<T>(initialState);
Expand All @@ -13,6 +13,6 @@ export function useValue<T>(initialState: T) {
},
set value(newValue) {
this.set(newValue);
}
},
};
}
Loading