Created
December 18, 2015 18:24
-
-
Save Josh-Miller/678e211edb6755e9a08e to your computer and use it in GitHub Desktop.
A state manager for Phaser v2 html5 game platform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| export const stateManager = { | |
| state: [], | |
| states: {}, | |
| currentState: function() { | |
| return this.state; | |
| }, | |
| addState: function(state, expiration, fn) { | |
| this.state.unshift(state); | |
| if (expiration) { | |
| this.expireState(state, expiration, fn); | |
| } | |
| }, | |
| removeState: function(state) { | |
| this.state.splice(this.state.indexOf(state)); | |
| }, | |
| registerState: function(name, state) { | |
| this.states[name] = state; | |
| }, | |
| expireState: function(state, expiration, fn) { | |
| setTimeout(() => { | |
| this.removeState(state); | |
| if (fn) fn(); | |
| }, expiration); | |
| }, | |
| fireStates: function() { | |
| this.currentState().map(currentState => { | |
| this.states[currentState](); | |
| }); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment