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

122 lines
2.9 KiB
JavaScript

/**
* Controls Superset - The apiControls properties get moved into the Controls object itself, and then the instance is created
* @param apiControls GameLib.API.Controls
* @constructor
*/
GameLib.Controls = function (
apiControls
) {
if (GameLib.Utils.UndefinedOrNull(apiControls)) {
apiControls = {};
}
if (apiControls instanceof GameLib.Controls) {
return apiControls;
}
GameLib.API.Controls.call(
this,
apiControls.id,
apiControls.controlsType,
apiControls.name,
apiControls.domElement,
apiControls.parentEntity
);
var componentType = GameLib.Component.COMPONENT_CONTROLS;
var linkedObjects = {
domElement : GameLib.DomElement
};
var delayed = false;
if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_EDITOR) {
componentType = GameLib.Component.COMPONENT_CONTROLS_EDITOR;
linkedObjects.raycaster = GameLib.D3.Raycaster;
linkedObjects.camera = GameLib.D3.Camera;
delayed = true;
}
if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_TOUCH) {
componentType = GameLib.Component.COMPONENT_CONTROLS_TOUCH
}
if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_KEYBOARD) {
componentType = GameLib.Component.COMPONENT_CONTROLS_KEYBOARD
}
if (this.controlsType === GameLib.Controls.CONTROLS_TYPE_MOUSE) {
componentType = GameLib.Component.COMPONENT_CONTROLS_MOUSE
}
GameLib.Component.call(
this,
componentType,
linkedObjects,
delayed
);
};
GameLib.Controls.prototype = Object.create(GameLib.API.Controls.prototype);
GameLib.Controls.prototype.constructor = GameLib.Controls;
/**
* Controls Type
* @type {number}
*/
GameLib.Controls.CONTROLS_TYPE_EDITOR = 0x0;
GameLib.Controls.CONTROLS_TYPE_TOUCH = 0x1;
GameLib.Controls.CONTROLS_TYPE_KEYBOARD = 0x2;
GameLib.Controls.CONTROLS_TYPE_MOUSE = 0x3;
/**
* Creates a mesh instance or updates it
*/
GameLib.Controls.prototype.createInstance = function() {
GameLib.Component.prototype.createInstance.call(this);
};
/**
* Updates the mesh instance
*/
GameLib.Controls.prototype.updateInstance = function() {
console.log('default controls update instance');
};
/**
* Converts a GameLib.Controls to a GameLib.API.Controls
* @returns {GameLib.API.Controls}
*/
GameLib.Controls.prototype.toApiObject = function() {
var apiControls = new GameLib.API.Controls(
this.id,
this.controlsType,
this.name,
GameLib.Utils.IdOrNull(this.domElement),
GameLib.Utils.IdOrNull(this.parentEntity)
);
return apiControls;
};
/**
* Converts a data object to a GameLib.Controls
* @param objectControls {Object}
* @constructor
*/
GameLib.Controls.FromObject = function(objectControls) {
var apiControls = GameLib.API.Controls.FromObject(objectControls);
return new GameLib.Controls(
apiControls
);
};