Skip to content

Commit fe65546

Browse files
Merge pull request #664 from nini22P/font-optimization
feat: add debug command `FONT_OPTIMIZATION`
2 parents 8eeb4e9 + 9ab1e56 commit fe65546

5 files changed

Lines changed: 55 additions & 29 deletions

File tree

packages/webgal/src/Core/util/syncWithEditor/webSocketFunc.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { webgalStore } from '@/store/store';
66
import { sceneParser, WebgalParser } from '@/Core/parser/sceneParser';
77
import { runScript } from '@/Core/controller/gamePlay/runScript';
88
import { nextSentence } from '@/Core/controller/gamePlay/nextSentence';
9-
import { setVisibility } from '@/store/GUIReducer';
9+
import { setFontOptimization, setVisibility } from '@/store/GUIReducer';
1010
import { resetStage } from '@/Core/controller/stage/resetStage';
1111
import { ISentence } from '@/Core/controller/scene/sceneInterface';
1212

@@ -97,6 +97,10 @@ export const webSocketFunc = () => {
9797
nextSentence();
9898
}, 100);
9999
}
100+
if (message.command === DebugCommand.FONT_OPTIMIZATION) {
101+
const command = message.message;
102+
webgalStore.dispatch(setFontOptimization(command === 'true'));
103+
}
100104
};
101105
socket.onerror = (e) => {
102106
logger.info('当前没有连接到 Terre 编辑器');

packages/webgal/src/Stage/TextBox/TextBox.tsx

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,43 @@ export interface EnhancedNode {
2020
}
2121

2222
export const TextBox = () => {
23+
const stageState = useSelector((state: RootState) => state.stage);
24+
const guiState = useSelector((state: RootState) => state.GUI);
25+
const userDataState = useSelector((state: RootState) => state.userData);
26+
const textDelay = useTextDelay(userDataState.optionData.textSpeed);
27+
const textDuration = useTextAnimationDuration(userDataState.optionData.textSpeed);
28+
let size = getTextSize(userDataState.optionData.textSize) + '%';
29+
const font = useFontFamily();
30+
const isText = stageState.showText !== '' || stageState.showName !== '';
31+
let textSizeState = userDataState.optionData.textSize;
32+
if (isText && stageState.showTextSize !== -1) {
33+
size = getTextSize(stageState.showTextSize) + '%';
34+
textSizeState = stageState.showTextSize;
35+
}
36+
const lineLimit = match(textSizeState)
37+
.with(textSize.small, () => 3)
38+
.with(textSize.medium, () => 2)
39+
.with(textSize.large, () => 2)
40+
.default(() => 2);
41+
// 拆字
42+
const textArray = compileSentence(stageState.showText, lineLimit);
43+
const isHasName = stageState.showName !== '';
44+
const showName = compileSentence(stageState.showName, lineLimit);
45+
const currentConcatDialogPrev = stageState.currentConcatDialogPrev;
46+
const currentDialogKey = stageState.currentDialogKey;
47+
const miniAvatar = stageState.miniAvatar;
48+
const textboxOpacity = userDataState.optionData.textboxOpacity;
49+
const Textbox = IMSSTextbox;
50+
const fontOptimization = guiState.fontOptimization;
51+
2352
const [isShowStroke, setIsShowStroke] = useState(true);
2453

2554
useEffect(() => {
55+
if (!fontOptimization) {
56+
setIsShowStroke(true);
57+
return;
58+
}
59+
2660
const handleResize = () => {
2761
const targetHeight = SCREEN_CONSTANTS.height;
2862
const targetWidth = SCREEN_CONSTANTS.width;
@@ -46,34 +80,8 @@ export const TextBox = () => {
4680
return () => {
4781
window.removeEventListener('resize', handleResize);
4882
};
49-
}, []);
83+
}, [fontOptimization]);
5084

51-
const stageState = useSelector((state: RootState) => state.stage);
52-
const userDataState = useSelector((state: RootState) => state.userData);
53-
const textDelay = useTextDelay(userDataState.optionData.textSpeed);
54-
const textDuration = useTextAnimationDuration(userDataState.optionData.textSpeed);
55-
let size = getTextSize(userDataState.optionData.textSize) + '%';
56-
const font = useFontFamily();
57-
const isText = stageState.showText !== '' || stageState.showName !== '';
58-
let textSizeState = userDataState.optionData.textSize;
59-
if (isText && stageState.showTextSize !== -1) {
60-
size = getTextSize(stageState.showTextSize) + '%';
61-
textSizeState = stageState.showTextSize;
62-
}
63-
const lineLimit = match(textSizeState)
64-
.with(textSize.small, () => 3)
65-
.with(textSize.medium, () => 2)
66-
.with(textSize.large, () => 2)
67-
.default(() => 2);
68-
// 拆字
69-
const textArray = compileSentence(stageState.showText, lineLimit);
70-
const isHasName = stageState.showName !== '';
71-
const showName = compileSentence(stageState.showName, lineLimit);
72-
const currentConcatDialogPrev = stageState.currentConcatDialogPrev;
73-
const currentDialogKey = stageState.currentDialogKey;
74-
const miniAvatar = stageState.miniAvatar;
75-
const textboxOpacity = userDataState.optionData.textboxOpacity;
76-
const Textbox = IMSSTextbox;
7785
return (
7886
<Textbox
7987
textArray={textArray}

packages/webgal/src/store/GUIReducer.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const initState: IGuiState = {
2828
isEnterGame: false,
2929
isShowLogo: true,
3030
enableAppreciationMode: false, // Paf87
31+
fontOptimization: false,
3132
};
3233

3334
/**
@@ -76,10 +77,20 @@ const GUISlice = createSlice({
7677
setEnableAppreciationMode: (state, action: PayloadAction<boolean>) => {
7778
state.enableAppreciationMode = action.payload;
7879
},
80+
setFontOptimization: (state, action: PayloadAction<boolean>) => {
81+
state.fontOptimization = action.payload;
82+
},
7983
},
8084
});
8185

82-
export const { setVisibility, setMenuPanelTag, setGuiAsset, setLogoImage, setEnableAppreciationMode } = GUISlice.actions;
86+
export const {
87+
setVisibility,
88+
setMenuPanelTag,
89+
setGuiAsset,
90+
setLogoImage,
91+
setEnableAppreciationMode,
92+
setFontOptimization,
93+
} = GUISlice.actions;
8394
export default GUISlice.reducer;
8495

8596
// export function GuiStateStore(): GuiStore {

packages/webgal/src/store/guiInterface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface IGuiState {
3030
isEnterGame: boolean;
3131
isShowLogo: boolean;
3232
enableAppreciationMode: boolean; // Pc102
33+
fontOptimization: boolean; // 字体优化
3334
}
3435

3536
export type componentsVisibility = Pick<

packages/webgal/src/types/debugProtocol.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export enum DebugCommand {
1515
SET_COMPONENT_VISIBILITY,
1616
// 临时场景
1717
TEMP_SCENE,
18+
// 字体优化
19+
FONT_OPTIMIZATION,
1820
}
1921

2022
export interface IDebugMessage {

0 commit comments

Comments
 (0)