moody
v1.0.1
Published
Moody is a library for defining running states such as a gamestate.
Downloads
15
Readme
Moody
Moody is a library for managing different running states in a stack. Don't like the mood? Why not add a new one to the stack for a new vibe?
Install
npm install moody
API
var newMoody = require('Moody');
var moody = newMoody();
moody.push(state, ...)
Add a new state to the top of the stack. Any additional args are passed to the new state's enter callback. The previous state will have its pause callback called.
var state = {
enter: function(name) {
console.log('Hi '+ name + '!')
}
};
moody.push(state, 'mom');
// => 'Hi mom!'
moody.pop()
Remove the current state from the stack. Any arguments passed to pop are passed to the resume callback. The new state will have its resume callback called.
var state = {
leave: function() {
console.log('Bye!')
}
};
moody.push(state);
moody.pop();
// => 'Bye!'
moody.execute(functionName, ...)
Execute a function on the current state. Any additional args are passed to the state's method.
var state = {
say: function(name) {
console.log('How are you '+ name + '?!')
}
};
moody.push(state);
moody.execute('say', 'mom');
// => 'How are you mom?!'
moody.swap(state, ...)
Remove the current state from the stack and add the new state. Any additional args are passed to the new state's enter callback.
moody.current()
Return the current state.
Credits
Inspiration for this library is from vrld's hump.gamestate
License
MIT