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

62 lines
1.3 KiB
JavaScript

/**
* Custom Code Component
* @param id
* @param name
* @param eventId
* @param code
* @param parentEntity
* @constructor
*/
GameLib.D3.API.CustomCode = function (
id,
name,
eventId,
code,
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(eventId)) {
eventId = 42;
}
this.eventId = eventId;
if (GameLib.Utils.UndefinedOrNull(code)) {
code = 'return null;';
}
this.code = code;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
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.FromObject = function(objectComponent) {
return new GameLib.D3.API.CustomCode(
objectComponent.id,
objectComponent.name,
objectComponent.eventId,
objectComponent.code,
objectComponent.parentEntity
);
};