2017-01-13 16:19:51 +01:00
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
|
2017-06-16 18:45:25 +02:00
|
|
|
if (!this.loaded) {
|
|
|
|
console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-01-13 16:19:51 +01:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
};
|