Skip to content

Commit 200af92

Browse files
Merge pull request #874 from xiaoxustudio/fix/fast-button-state
fix: fast button state error
2 parents 17b098a + 70beeae commit 200af92

4 files changed

Lines changed: 24 additions & 12 deletions

File tree

packages/webgal/src/Core/Modules/gamePlay.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
import PixiStage from '@/Core/controller/stage/pixi/PixiController';
22
import { PerformController } from '@/Core/Modules/perform/performController';
3+
import { setFastButton } from '../controller/gamePlay/fastSkip';
4+
import { setAutoButton } from '../controller/gamePlay/autoPlay';
35

46
/**
57
* 游戏运行时变量
68
*/
79
export class Gameplay {
8-
public isAuto = false;
9-
public isFast = false;
1010
public autoInterval: ReturnType<typeof setInterval> | null = null;
1111
public fastInterval: ReturnType<typeof setInterval> | null = null;
1212
public autoTimeout: ReturnType<typeof setTimeout> | null = null;
1313
public pixiStage: PixiStage | null = null;
1414
public performController = new PerformController();
15+
16+
/* 有图标状态需求 */
17+
private _isAuto = false;
18+
public get isAuto() {
19+
return this._isAuto;
20+
}
21+
public set isAuto(value: boolean) {
22+
this._isAuto = value;
23+
setAutoButton(value);
24+
}
25+
private _isFast = false;
26+
public get isFast() {
27+
return this._isFast;
28+
}
29+
public set isFast(value: boolean) {
30+
this._isFast = value;
31+
setFastButton(value);
32+
}
33+
1534
public resetGamePlay() {
1635
this.isAuto = false;
1736
this.isFast = false;

packages/webgal/src/Core/controller/gamePlay/autoPlay.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { WebGAL } from '@/Core/WebGAL';
99
* 设置 autoplay 按钮的激活与否
1010
* @param on
1111
*/
12-
const setButton = (on: boolean) => {
12+
export const setAutoButton = (on: boolean) => {
1313
const autoIcon = document.getElementById('Button_ControlPanel_auto');
1414
if (autoIcon) {
1515
if (on) {
@@ -23,7 +23,6 @@ const setButton = (on: boolean) => {
2323
*/
2424
export const stopAuto = () => {
2525
WebGAL.gameplay.isAuto = false;
26-
setButton(false);
2726
if (WebGAL.gameplay.autoInterval !== null) {
2827
clearInterval(WebGAL.gameplay.autoInterval);
2928
WebGAL.gameplay.autoInterval = null;
@@ -44,7 +43,6 @@ export const switchAuto = () => {
4443
} else {
4544
// 当前不在自动播放
4645
WebGAL.gameplay.isAuto = true;
47-
setButton(true);
4846
WebGAL.gameplay.autoInterval = setInterval(autoPlay, 100);
4947
}
5048
};

packages/webgal/src/Core/controller/gamePlay/fastSkip.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { SYSTEM_CONFIG } from '@/config';
1010
* 设置 fast 按钮的激活与否
1111
* @param on
1212
*/
13-
const setButton = (on: boolean) => {
13+
export const setFastButton = (on: boolean) => {
1414
const autoIcon = document.getElementById('Button_ControlPanel_fast');
1515
if (autoIcon) {
1616
if (on) {
@@ -19,8 +19,6 @@ const setButton = (on: boolean) => {
1919
}
2020
};
2121

22-
export { setButton as setFastButton };
23-
2422
/**
2523
* 停止快进模式
2624
*/
@@ -29,7 +27,6 @@ export const stopFast = () => {
2927
return;
3028
}
3129
WebGAL.gameplay.isFast = false;
32-
setButton(false);
3330
if (WebGAL.gameplay.fastInterval !== null) {
3431
clearInterval(WebGAL.gameplay.fastInterval);
3532
WebGAL.gameplay.fastInterval = null;
@@ -44,7 +41,6 @@ export const startFast = () => {
4441
return;
4542
}
4643
WebGAL.gameplay.isFast = true;
47-
setButton(true);
4844
WebGAL.gameplay.fastInterval = setInterval(() => {
4945
nextSentence();
5046
}, SYSTEM_CONFIG.fast_timeout);

packages/webgal/src/hooks/useHotkey.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,13 @@ export function useMouseWheel() {
143143
if (WebGAL.gameplay.isFast) stopFast();
144144
WebGAL.gameplay.isFast = true;
145145
// 滚轮视作快进
146-
setFastButton(true);
147146
setTimeout(() => {
148147
WebGAL.gameplay.isFast = false;
149-
setFastButton(false);
150148
}, 150);
151149
next();
152150
}
153151
}, []);
152+
154153
useMounted(() => {
155154
document.addEventListener('wheel', handleMouseWheel);
156155
});

0 commit comments

Comments
 (0)