/** * Coder * @param id * @param name * @param coderType * @constructor */ GameLib.D3.Coder = function Coder( id, name, coderType ) { if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Coder (' + id + ')'; } this.name = name; if (GameLib.Utils.UndefinedOrNull(coderType)) { coderType = GameLib.D3.Coder.CODER_TYPE_CODE_MIRROR; } this.coderType = coderType; this.instance = this.createInstance(); }; /** * GameLib.D3.Coder Types * @type {number} */ GameLib.D3.Coder.CODER_TYPE_CODE_MIRROR = 0x1; /** * @returns {THREE.Coder} */ GameLib.D3.Coder.prototype.createInstance = function(update) { var instance = null; if (update) { instance = this.instance; } else { instance = CodeMirror; } return instance; }; /** * Updates the instance with the current state */ GameLib.D3.Coder.prototype.updateInstance = function() { this.instance = this.createInstance(true); }; /** * True if THREE physics * @returns {boolean} */ GameLib.D3.Coder.prototype.isCodeMirror = function() { return (this.coderType == GameLib.D3.Coder.CODER_TYPE_CODE_MIRROR) }; /** * Logs a warning and throws an error if not cannon */ GameLib.D3.Coder.prototype.isNotCodeMirrorThrow = function() { if (this.coderType != GameLib.D3.Coder.CODER_TYPE_CODE_MIRROR) { console.warn('Only CodeMirror supported for this function'); throw new Error('Only CodeMirror supported for this function'); } };