Skip to content

Commit

Permalink
feat: slide text speed and autoplay speed
Browse files Browse the repository at this point in the history
  • Loading branch information
ClodLingxi committed Dec 20, 2024
1 parent 3534bdd commit 3be26d1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 60 deletions.
5 changes: 3 additions & 2 deletions packages/webgal/src/Core/controller/gamePlay/autoPlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ export const autoNextSentence = () => {
* 自动播放的执行函数
*/
const autoPlay = () => {
const delay = webgalStore.getState().userData.optionData.autoSpeed;
const autoPlayDelay = 750 - 250 * delay;
const data = webgalStore.getState().userData.optionData.autoSpeed;
// 范围为 [250, 1750]
const autoPlayDelay = 250 + (100 - data) * 15;
let isBlockingAuto = false;
WebGAL.gameplay.performController.performList.forEach((e) => {
if (e.blockingAuto())
Expand Down
4 changes: 2 additions & 2 deletions packages/webgal/src/Core/gameScripts/say.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IPerform } from '@/Core/Modules/perform/performInterface';
import { playVocal } from './vocal';
import { webgalStore } from '@/store/store';
import { setStage } from '@/store/stageReducer';
import { useTextDelay } from '@/hooks/useTextOptions';
import { useTextAnimationDuration, useTextDelay } from '@/hooks/useTextOptions';
import { getRandomPerformName, PerformController } from '@/Core/Modules/perform/performController';
import { getSentenceArgByKey } from '@/Core/util/getSentenceArg';
import { textSize, voiceOption } from '@/store/userDataInterface';
Expand Down Expand Up @@ -148,7 +148,7 @@ export const say = (sentence: ISentence): IPerform => {
}

const performInitName: string = getRandomPerformName();
let endDelay = 750 - userDataState.optionData.textSpeed * 250;
let endDelay = useTextAnimationDuration(userDataState.optionData.textSpeed) / 2;
// 如果有 notend 参数,那么就不需要等待
if (isNotend) {
endDelay = 0;
Expand Down
25 changes: 8 additions & 17 deletions packages/webgal/src/UI/Menu/Options/Display/Display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,14 @@ export function Display() {
/>
</NormalOption>
<NormalOption key="textSpeed" title={t('textSpeed.title')}>
<NormalButton
textList={t('textSpeed.options.slow', 'textSpeed.options.medium', 'textSpeed.options.fast')}
functionList={[
() => {
dispatch(setOptionData({ key: 'textSpeed', value: playSpeed.slow }));
setStorage();
},
() => {
dispatch(setOptionData({ key: 'textSpeed', value: playSpeed.normal }));
setStorage();
},
() => {
dispatch(setOptionData({ key: 'textSpeed', value: playSpeed.fast }));
setStorage();
},
]}
currentChecked={userDataState.optionData.textSpeed}
<OptionSlider
initValue={userDataState.optionData.textSpeed}
uniqueID={t('textSpeed.title')}
onChange={(event) => {
const newValue = event.target.value;
dispatch(setOptionData({ key: 'textSpeed', value: Number(newValue) }));
setStorage();
}}
/>
</NormalOption>
<NormalOption key="textSize" title={t('textSize.title')}>
Expand Down
26 changes: 9 additions & 17 deletions packages/webgal/src/UI/Menu/Options/System/System.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { WebGAL } from '@/Core/WebGAL';
import useSoundEffect from '@/hooks/useSoundEffect';
import savesReducer, { ISavesData, saveActions } from '@/store/savesReducer';
import { dumpFastSaveToStorage, dumpSavesToStorage } from '@/Core/controller/storage/savesController';
import { OptionSlider } from '@/UI/Menu/Options/OptionSlider';

interface IExportGameData {
userData: IUserData;
Expand Down Expand Up @@ -104,23 +105,14 @@ export function System() {
{!showAbout && (
<>
<NormalOption key="option1" title={t('autoSpeed.title')}>
<NormalButton
textList={t('autoSpeed.options.slow', 'autoSpeed.options.medium', 'autoSpeed.options.fast')}
functionList={[
() => {
dispatch(setOptionData({ key: 'autoSpeed', value: playSpeed.slow }));
setStorage();
},
() => {
dispatch(setOptionData({ key: 'autoSpeed', value: playSpeed.normal }));
setStorage();
},
() => {
dispatch(setOptionData({ key: 'autoSpeed', value: playSpeed.fast }));
setStorage();
},
]}
currentChecked={userDataState.optionData.autoSpeed}
<OptionSlider
initValue={userDataState.optionData.autoSpeed}
uniqueID={t('autoSpeed.title')}
onChange={(event) => {
const newValue = event.target.value;
dispatch(setOptionData({ key: 'autoSpeed', value: Number(newValue) }));
setStorage();
}}
/>
</NormalOption>
<NormalOption key="option7" title={t('language.title')}>
Expand Down
28 changes: 10 additions & 18 deletions packages/webgal/src/hooks/useTextOptions.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import { playSpeed } from '@/store/userDataInterface';

export function useTextDelay(type: playSpeed) {
switch (type) {
case playSpeed.slow:
return 80;
case playSpeed.normal:
return 35;
case playSpeed.fast:
return 3;
}
// 范围为 [startRange, step * 100 + startRange]
export function useTextDelay(data: number) {
const startRange = 3;
const step = 1.5;
return startRange + (100 - data) * step;
}

export function useTextAnimationDuration(type: playSpeed) {
switch (type) {
case playSpeed.slow:
return 800;
case playSpeed.normal:
return 350;
case playSpeed.fast:
return 200;
}
// 范围为 [startRange, step * 100 + startRange]
export function useTextAnimationDuration(data: number) {
const startRange = 200;
const step = 15;
return startRange + (100 - data) * step;
}
4 changes: 2 additions & 2 deletions packages/webgal/src/store/userDataInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export enum fullScreenOption {
*/
export interface IOptionData {
volumeMain: number; // 主音量
textSpeed: playSpeed; // 文字速度
autoSpeed: playSpeed; // 自动播放速度
textSpeed: number; // 文字速度
autoSpeed: number; // 自动播放速度
textSize: textSize;
vocalVolume: number; // 语音音量
bgmVolume: number; // 背景音乐音量
Expand Down
4 changes: 2 additions & 2 deletions packages/webgal/src/store/userDataReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import { ISetGameVar } from './stageInterface';
const initialOptionSet: IOptionData = {
slPage: 1,
volumeMain: 100, // 主音量
textSpeed: playSpeed.normal, // 文字速度
autoSpeed: playSpeed.normal, // 自动播放速度
textSpeed: 50, // 文字速度
autoSpeed: 50, // 自动播放速度
textSize: textSize.medium,
vocalVolume: 100, // 语音音量
bgmVolume: 25, // 背景音乐音量
Expand Down

0 comments on commit 3be26d1

Please sign in to comment.