Skip to content

Commit

Permalink
Rename to scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
florisdh committed Jul 18, 2019
1 parent a07425e commit fff1e91
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
10 changes: 5 additions & 5 deletions src/baseState.ts → src/baseScene.ts
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down
10 changes: 10 additions & 0 deletions src/iScene.ts
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 0 additions & 10 deletions src/iState.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
28 changes: 14 additions & 14 deletions src/stateManager.ts → src/sceneManager.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);
Expand All @@ -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;
}
}

0 comments on commit fff1e91

Please sign in to comment.