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

89 lines
1.9 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.canvas,
2017-08-24 22:20:40 +02:00
apiControls.parentEntity
);
var linkedObjects = {
canvas : GameLib.Canvas
};
2017-08-24 22:20:40 +02:00
2017-10-27 10:03:53 +02:00
var delayed = false;
2018-01-29 12:42:46 +01:00
if (apiControls.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
*/
2018-01-12 14:57:15 +01:00
GameLib.Controls.prototype.updateInstance = function(property) {
if (property === 'canvas') {
2018-01-12 14:57:15 +01:00
GameLib.Event.Emit(
GameLib.Event.CANVAS_CHANGE,
2018-01-12 14:57:15 +01:00
{
component: this
}
);
}
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.canvas),
2017-08-24 22:20:40 +02:00
GameLib.Utils.IdOrNull(this.parentEntity)
);
return apiControls;
};