Skip to content

Commit

Permalink
fix(player): 恢复live2d语言预载机制
Browse files Browse the repository at this point in the history
  • Loading branch information
diyigemt committed Jul 31, 2023
1 parent 817663a commit 81ec9e4
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions lib/ba-story-player/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import {
utils as pixiUtils,
} from "pixijs";
import { extensions } from "pixijs";
import { watch } from "vue";
import { version } from "../package.json";
import { L2DInit } from "./layers/l2dLayer/L2D";
import { useUiState } from "./stores/state";
import { bgInit } from "@/layers/bgLayer";
import { characterInit } from "@/layers/characterLayer";
import { effectInit } from "@/layers/effectLayer";
Expand All @@ -23,8 +25,7 @@ import { translate } from "@/layers/translationLayer";
import { buildStoryIndexStackRecord } from "@/layers/translationLayer/utils";
import { PlayerConfigs, StoryUnit } from "@/types/common";
import "@pixi/sound";
import { watch } from "vue";
import { useUiState } from "./stores/state";
import { sound } from "@pixi/sound";

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand All @@ -40,7 +41,6 @@ let privateState: ReturnType<typeof initPrivateState>;
*/
const unexistL2dSoundEvent = ["sound/Nonomi_MemorialLobby_3_3"];


export function checkloadAssetAlias<T = any>(alias: string, url: string) {
if (!resourcesLoader.loadedList.includes(alias)) {
resourcesLoader.loadedList.push(alias);
Expand All @@ -49,15 +49,13 @@ export function checkloadAssetAlias<T = any>(alias: string, url: string) {
return Promise.resolve();
}


/**
* 继续播放
*/
export function continuePlay() {
eventBus.emit("continue");
}


/**
* 回收播放器资源, 让播放器回到初始状态
*/
Expand All @@ -71,7 +69,6 @@ export function dispose() {
storyHandler.isEnd = true;
}


/**
* 事件发送控制对象
*/
Expand Down Expand Up @@ -153,13 +150,16 @@ export const eventEmitter = {
this.textDone = true;
});
const { autoMode } = useUiState();
watch(() => autoMode.value, (cur) => {
if (cur) {
storyHandler.startAuto();
} else {
storyHandler.stopAuto();
watch(
() => autoMode.value,
cur => {
if (cur) {
storyHandler.startAuto();
} else {
storyHandler.stopAuto();
}
}
});
);
eventBus.on("skip", () => storyHandler.end());
eventBus.on("playVoiceJPDone", async () => {
if (storyHandler.auto) {
Expand Down Expand Up @@ -467,7 +467,6 @@ export const eventEmitter = {
},
};


/**
* 调用各层的初始化函数
*/
Expand Down Expand Up @@ -566,7 +565,6 @@ export async function init(
});
}


/**
* 资源加载处理对象
*/
Expand Down Expand Up @@ -725,16 +723,18 @@ export const resourcesLoader = {
* 添加l2d语音
*/
loadL2dVoice(audioEvents: IEventData[]) {
return;
// for (const event of audioEvents) {
// if (
// event.name.includes("MemorialLobby") &&
// !unexistL2dSoundEvent.includes(event.name)
// ) {
// const voiceUrl = utils.getResourcesUrl("l2dVoice", event.name);
// this.loadTaskList.push(loadAssetAlias(voiceUrl, voiceUrl));
// }
// }
for (const event of audioEvents) {
if (
event.name.includes("MemorialLobby") &&
!unexistL2dSoundEvent.includes(event.name)
) {
const voiceUrl = utils.getResourcesUrl("l2dVoice", event.name);
sound.add(voiceUrl, {
url: voiceUrl,
preload: true,
});
}
}
},

/**
Expand Down Expand Up @@ -842,7 +842,6 @@ export const resourcesLoader = {
},
};


/**
* 暂停播放
*/
Expand All @@ -857,13 +856,16 @@ function waitForStoryUnitPlayComplete(currentIndex: number) {

return new Promise<void>((resolve, reject) => {
const { tabActivated } = useUiState();
const watchSideEffect = watch(() => tabActivated.value, (cur) => {
if (cur) {
restart();
} else {
resetTime();
const watchSideEffect = watch(
() => tabActivated.value,
cur => {
if (cur) {
restart();
} else {
resetTime();
}
}
});
);
function resetTime() {
clearInterval(interval);
const now = Date.now();
Expand Down

0 comments on commit 81ec9e4

Please sign in to comment.