Barely working basic playback
This commit is contained in:
parent
98a443e298
commit
9b5198a6ce
19 changed files with 406 additions and 24 deletions
|
@ -4,3 +4,4 @@ configure_file(class.js class.js)
|
|||
configure_file(subscribable.js subscribable.js)
|
||||
configure_file(globalMethods.js globalMethods.js)
|
||||
configure_file(enum.js enum.js)
|
||||
configure_file(stateMachine.js stateMachine)
|
||||
|
|
33
libjs/utils/stateMachine.js
Normal file
33
libjs/utils/stateMachine.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
"use strict";
|
||||
|
||||
var Subscribable = require("./subscribable");
|
||||
|
||||
var StateMachine = Subscribable.inherit({
|
||||
className: "StateMachine",
|
||||
constructor: function (initialState, graph) {
|
||||
Subscribable.fn.constructor.call(this);
|
||||
|
||||
this._state = initialState;
|
||||
this._graph = graph;
|
||||
},
|
||||
manipulation: function (name) {
|
||||
var newState = this._graph[this._state][name];
|
||||
if (newState) {
|
||||
var oldState = this._state;
|
||||
this._state = newState;
|
||||
|
||||
this.trigger("stateChanged", {
|
||||
newState: newState,
|
||||
manipulation: name,
|
||||
oldState: oldState
|
||||
});
|
||||
} else {
|
||||
this.trigger("stateMissed");
|
||||
}
|
||||
},
|
||||
state: function () {
|
||||
return this._state;
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = StateMachine;
|
Loading…
Add table
Add a link
Reference in a new issue