2017-01-09 15:20:48 +01:00
|
|
|
/**
|
|
|
|
* Runtime mouse for updating instance objects
|
|
|
|
* @param graphics GameLib.D3.Graphics
|
|
|
|
* @param apiMouse GameLib.API.Mouse
|
|
|
|
* @constructor
|
|
|
|
*/
|
2017-01-17 13:24:45 +01:00
|
|
|
GameLib.Mouse = function (graphics, apiMouse) {
|
2017-01-09 15:20:48 +01:00
|
|
|
|
|
|
|
this.graphics = graphics;
|
|
|
|
this.graphics.isNotThreeThrow();
|
|
|
|
|
2017-02-21 18:55:18 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiMouse)){
|
|
|
|
apiMouse = {};
|
|
|
|
}
|
|
|
|
|
2017-05-11 04:48:02 +02:00
|
|
|
if (apiMouse instanceof GameLib.Mouse) {
|
|
|
|
return apiMouse;
|
|
|
|
}
|
|
|
|
|
2017-01-09 15:20:48 +01:00
|
|
|
GameLib.API.Mouse.call(
|
|
|
|
this,
|
|
|
|
apiMouse.id,
|
|
|
|
apiMouse.name,
|
|
|
|
apiMouse.x,
|
2017-01-19 17:50:11 +01:00
|
|
|
apiMouse.y,
|
|
|
|
apiMouse.parentEntity
|
2017-01-09 15:20:48 +01:00
|
|
|
);
|
|
|
|
|
2017-01-19 17:50:11 +01:00
|
|
|
this.instance = this.createInstance();
|
2017-01-09 15:20:48 +01:00
|
|
|
};
|
|
|
|
|
2017-01-19 17:50:11 +01:00
|
|
|
GameLib.Mouse.prototype = Object.create(GameLib.API.Mouse.prototype);
|
|
|
|
GameLib.Mouse.prototype.constructor = GameLib.Mouse;
|
|
|
|
|
2017-01-09 15:20:48 +01:00
|
|
|
/**
|
|
|
|
* Creates an instance mouse
|
|
|
|
* @param update
|
|
|
|
* @returns {*}
|
|
|
|
*/
|
|
|
|
GameLib.Mouse.prototype.createInstance = function(update) {
|
2017-01-19 17:50:11 +01:00
|
|
|
|
|
|
|
var instance = null;
|
|
|
|
|
|
|
|
if (update) {
|
|
|
|
instance = this.instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
2017-01-09 15:20:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the instance vector, calls updateInstance on the parent object
|
|
|
|
*/
|
|
|
|
GameLib.Mouse.prototype.updateInstance = function() {
|
|
|
|
this.createInstance(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts runtime vector to API Vector
|
|
|
|
* @returns {GameLib.API.Mouse}
|
|
|
|
*/
|
2017-05-16 14:51:57 +02:00
|
|
|
GameLib.Mouse.prototype.toApiObject = function() {
|
2017-01-09 15:20:48 +01:00
|
|
|
return new GameLib.API.Mouse(
|
|
|
|
this.id,
|
|
|
|
this.name,
|
|
|
|
this.x,
|
2017-01-19 17:50:11 +01:00
|
|
|
this.y,
|
|
|
|
this.parentEntity
|
2017-01-09 15:20:48 +01:00
|
|
|
);
|
|
|
|
};
|