r3-legacy/src/game-lib-controls-0.js

94 lines
2.1 KiB
JavaScript
Raw Normal View History

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 = {};
}
GameLib.API.Controls.call(
2017-08-24 22:20:40 +02:00
this,
apiControls.id,
apiControls.name,
2018-01-09 10:56:41 +01:00
apiControls.controlsType,
apiControls.domElement,
2017-08-24 22:20:40 +02:00
apiControls.parentEntity
);
var linkedObjects = {
2018-01-11 14:33:32 +01:00
domElement : GameLib.Canvas
};
2017-08-24 22:20:40 +02:00
2017-10-27 10:03:53 +02:00
var delayed = false;
2018-01-09 10:56:41 +01:00
if (this.controlsType === GameLib.API.Controls.CONTROLS_TYPE_EDITOR) {
2017-08-24 22:20:40 +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
/**
* 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.name,
2018-01-09 10:56:41 +01:00
this.controlsType,
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
);
};