UNPKG

character-sheet

Version:

CharacterSheet library for assembling relationships between stats and modifiers.

129 lines (101 loc) 3.15 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: Operation.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: Operation.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/** * The basic definition of any operation. * * @typedef OperationDefinition {object} * @param OperationDefinition.type {string} Represents the type. (ex: 'add') */ /** * Operation Base Class * * Represents a dynamic modification to a character sheet property. */ class Operation { /** * Key-value store of modules and their types * @static * @property {object} _registeredOperations */ static _registeredOperations = {}; /** * Operation Type * * Identifies the operation in its definition. * @static * @param {String} */ static type = null; /** * @constructor * @param operationDefinition {OperationDefinition} */ constructor(operationDefinition = { type: 'missing-type' }) {} /** * Operational transformation * * @param value * @param character * * @returns {Number | String | Boolean} */ transform(value, resolver) { throw Error('Must Override Operation.prototype.transform()'); return 0; } /** * Generate a operation instance from its definition. * * @static * @param {OperationDefinition} operationDefinition A operation definition */ static from(operationDefinition) { const { type } = operationDefinition; if (this.type === type) { return new this(operationDefinition); } else if (Operation._registeredOperations[type]) { return Operation._registeredOperations[type].from(operationDefinition); } return null; } /** * Registeres a operation so that its definitions may be used dynamically. * * @param {Operation} OperationClass Any operation */ static registerOperation(OperationClass) { Operation._registeredOperations[OperationClass.type] = OperationClass; } } export default Operation; </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Add.html">Add</a></li><li><a href="Modifier.html">Modifier</a></li><li><a href="Operation.html">Operation</a></li><li><a href="Using.html">Using</a></li></ul><h3>Global</h3><ul><li><a href="global.html#RegisterWith">RegisterWith</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Dec 25 2018 11:17:38 GMT-0800 (Pacific Standard Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>