diff --git a/src/baseState.ts b/src/baseScene.ts similarity index 53% rename from src/baseState.ts rename to src/baseScene.ts index 4788e93..3b278b1 100644 --- a/src/baseState.ts +++ b/src/baseScene.ts @@ -1,15 +1,15 @@ -import {StateManager} from "./stateManager"; -import {IState} from "./IState"; +import {SceneManager} from "./sceneManager"; +import {IScene} from "./iScene"; -export class BaseState extends PIXI.Container implements IState { +export class BaseScene extends PIXI.Container implements IScene { public app: PIXI.Application|null; - public states: StateManager|null; + public scenes: SceneManager|null; constructor() { super(); this.app = null; - this.states = null; + this.scenes = null; } public init(): void {} diff --git a/src/iScene.ts b/src/iScene.ts new file mode 100644 index 0000000..c05c2a7 --- /dev/null +++ b/src/iScene.ts @@ -0,0 +1,10 @@ +import {SceneManager} from "./sceneManager"; + +export interface IScene extends PIXI.Container { + app: PIXI.Application|null; + scenes: SceneManager|null; + init(): void; + start(): void; + stop(): void; + update(delta: number): void; +} diff --git a/src/iState.ts b/src/iState.ts deleted file mode 100644 index 1943836..0000000 --- a/src/iState.ts +++ /dev/null @@ -1,10 +0,0 @@ -import {StateManager} from "./stateManager"; - -export interface IState extends PIXI.Container { - app: PIXI.Application|null; - states: StateManager|null; - init(): void; - start(): void; - stop(): void; - update(delta: number): void; -} diff --git a/src/index.ts b/src/index.ts index f850c0b..0c1c4bf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ -export {BaseState} from "./baseState"; -export {StateManager} from "./stateManager"; -export {IState} from "./iState"; +export {BaseScene} from "./baseScene"; +export {SceneManager} from "./sceneManager"; +export {IScene} from "./iScene"; diff --git a/src/stateManager.ts b/src/sceneManager.ts similarity index 63% rename from src/stateManager.ts rename to src/sceneManager.ts index 591c6a8..a3be54a 100644 --- a/src/stateManager.ts +++ b/src/sceneManager.ts @@ -1,37 +1,37 @@ -import {IState} from "./iState"; +import {IScene} from "./iScene"; -export class StateManager { +export class SceneManager { private app: PIXI.Application; - private states: {[name: string]: IState}; + private scenes: {[name: string]: IScene}; private current: string|null; constructor(app: PIXI.Application) { this.app = app; - this.states = {}; + this.scenes = {}; this.current = null; // Listen for animate update app.ticker.add(this.update.bind(this)); } private update(delta: number): void { - let active: IState|null = this.active; + let active: IScene|null = this.active; if (active) { active.update(delta); } } - public add(name: string, state: IState): void { + public add(name: string, scene: IScene): void { if (this.contains(name)) { return; } - this.states[name] = state; - state.app = this.app; - state.states = this; - state.init(); + this.scenes[name] = scene; + scene.app = this.app; + scene.scenes = this; + scene.init(); } public contains(name: string): boolean { - return !!this.states[name]; + return !!this.scenes[name]; } public start(name: string): void { @@ -40,7 +40,7 @@ export class StateManager { } // Stop current - let active: IState|null = this.active; + let active: IScene|null = this.active; if (active) { active.stop(); this.app.stage.removeChild(active); @@ -54,7 +54,7 @@ export class StateManager { } } - public get active(): IState|null { - return this.current ? this.states[this.current] : null; + public get active(): IScene|null { + return this.current ? this.scenes[this.current] : null; } }