r3-legacy/src/game-lib-d3-api-custom-code.js

74 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-01-13 16:19:51 +01:00
/**
* This component makes the parentEntity (ex. car) follow the path provided by the spline
* @param id String
* @param name String
* @param code String
* @param domElementId
* @param parentEntity
* @param args
* @constructor
*/
GameLib.D3.API.CustomCode = function (
id,
name,
code,
domElementId,
parentEntity,
args
) {
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_CUSTOM_CODE,
{
'args' : [GameLib.Component]
},
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'CustomCode (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(code)) {
code = '';
}
this.code = code;
if (GameLib.Utils.UndefinedOrNull(domElementId)) {
domElementId = "CustomCode_" + this.id;
}
this.domElementId = domElementId;
if (GameLib.Utils.UndefinedOrNull(args)) {
args = [];
}
this.args = args;
};
GameLib.D3.API.CustomCode.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.CustomCode.prototype.constructor = GameLib.D3.API.CustomCode;
/**
* Object to GameLib.D3.API.CustomCode
* @param objectComponent
* @returns {GameLib.D3.API.CustomCode}
* @constructor
*/
GameLib.D3.API.CustomCode.FromObjectComponent = function(objectComponent) {
return new GameLib.D3.API.CustomCode(
objectComponent.id,
objectComponent.name,
objectComponent.code,
objectComponent.domElementId,
objectComponent.parentEntity,
objectComponent.args
);
};