Skip to content

Commit a067bc3

Browse files
Merge pull request #757 from HardyNLee/fix-live2d-loading
fix: initialize live2d in PixiStage constructor
2 parents c03464d + bcc46d8 commit a067bc3

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

packages/webgal/src/Core/controller/stage/pixi/PixiController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ export default class PixiStage {
10771077
} catch (error) {
10781078
console.error('Failed to load figureCash:', error);
10791079
}
1080+
Live2D.initLive2D();
10801081
}
10811082
}
10821083

packages/webgal/src/Core/live2DCore.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,41 @@ export class Live2DCore {
3636
public SoundManager: any;
3737
public Config: any;
3838

39-
public constructor() {
40-
this.initLive2D();
39+
// 临时记录未初始化前的数据
40+
// 旧版表情混合模式
41+
private _legacyExpressionBlendMode = false;
42+
public get legacyExpressionBlendMode() {
43+
return this._legacyExpressionBlendMode;
44+
}
45+
public set legacyExpressionBlendMode(value: boolean) {
46+
this._legacyExpressionBlendMode = value;
47+
if (this.isAvailable) {
48+
this.Config.legacyExpressionBlendMode = value;
49+
}
4150
}
4251

43-
private async initLive2D() {
52+
/**
53+
* 初始化 Live 2D
54+
* 出于某些原因,直接在此类的构造函数初始化
55+
* 会导致加载 Live 2D 失败
56+
*/
57+
public async initLive2D() {
4458
try {
4559
const { Live2DModel, SoundManager, config } = await import('pixi-live2d-display-webgal');
4660
this.Live2DModel = Live2DModel;
4761
this.SoundManager = SoundManager;
4862
this.Config = config;
4963
this.isAvailable = true;
5064
console.info('live2d lib load success');
65+
this.initConfig();
5166
} catch (error) {
5267
this.isAvailable = false;
5368
console.info('live2d lib load failed', error);
5469
}
5570
}
71+
72+
// 初始化配置
73+
private initConfig() {
74+
this.Config.legacyExpressionBlendMode = this._legacyExpressionBlendMode;
75+
}
5676
}

packages/webgal/src/Core/util/coreInitialFunction/infoFetcher.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getStorage, getStorageAsync, setStorage } from '../../controller/storag
44
import { webgalStore } from '@/store/store';
55
import { initKey } from '@/Core/controller/storage/fastSaveLoad';
66
import { WebgalParser } from '@/Core/parser/sceneParser';
7-
import { WebGAL } from '@/Core/WebGAL';
7+
import { Live2D, WebGAL } from '@/Core/WebGAL';
88
import { getFastSaveFromStorage, getSavesFromStorage } from '@/Core/controller/storage/savesController';
99
import { setGlobalVar } from '@/store/userDataReducer';
1010
import { setEnableAppreciationMode, setVisibility } from '@/store/GUIReducer';
@@ -60,6 +60,9 @@ export const infoFetcher = (url: string) => {
6060
if (command === 'Enable_Appreciation') {
6161
dispatch(setEnableAppreciationMode(res));
6262
}
63+
if (command === 'Legacy_Expression_Blend_Mode') {
64+
Live2D.legacyExpressionBlendMode = res === true;
65+
}
6366
}
6467
}
6568
});

0 commit comments

Comments
 (0)