import Scene from "../../Wolfie2D/Scene/Scene"; import Label, { HAlign } from "../../Wolfie2D/Nodes/UIElements/Label"; import Story from "../Tools/DataTypes/Story"; import { UIElementType } from "../../Wolfie2D/Nodes/UIElements/UIElementTypes"; import Vec2 from "../../Wolfie2D/DataTypes/Vec2"; import Color from "../../Wolfie2D/Utils/Color"; import Layer from "../../Wolfie2D/Scene/Layer"; import Sprite from "../../Wolfie2D/Nodes/Sprites/Sprite"; import { GameEventType } from "../../Wolfie2D/Events/GameEventType"; enum Mode { GAME_MODE = "GameMode", STORY_MODE = "StoryMode", PAUSE_MODE = "PauseMode", } export default class SceneWithStory extends Scene { private currentMode: Mode = Mode.GAME_MODE; private storytextLabel: Label; private storyLayer: Layer; // private primary: Layer; private story: Story; private storyProgress: number; private storySprites: Array; private storyBGMs: Array; private currentSpeaker: string; private currentContent: string; startScene(): void { // The code below are for testing only. Please comment them when submit // this.primary = this.addUILayer("primary"); // const center = this.viewport.getCenter(); // const loadStory = this.add.uiElement(UIElementType.BUTTON, "primary", { position: new Vec2(center.x, center.y), text: "LoadStory" }); // loadStory.size.set(200, 50); // loadStory.borderWidth = 2; // loadStory.borderColor = Color.WHITE; // loadStory.backgroundColor = Color.TRANSPARENT; // loadStory.onClickEventId = "loadStory"; // this.receiver.subscribe("loadStory"); } /** * This function load a story JSON from storyPath and auto display it to storyLayer * @param storyPath The path to the story JSON */ async storyLoader(storyPath: string) { this.storyLayer = this.addUILayer("story"); const response = await (await fetch(storyPath)).json(); this.story = response; if (this.story.bgm) { this.storyBGMs = new Array; this.story.bgm.forEach((bgm) => { this.load.audio(bgm.key, bgm.path); console.log("audio:", bgm.key, "path:", bgm.path); this.load.loadResourcesFromQueue(() => { console.log("finished loading audio"); this.emitter.fireEvent(GameEventType.PLAY_SOUND, { key: bgm.key, loop: false, holdReference: true }); }); this.storyBGMs.push(bgm.key); }) } this.currentSpeaker = this.story.texts[0].speaker; this.currentContent = this.story.texts[0].content; this.storytextLabel =