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

68 lines
1.3 KiB
JavaScript

/**
* Runtime Mouse
* @param apiMouse
* @returns {GameLib.Mouse}
* @constructor
*/
GameLib.Mouse = function (apiMouse) {
if (GameLib.Utils.UndefinedOrNull(apiMouse)){
apiMouse = {};
}
GameLib.API.Mouse.call(
this,
apiMouse.id,
apiMouse.name,
apiMouse.parentEntity,
apiMouse.x,
apiMouse.y
);
GameLib.Component.call(this);
};
GameLib.Mouse.prototype = Object.create(GameLib.Component.prototype);
GameLib.Mouse.prototype.constructor = GameLib.Mouse;
/**
* createInstance
*/
GameLib.Mouse.prototype.createInstance = function() {
this.instance = {};
GameLib.Component.prototype.createInstance.call(this);
};
/**
* updateInstance
* @param property
*/
GameLib.Mouse.prototype.updateInstance = function(property) {
if (
property === 'x' ||
property === 'y'
) {
this.instance.x = this.x;
this.instance.y = this.y;
return;
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**
* Converts GameLib.Mouse vector to GameLib.API.Mouse
* @returns {GameLib.API.Mouse}
*/
GameLib.Mouse.prototype.toApiObject = function() {
return new GameLib.API.Mouse(
this.id,
this.name,
GameLib.Utils.IdOrNull(this.parentEntity),
this.x,
this.y
);
};