2017-08-24 22:20:40 +02:00
|
|
|
/**
|
|
|
|
* Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created
|
2017-12-02 12:01:18 +01:00
|
|
|
* @param apiControls GameLib.API.Controls
|
2017-08-24 22:20:40 +02:00
|
|
|
* @constructor
|
|
|
|
*/
|
2017-12-02 12:01:18 +01:00
|
|
|
GameLib.Controls = function (
|
2017-08-24 22:20:40 +02:00
|
|
|
apiControls
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(apiControls)) {
|
|
|
|
apiControls = {};
|
|
|
|
}
|
|
|
|
|
2017-12-02 12:01:18 +01:00
|
|
|
if (apiControls instanceof GameLib.Controls) {
|
2017-08-24 22:20:40 +02:00
|
|
|
return apiControls;
|
|
|
|
}
|
|
|
|
|
2017-12-02 12:01:18 +01:00
|
|
|
GameLib.API.Controls.call(
|
2017-08-24 22:20:40 +02:00
|
|
|
this,
|
|
|
|
apiControls.id,
|
|
|
|
apiControls.controlsType,
|
|
|
|
apiControls.name,
|
2017-09-27 14:38:58 +02:00
|
|
|
apiControls.domElement,
|
2017-08-24 22:20:40 +02:00
|
|
|
apiControls.parentEntity
|
|
|
|
);
|
|
|
|
|
2017-09-27 14:38:58 +02:00
|
|
|
var linkedObjects = {
|
|
|
|
domElement : GameLib.DomElement
|
|
|
|
};
|
2017-08-24 22:20:40 +02:00
|
|
|
|
2017-10-27 10:03:53 +02:00
|
|
|
var delayed = false;
|
|
|
|
|
2017-12-02 12:01:18 +01:00
|
|
|
if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_EDITOR) {
|
2017-08-24 22:20:40 +02:00
|
|
|
|
2017-10-08 03:17:36 +02:00
|
|
|
linkedObjects.raycaster = GameLib.D3.Raycaster;
|
|
|
|
linkedObjects.camera = GameLib.D3.Camera;
|
2017-10-27 10:03:53 +02:00
|
|
|
|
|
|
|
delayed = true;
|
2017-08-24 22:20:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GameLib.Component.call(
|
|
|
|
this,
|
2017-10-27 10:03:53 +02:00
|
|
|
linkedObjects,
|
|
|
|
delayed
|
2017-08-24 22:20:40 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-01-07 12:40:16 +01:00
|
|
|
GameLib.Controls.prototype = Object.create(GameLib.Component.prototype);
|
2017-12-02 12:01:18 +01:00
|
|
|
GameLib.Controls.prototype.constructor = GameLib.Controls;
|
2017-08-24 22:20:40 +02:00
|
|
|
|
2017-12-04 13:23:15 +01:00
|
|
|
GameLib.Controls.D3 = function() {};
|
|
|
|
|
2017-08-24 22:20:40 +02:00
|
|
|
/**
|
|
|
|
* Controls Type
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2017-12-02 12:01:18 +01:00
|
|
|
GameLib.Controls.CONTROLS_TYPE_EDITOR = 0x0;
|
|
|
|
GameLib.Controls.CONTROLS_TYPE_TOUCH = 0x1;
|
|
|
|
GameLib.Controls.CONTROLS_TYPE_KEYBOARD = 0x2;
|
|
|
|
GameLib.Controls.CONTROLS_TYPE_MOUSE = 0x3;
|
2017-08-24 22:20:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a mesh instance or updates it
|
|
|
|
*/
|
2017-12-02 12:01:18 +01:00
|
|
|
GameLib.Controls.prototype.createInstance = function() {
|
2017-10-23 14:52:35 +02:00
|
|
|
GameLib.Component.prototype.createInstance.call(this);
|
2017-08-24 22:20:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the mesh instance
|
|
|
|
*/
|
2017-12-02 12:01:18 +01:00
|
|
|
GameLib.Controls.prototype.updateInstance = function() {
|
2017-08-24 22:20:40 +02:00
|
|
|
console.log('default controls update instance');
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-12-02 12:01:18 +01:00
|
|
|
* Converts a GameLib.Controls to a GameLib.API.Controls
|
|
|
|
* @returns {GameLib.API.Controls}
|
2017-08-24 22:20:40 +02:00
|
|
|
*/
|
2017-12-02 12:01:18 +01:00
|
|
|
GameLib.Controls.prototype.toApiObject = function() {
|
2017-08-24 22:20:40 +02:00
|
|
|
|
2017-12-02 12:01:18 +01:00
|
|
|
var apiControls = new GameLib.API.Controls(
|
2017-08-24 22:20:40 +02:00
|
|
|
this.id,
|
|
|
|
this.controlsType,
|
|
|
|
this.name,
|
2017-09-27 14:38:58 +02:00
|
|
|
GameLib.Utils.IdOrNull(this.domElement),
|
2017-08-24 22:20:40 +02:00
|
|
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
|
|
|
);
|
|
|
|
|
|
|
|
return apiControls;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-12-02 12:01:18 +01:00
|
|
|
* Converts a data object to a GameLib.Controls
|
2017-08-24 22:20:40 +02:00
|
|
|
* @param objectControls {Object}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2017-12-02 12:01:18 +01:00
|
|
|
GameLib.Controls.FromObject = function(objectControls) {
|
2017-08-24 22:20:40 +02:00
|
|
|
|
2017-12-02 12:01:18 +01:00
|
|
|
var apiControls = GameLib.API.Controls.FromObject(objectControls);
|
2017-08-24 22:20:40 +02:00
|
|
|
|
2017-12-02 12:01:18 +01:00
|
|
|
return new GameLib.Controls(
|
2017-08-24 22:20:40 +02:00
|
|
|
apiControls
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|