r3-legacy/src/game-lib-number.js

76 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-01-29 12:42:46 +01:00
/**
* Runtime vector2 for updating instance objects
* @param apiNumber GameLib.API.Number
* @param parentObject
* @constructor
*/
GameLib.Number = function (
apiNumber,
parentObject
) {
if (GameLib.Utils.UndefinedOrNull(apiNumber)) {
apiNumber = {};
}
GameLib.API.Number.call(
this,
apiNumber
);
if (GameLib.Utils.UndefinedOrNull(parentObject)) {
parentObject = null;
}
this.parentObject = parentObject;
this.createInstance();
};
GameLib.Number.prototype = Object.create(GameLib.API.Number.prototype);
GameLib.Number.prototype.constructor = GameLib.Number;
/**
* Creates an instance vector2
* @returns {*}
*/
GameLib.Number.prototype.createInstance = function() {
this.instance = {};
};
/**
* Updates the instance vector, calls updateInstance on the parent object
*/
GameLib.Number.prototype.updateInstance = function(property, parentProperty) {
if (property === 'value') {
if (this.parentObject && this.parentObject.updateInstance) {
this.parentObject.updateInstance(parentProperty);
}
}
if (property === 'grain') {
console.warn('todo: update number instance grain');
}
if (property === 'min') {
console.warn('todo: update number instance min');
}
if (property === 'max') {
console.warn('todo: update number instance max');
}
};
/**
* Converts runtime vector to API Vector
* @returns {GameLib.API.Number}
*/
GameLib.Number.prototype.toApiObject = function() {
return new GameLib.API.Number(
this.value,
this.grain,
this.min,
this.max
);
};