2017-01-13 16:19:51 +01:00
|
|
|
/**
|
|
|
|
* Creates a CustomCode object
|
|
|
|
* @param apiCustomCode GameLib.D3.API.CustomCode
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.D3.CustomCode = function(
|
|
|
|
apiCustomCode
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiCustomCode)) {
|
|
|
|
apiCustomCode = {};
|
|
|
|
}
|
|
|
|
|
2017-05-11 04:48:02 +02:00
|
|
|
if (apiCustomCode instanceof GameLib.D3.CustomCode) {
|
|
|
|
return apiCustomCode;
|
|
|
|
}
|
|
|
|
|
2017-01-13 16:19:51 +01:00
|
|
|
GameLib.D3.API.CustomCode.call(
|
|
|
|
this,
|
|
|
|
apiCustomCode.id,
|
|
|
|
apiCustomCode.name,
|
2017-06-16 15:49:53 +02:00
|
|
|
apiCustomCode.parentEntity,
|
2017-01-13 16:19:51 +01:00
|
|
|
apiCustomCode.code,
|
|
|
|
apiCustomCode.domElementId,
|
|
|
|
apiCustomCode.args
|
|
|
|
);
|
|
|
|
|
2017-06-16 15:49:53 +02:00
|
|
|
GameLib.Component.call(
|
|
|
|
this,
|
|
|
|
GameLib.Component.COMPONENT_CUSTOM_CODE,
|
|
|
|
{
|
|
|
|
'args' : [GameLib.Component]
|
|
|
|
}
|
|
|
|
);
|
2017-01-13 16:19:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
GameLib.D3.CustomCode.prototype = Object.create(GameLib.D3.API.CustomCode.prototype);
|
|
|
|
GameLib.D3.CustomCode.prototype.constructor = GameLib.D3.CustomCode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a camera instance of 'graphics' type (only THREE for now)
|
|
|
|
* @returns {THREE.CustomCode}
|
|
|
|
*/
|
|
|
|
GameLib.D3.CustomCode.prototype.createInstance = function(update) {
|
|
|
|
|
2017-06-16 15:49:53 +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 = function(deltaTime) {
|
|
|
|
this.args['deltaTime'] = deltaTime;
|
|
|
|
var f = new Function(this.code).apply(this.parentEntity, this.args);
|
|
|
|
f();
|
|
|
|
};
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the instance with the current state
|
|
|
|
*/
|
|
|
|
GameLib.D3.CustomCode.prototype.updateInstance = function() {
|
|
|
|
this.instance = this.createInstance(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a GameLib.D3.CustomCode to a new GameLib.D3.API.CustomCode
|
|
|
|
* @returns {GameLib.D3.API.CustomCode}
|
|
|
|
*/
|
2017-05-16 14:51:57 +02:00
|
|
|
GameLib.D3.CustomCode.prototype.toApiObject = function() {
|
2017-01-13 16:19:51 +01:00
|
|
|
|
2017-06-16 15:49:53 +02:00
|
|
|
var apiArgs = this.args.map(
|
|
|
|
function(arg) {
|
|
|
|
return GameLib.Utils.IdOrNull(arg);
|
|
|
|
}
|
|
|
|
);
|
2017-01-13 16:19:51 +01:00
|
|
|
|
|
|
|
return new GameLib.D3.API.CustomCode(
|
|
|
|
this.id,
|
|
|
|
this.name,
|
2017-06-16 15:49:53 +02:00
|
|
|
GameLib.Utils.IdOrNull(this.parentEntity),
|
2017-01-13 16:19:51 +01:00
|
|
|
this.code,
|
|
|
|
this.domElementId,
|
|
|
|
apiArgs
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts from an Object CustomCode to a GameLib.D3.CustomCode
|
|
|
|
* @param objectCustomCode Object
|
|
|
|
* @returns {GameLib.D3.CustomCode}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2017-06-14 14:21:57 +02:00
|
|
|
GameLib.D3.CustomCode.FromObject = function(objectCustomCode) {
|
2017-01-13 16:19:51 +01:00
|
|
|
|
2017-06-14 14:21:57 +02:00
|
|
|
var apiCustomCode = GameLib.D3.API.CustomCode.FromObject(objectCustomCode);
|
2017-01-13 16:19:51 +01:00
|
|
|
|
|
|
|
return new GameLib.D3.CustomCode(
|
|
|
|
apiCustomCode
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
GameLib.D3.CustomCode.prototype.update = function(deltaTime) {
|
|
|
|
this.instance(deltaTime);
|
|
|
|
};
|