@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
41 lines (36 loc) • 1.01 kB
JavaScript
/**
* Base class for implementing reversible actions.
* Actions are intended to be used in conjunction with {@link ActionProcessor}
* @template CTX
*
* @author Alex Goldring
* @copyright Company Named Limited (c) 2025
*/
export class Action {
/**
* How much memory does this action require, used by the ActionProcessor in order to decide how much history to keep
* @return {number}
*/
computeByteSize() {
return 1;
}
/**
* Apply action
* @param {CTX} context
*/
async apply(context) {
throw new Error('Not Implemented. Needs to be overridden in subclass');
}
/**
* Revert action, restoring state to just before this action was applied
* @param {CTX} context
*/
async revert(context) {
throw new Error('Not Implemented. Needs to be overridden in subclass');
}
}
/**
* Used for quick instanceof checks
* @type {boolean}
*/
Action.prototype.isAction = true;