@@ -2,67 +2,73 @@ import { webgalStore } from '@/store/store';
22import { setGlobalVar } from '@/store/userDataReducer' ;
33import { setEnableAppreciationMode } from '@/store/GUIReducer' ;
44import { Live2D , WebGAL } from '@/Core/WebGAL' ;
5- import { WebgalParser } from '@/Core/parser/sceneParser' ;
65import { getStorageAsync , setStorage } from '@/Core/controller/storage/storageController' ;
76import { initKey } from '@/Core/controller/storage/fastSaveLoad' ;
87import { getFastSaveFromStorage , getSavesFromStorage } from '@/Core/controller/storage/savesController' ;
98import { logger } from '@/Core/util/logger' ;
109import axios from 'axios' ;
1110
11+ interface IWebgalConfig {
12+ gameName ?: string ; // 游戏名称
13+ gameKey ?: string ; // 游戏Key
14+ gameLogo ?: string [ ] ; // 游戏Logo
15+ titleImage ?: string ; // 标题图片
16+ titleBgm ?: string ; // 标题背景音乐
17+ defaultLanguage ?: string ; // 默认语言
18+ enableAppreciation ?: boolean ; // 启用鉴赏功能
19+ enablePanic ?: boolean ; // 启用紧急回避
20+ enableLegacyExpressionBlendMode ?: boolean ; // 启用旧版 Live2D 表情混合模式
21+ }
22+
1223/**
1324 * 获取游戏信息
1425 * @param url 游戏信息路径
1526 */
16- export const infoFetcher = ( url : string ) => {
27+ export const infoFetcher = async ( url : string ) => {
1728 const dispatch = webgalStore . dispatch ;
18- axios . get ( url ) . then ( async ( r ) => {
19- let gameConfigRaw : string = r . data ;
20- let gameConfig = WebgalParser . parseConfig ( gameConfigRaw ) ;
21- logger . info ( '获取到游戏信息' , gameConfig ) ;
22- // 先把 key 找到并设置了
23- const keyItem = gameConfig . find ( ( e ) => e . command === 'Game_key' ) ;
24- WebGAL . gameKey = ( keyItem ?. args ?. [ 0 ] as string ) ?? '' ;
25- initKey ( ) ;
26- await getStorageAsync ( ) ;
27- getFastSaveFromStorage ( ) ;
28- getSavesFromStorage ( 0 , 0 ) ;
29- // 按照游戏的配置开始设置对应的状态
30- gameConfig . forEach ( ( e ) => {
31- const { command, args } = e ;
32- if ( args . length > 0 ) {
33- if ( args . length > 1 ) {
34- dispatch (
35- setGlobalVar ( {
36- key : command ,
37- value : args . join ( '|' ) ,
38- } ) ,
39- ) ;
40- } else {
41- let res : any = args [ 0 ] . trim ( ) ;
42- if ( / ^ ( t r u e | f a l s e ) $ / g. test ( args [ 0 ] ) ) {
43- res = res === 'true' ;
44- } else if ( / ^ [ 0 - 9 ] + \. ? [ 0 - 9 ] + $ / g. test ( args [ 0 ] ) ) {
45- res = Number ( res ) ;
46- }
47-
48- dispatch (
49- setGlobalVar ( {
50- key : command ,
51- value : res ,
52- } ) ,
53- ) ;
54-
55- if ( command === 'Enable_Appreciation' ) {
56- dispatch ( setEnableAppreciationMode ( res ) ) ;
57- }
58- if ( command === 'Legacy_Expression_Blend_Mode' ) {
59- Live2D . legacyExpressionBlendMode = res === true ;
60- }
61- }
62- }
63- } ) ;
64- // @ts -expect-error renderPromiseResolve is a global variable
65- window . renderPromiseResolve ( ) ;
66- setStorage ( ) ;
67- } ) ;
29+ const resp = await axios . get ( url ) ;
30+ const gameConfig : IWebgalConfig = resp . data ;
31+ logger . info ( '获取到游戏信息' , gameConfig ) ;
32+ // 先把 key 找到并设置了
33+ WebGAL . gameKey = gameConfig . gameKey ?? '' ;
34+ initKey ( ) ;
35+ await getStorageAsync ( ) ;
36+ getFastSaveFromStorage ( ) ;
37+ getSavesFromStorage ( 0 , 0 ) ;
38+ // 将游戏配置写入为全局变量
39+ for ( const [ key , value ] of Object . entries ( gameConfig ) ) {
40+ if ( value === undefined ) continue ;
41+ if ( typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string' ) {
42+ dispatch (
43+ setGlobalVar ( {
44+ key : key ,
45+ value : value ,
46+ } ) ,
47+ ) ;
48+ } else if ( Array . isArray ( value ) ) {
49+ dispatch (
50+ setGlobalVar ( {
51+ key : key ,
52+ value : value . join ( '|' ) ,
53+ } ) ,
54+ ) ;
55+ } else {
56+ dispatch (
57+ setGlobalVar ( {
58+ key : key ,
59+ value : String ( value ) ,
60+ } ) ,
61+ ) ;
62+ }
63+ }
64+ // 配置游戏
65+ if ( gameConfig . enableAppreciation !== undefined ) {
66+ dispatch ( setEnableAppreciationMode ( gameConfig . enableAppreciation ) ) ;
67+ }
68+ if ( gameConfig . enableLegacyExpressionBlendMode !== undefined ) {
69+ Live2D . legacyExpressionBlendMode = gameConfig . enableLegacyExpressionBlendMode ;
70+ }
71+ // @ts -expect-error renderPromiseResolve is a global variable
72+ window . renderPromiseResolve ( ) ;
73+ setStorage ( ) ;
6874} ;
0 commit comments