Update framework
This commit is contained in:
0
framework/scene/index.d.ts
vendored
Normal file
0
framework/scene/index.d.ts
vendored
Normal file
0
framework/scene/index.js
Normal file
0
framework/scene/index.js
Normal file
12
framework/scene/manager.d.ts
vendored
Normal file
12
framework/scene/manager.d.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Scene } from './scene';
|
||||
export declare class SceneManager {
|
||||
scenes: Map<string, Scene>;
|
||||
currentScene: Scene;
|
||||
defaultScene: Scene;
|
||||
constructor();
|
||||
init(): void;
|
||||
addScene(scene: Scene): void;
|
||||
removeScene(scene: Scene): void;
|
||||
switchTo(scene: Scene): void;
|
||||
setDefaultScene(scene: Scene): void;
|
||||
}
|
33
framework/scene/manager.js
Normal file
33
framework/scene/manager.js
Normal file
@@ -0,0 +1,33 @@
|
||||
export class SceneManager {
|
||||
constructor() {
|
||||
this.scenes = new Map();
|
||||
}
|
||||
init() {
|
||||
if (this.defaultScene) {
|
||||
this.switchTo(this.defaultScene);
|
||||
}
|
||||
}
|
||||
addScene(scene) {
|
||||
this.scenes.set(scene.id, scene);
|
||||
}
|
||||
removeScene(scene) {
|
||||
if (scene === this.currentScene)
|
||||
this.currentScene.onDeactivate();
|
||||
this.scenes.delete(scene.id);
|
||||
}
|
||||
switchTo(scene) {
|
||||
if (scene === this.currentScene)
|
||||
return;
|
||||
let data;
|
||||
if (this.currentScene) {
|
||||
this.currentScene.onDeactivate();
|
||||
data = this.currentScene.data;
|
||||
}
|
||||
this.currentScene = this.scenes.get(scene.id);
|
||||
this.currentScene.onSwitch(data);
|
||||
this.currentScene.onActivate(this);
|
||||
}
|
||||
setDefaultScene(scene) {
|
||||
this.defaultScene = scene;
|
||||
}
|
||||
}
|
10
framework/scene/scene.d.ts
vendored
Normal file
10
framework/scene/scene.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { SceneManager } from './manager';
|
||||
export interface Scene {
|
||||
id: string;
|
||||
data: any;
|
||||
onActivate(manager: SceneManager): any;
|
||||
onDeactivate(): any;
|
||||
onSwitch(data: any): any;
|
||||
update(dt: number): any;
|
||||
updateDraw(): any;
|
||||
}
|
1
framework/scene/scene.js
Normal file
1
framework/scene/scene.js
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
Reference in New Issue
Block a user