touch, keyboard and mouse control components
parent
c572393a54
commit
e6f61fac58
|
@ -145,13 +145,15 @@ GameLib.Component.COMPONENT_SHAPE_HEIGHT_MAP = 0x2e;
|
||||||
GameLib.Component.COMPONENT_SHAPE_PLANE = 0x2f;
|
GameLib.Component.COMPONENT_SHAPE_PLANE = 0x2f;
|
||||||
GameLib.Component.COMPONENT_CONTROLS = 0x30;
|
GameLib.Component.COMPONENT_CONTROLS = 0x30;
|
||||||
GameLib.Component.COMPONENT_CONTROLS_EDITOR = 0x31;
|
GameLib.Component.COMPONENT_CONTROLS_EDITOR = 0x31;
|
||||||
GameLib.Component.COMPONENT_CONTROLS_FLY = 0x32;
|
GameLib.Component.COMPONENT_CONTROLS_TOUCH = 0x32;
|
||||||
GameLib.Component.COMPONENT_FRICTION_MATERIAL = 0x33;
|
GameLib.Component.COMPONENT_FRICTION_MATERIAL = 0x33;
|
||||||
GameLib.Component.COMPONENT_FRICTION_CONTACT_MATERIAL = 0x34;
|
GameLib.Component.COMPONENT_FRICTION_CONTACT_MATERIAL = 0x34;
|
||||||
GameLib.Component.COMPONENT_RAYCAST_VEHICLE = 0x35;
|
GameLib.Component.COMPONENT_RAYCAST_VEHICLE = 0x35;
|
||||||
GameLib.Component.COMPONENT_RAYCAST_WHEEL = 0x36;
|
GameLib.Component.COMPONENT_RAYCAST_WHEEL = 0x36;
|
||||||
GameLib.Component.COMPONENT_CLOCK = 0x37;
|
GameLib.Component.COMPONENT_CLOCK = 0x37;
|
||||||
GameLib.Component.COMPONENT_ANIMATION = 0x38;
|
GameLib.Component.COMPONENT_ANIMATION = 0x38;
|
||||||
|
GameLib.Component.COMPONENT_CONTROLS_KEYBOARD = 0x39;
|
||||||
|
GameLib.Component.COMPONENT_CONTROLS_MOUSE = 0x3a;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns string name for component number
|
* Returns string name for component number
|
||||||
|
@ -210,13 +212,15 @@ GameLib.Component.GetComponentName = function(number) {
|
||||||
case 0x2f : return 'GameLib.D3.Shape.Plane';
|
case 0x2f : return 'GameLib.D3.Shape.Plane';
|
||||||
case 0x30 : return 'GameLib.D3.Controls';
|
case 0x30 : return 'GameLib.D3.Controls';
|
||||||
case 0x31 : return 'GameLib.D3.Controls.Editor';
|
case 0x31 : return 'GameLib.D3.Controls.Editor';
|
||||||
case 0x32 : return 'GameLib.D3.Controls.Fly';
|
case 0x32 : return 'GameLib.D3.Controls.Touch';
|
||||||
case 0x33 : return 'GameLib.D3.FrictionMaterial';
|
case 0x33 : return 'GameLib.D3.FrictionMaterial';
|
||||||
case 0x34 : return 'GameLib.D3.FrictionContactMaterial';
|
case 0x34 : return 'GameLib.D3.FrictionContactMaterial';
|
||||||
case 0x35 : return 'GameLib.D3.RaycastVehicle';
|
case 0x35 : return 'GameLib.D3.RaycastVehicle';
|
||||||
case 0x36 : return 'GameLib.D3.RaycastWheel';
|
case 0x36 : return 'GameLib.D3.RaycastWheel';
|
||||||
case 0x37 : return 'GameLib.Clock';
|
case 0x37 : return 'GameLib.Clock';
|
||||||
case 0x38 : return 'GameLib.D3.Animation';
|
case 0x38 : return 'GameLib.D3.Animation';
|
||||||
|
case 0x39 : return 'GameLib.D3.Controls.Keyboard';
|
||||||
|
case 0x3a : return 'GameLib.D3.Controls.Mouse';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,6 @@ GameLib.API.DomElement = function(
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
||||||
parentEntity = null;
|
|
||||||
}
|
|
||||||
this.parentEntity = parentEntity;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
id = GameLib.Utils.RandomId();
|
||||||
}
|
}
|
||||||
|
@ -32,6 +27,11 @@ GameLib.API.DomElement = function(
|
||||||
domElementId = '';
|
domElementId = '';
|
||||||
}
|
}
|
||||||
this.domElementId = domElementId;
|
this.domElementId = domElementId;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
||||||
|
parentEntity = null;
|
||||||
|
}
|
||||||
|
this.parentEntity = parentEntity;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.API.DomElement.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.API.DomElement.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
/**
|
/**
|
||||||
* Raw Controls API object - should always correspond with the Controls Schema
|
* Raw Controls API object
|
||||||
* @param id
|
* @param id
|
||||||
* @param controlsType
|
* @param controlsType
|
||||||
* @param name
|
* @param name
|
||||||
|
* @param domElement
|
||||||
* @param parentEntity
|
* @param parentEntity
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
@ -10,6 +11,7 @@ GameLib.D3.API.Controls = function(
|
||||||
id,
|
id,
|
||||||
controlsType,
|
controlsType,
|
||||||
name,
|
name,
|
||||||
|
domElement,
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
@ -18,18 +20,56 @@ GameLib.D3.API.Controls = function(
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(controlsType)) {
|
if (GameLib.Utils.UndefinedOrNull(controlsType)) {
|
||||||
controlsType = GameLib.D3.Controls.CONTROLS_TYPE_EDITOR;
|
|
||||||
|
if (this instanceof GameLib.D3.Controls.Editor) {
|
||||||
|
controlsType = GameLib.D3.Controls.CONTROLS_TYPE_EDITOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this instanceof GameLib.D3.Controls.Touch) {
|
||||||
|
controlsType = GameLib.D3.Controls.CONTROLS_TYPE_TOUCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this instanceof GameLib.D3.Controls.Keyboard) {
|
||||||
|
controlsType = GameLib.D3.Controls.CONTROLS_TYPE_KEYBOARD;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this instanceof GameLib.D3.Controls.Mouse) {
|
||||||
|
controlsType = GameLib.D3.Controls.CONTROLS_TYPE_MOUSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(controlsType)) {
|
||||||
|
throw new Error('Could not determine controls type from this');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.controlsType = controlsType;
|
this.controlsType = controlsType;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
name = 'Controls (' + this.id + ')';
|
|
||||||
if (controlsType === GameLib.D3.Controls.CONTROLS_TYPE_EDITOR) {
|
if (controlsType === GameLib.D3.Controls.CONTROLS_TYPE_EDITOR) {
|
||||||
name = 'Controls for Editing';
|
name = 'Editing Controls';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (controlsType === GameLib.D3.Controls.CONTROLS_TYPE_TOUCH) {
|
||||||
|
name = 'Touch Controls';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (controlsType === GameLib.D3.Controls.CONTROLS_TYPE_KEYBOARD) {
|
||||||
|
name = 'Keyboard Controls';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (controlsType === GameLib.D3.Controls.CONTROLS_TYPE_MOUSE) {
|
||||||
|
name = 'Mouse Controls';
|
||||||
|
}
|
||||||
|
|
||||||
|
name += ' (' + this.id + ')';
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(domElement)) {
|
||||||
|
domElement = null;
|
||||||
|
}
|
||||||
|
this.domElement = domElement;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
||||||
parentEntity = null;
|
parentEntity = null;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +89,7 @@ GameLib.D3.API.Controls.FromObject = function (objectControls){
|
||||||
objectControls.id,
|
objectControls.id,
|
||||||
objectControls.controlsType,
|
objectControls.controlsType,
|
||||||
objectControls.name,
|
objectControls.name,
|
||||||
|
objectControls.domElement,
|
||||||
objectControls.parentEntity
|
objectControls.parentEntity
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -144,6 +144,23 @@ GameLib.D3.Camera.prototype.createInstance = function() {
|
||||||
* Updates the instance with the current state
|
* Updates the instance with the current state
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Camera.prototype.updateInstance = function() {
|
GameLib.D3.Camera.prototype.updateInstance = function() {
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL &&
|
||||||
|
this.instance instanceof THREE.PerspectiveCamera
|
||||||
|
) {
|
||||||
|
this.instance = this.createInstance();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE &&
|
||||||
|
this.instance instanceof THREE.OrthographicCamera
|
||||||
|
) {
|
||||||
|
this.instance = this.createInstance();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
|
if (this.cameraType === GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
|
||||||
this.instance.left = this.minX;
|
this.instance.left = this.minX;
|
||||||
this.instance.right = this.maxX;
|
this.instance.right = this.maxX;
|
||||||
|
|
|
@ -24,27 +24,36 @@ GameLib.D3.Controls = function (
|
||||||
apiControls.id,
|
apiControls.id,
|
||||||
apiControls.controlsType,
|
apiControls.controlsType,
|
||||||
apiControls.name,
|
apiControls.name,
|
||||||
|
apiControls.domElement,
|
||||||
apiControls.parentEntity
|
apiControls.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
var componentType = GameLib.Component.COMPONENT_CONTROLS;
|
var componentType = GameLib.Component.COMPONENT_CONTROLS;
|
||||||
|
|
||||||
var linkedObjects = null;
|
var linkedObjects = {
|
||||||
|
domElement : GameLib.DomElement
|
||||||
|
};
|
||||||
|
|
||||||
if (this.controlsType === GameLib.D3.Controls.CONTROLS_TYPE_EDITOR) {
|
if (this.controlsType === GameLib.D3.Controls.CONTROLS_TYPE_EDITOR) {
|
||||||
|
|
||||||
componentType = GameLib.Component.COMPONENT_CONTROLS_EDITOR;
|
componentType = GameLib.Component.COMPONENT_CONTROLS_EDITOR;
|
||||||
|
|
||||||
linkedObjects = {
|
linkedObjects.raycaster = GameLib.D3.Raycaster;
|
||||||
'raycaster' : GameLib.D3.Raycaster,
|
linkedObjects.renderer = GameLib.D3.Renderer;
|
||||||
'renderer' : GameLib.D3.Renderer
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.controlsType === GameLib.D3.Controls.CONTROLS_TYPE_FLY) {
|
if (this.controlsType === GameLib.D3.Controls.CONTROLS_TYPE_TOUCH) {
|
||||||
componentType = GameLib.Component.COMPONENT_CONTROLS_FLY
|
componentType = GameLib.Component.COMPONENT_CONTROLS_TOUCH
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.controlsType === GameLib.D3.Controls.CONTROLS_TYPE_KEYBOARD) {
|
||||||
|
componentType = GameLib.Component.COMPONENT_CONTROLS_KEYBOARD
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.controlsType === GameLib.D3.Controls.CONTROLS_TYPE_MOUSE) {
|
||||||
|
componentType = GameLib.Component.COMPONENT_CONTROLS_MOUSE
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
componentType,
|
componentType,
|
||||||
|
@ -59,8 +68,10 @@ GameLib.D3.Controls.prototype.constructor = GameLib.D3.Controls;
|
||||||
* Controls Type
|
* Controls Type
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Controls.CONTROLS_TYPE_EDITOR = 0x0;
|
GameLib.D3.Controls.CONTROLS_TYPE_EDITOR = 0x0;
|
||||||
GameLib.D3.Controls.CONTROLS_TYPE_FLY = 0x1;
|
GameLib.D3.Controls.CONTROLS_TYPE_TOUCH = 0x1;
|
||||||
|
GameLib.D3.Controls.CONTROLS_TYPE_KEYBOARD = 0x2;
|
||||||
|
GameLib.D3.Controls.CONTROLS_TYPE_MOUSE = 0x3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a mesh instance or updates it
|
* Creates a mesh instance or updates it
|
||||||
|
@ -86,6 +97,7 @@ GameLib.D3.Controls.prototype.toApiObject = function() {
|
||||||
this.id,
|
this.id,
|
||||||
this.controlsType,
|
this.controlsType,
|
||||||
this.name,
|
this.name,
|
||||||
|
GameLib.Utils.IdOrNull(this.domElement),
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -112,8 +112,8 @@ GameLib.D3.Controls.Editor.prototype.updateInstance = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh
|
* Converts a GameLib.D3.Controls.Editor to a GameLib.D3.API.Mesh
|
||||||
* @returns {GameLib.D3.API.Mesh}
|
* @returns {GameLib.D3.API.Controls}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Controls.Editor.prototype.toApiObject = function() {
|
GameLib.D3.Controls.Editor.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
@ -134,14 +134,14 @@ GameLib.D3.Controls.Editor.prototype.toApiObject = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Controls.Editor.FromObject = function(graphics, objectControls) {
|
GameLib.D3.Controls.Editor.FromObject = function(graphics, objectControls) {
|
||||||
|
|
||||||
var apiMesh = GameLib.D3.API.Controls.FromObject(objectControls);
|
var apiControls = GameLib.D3.API.Controls.FromObject(objectControls);
|
||||||
|
|
||||||
apiMesh.renderer = objectControls.renderer;
|
apiControls.renderer = objectControls.renderer;
|
||||||
apiMesh.raycaster = objectControls.raycaster;
|
apiControls.raycaster = objectControls.raycaster;
|
||||||
|
|
||||||
return new GameLib.D3.Controls.Editor(
|
return new GameLib.D3.Controls.Editor(
|
||||||
graphics,
|
graphics,
|
||||||
apiMesh
|
apiControls
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
|
@ -0,0 +1,75 @@
|
||||||
|
/**
|
||||||
|
* Keyboard Controls
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param apiControls GameLib.D3.API.Controls
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Keyboard = function (
|
||||||
|
graphics,
|
||||||
|
apiControls
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
GameLib.D3.Controls.call(
|
||||||
|
this,
|
||||||
|
this.graphics,
|
||||||
|
apiControls
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inheritance
|
||||||
|
* @type {GameLib.D3.Controls}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Keyboard.prototype = Object.create(GameLib.D3.Controls.prototype);
|
||||||
|
GameLib.D3.Controls.Keyboard.prototype.constructor = GameLib.D3.Controls.Keyboard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Instance
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Keyboard.prototype.createInstance = function() {
|
||||||
|
/**
|
||||||
|
* Return true to indicate no dependencies to other components
|
||||||
|
*/
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Instance
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Keyboard.prototype.updateInstance = function() {
|
||||||
|
GameLib.D3.Controls.prototype.updateInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Controls.Keyboard to a GameLib.D3.API.Controls
|
||||||
|
* @returns {GameLib.D3.API.Controls}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Keyboard.prototype.toApiObject = function() {
|
||||||
|
var apiControls = GameLib.D3.Controls.prototype.toApiObject.call(this);
|
||||||
|
/**
|
||||||
|
* add other properties here as this component develops...
|
||||||
|
*/
|
||||||
|
return apiControls;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct an Keyboard Controls object from data
|
||||||
|
* @param graphics
|
||||||
|
* @param objectControls
|
||||||
|
* @returns {GameLib.D3.Controls.Keyboard}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Keyboard.FromObject = function(graphics, objectControls) {
|
||||||
|
|
||||||
|
var apiControls = GameLib.D3.API.Controls.FromObject(objectControls);
|
||||||
|
|
||||||
|
return new GameLib.D3.Controls.Keyboard(
|
||||||
|
graphics,
|
||||||
|
apiControls
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,75 @@
|
||||||
|
/**
|
||||||
|
* Mouse Controls
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param apiControls GameLib.D3.API.Controls
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Mouse = function (
|
||||||
|
graphics,
|
||||||
|
apiControls
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
GameLib.D3.Controls.call(
|
||||||
|
this,
|
||||||
|
this.graphics,
|
||||||
|
apiControls
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inheritance
|
||||||
|
* @type {GameLib.D3.Controls}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Mouse.prototype = Object.create(GameLib.D3.Controls.prototype);
|
||||||
|
GameLib.D3.Controls.Mouse.prototype.constructor = GameLib.D3.Controls.Mouse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Instance
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Mouse.prototype.createInstance = function() {
|
||||||
|
/**
|
||||||
|
* Return true to indicate no dependencies to other components
|
||||||
|
*/
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Instance
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Mouse.prototype.updateInstance = function() {
|
||||||
|
GameLib.D3.Controls.prototype.updateInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Controls.Mouse to a GameLib.D3.API.Controls
|
||||||
|
* @returns {GameLib.D3.API.Controls}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Mouse.prototype.toApiObject = function() {
|
||||||
|
var apiControls = GameLib.D3.Controls.prototype.toApiObject.call(this);
|
||||||
|
/**
|
||||||
|
* add other properties here as this component develops...
|
||||||
|
*/
|
||||||
|
return apiControls;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct an Mouse Controls object from data
|
||||||
|
* @param graphics
|
||||||
|
* @param objectControls
|
||||||
|
* @returns {GameLib.D3.Controls.Mouse}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Mouse.FromObject = function(graphics, objectControls) {
|
||||||
|
|
||||||
|
var apiControls = GameLib.D3.API.Controls.FromObject(objectControls);
|
||||||
|
|
||||||
|
return new GameLib.D3.Controls.Mouse(
|
||||||
|
graphics,
|
||||||
|
apiControls
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,75 @@
|
||||||
|
/**
|
||||||
|
* Touch Controls
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param apiControls GameLib.D3.API.Controls
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Touch = function (
|
||||||
|
graphics,
|
||||||
|
apiControls
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
GameLib.D3.Controls.call(
|
||||||
|
this,
|
||||||
|
this.graphics,
|
||||||
|
apiControls
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inheritance
|
||||||
|
* @type {GameLib.D3.Controls}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Touch.prototype = Object.create(GameLib.D3.Controls.prototype);
|
||||||
|
GameLib.D3.Controls.Touch.prototype.constructor = GameLib.D3.Controls.Touch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Instance
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Touch.prototype.createInstance = function() {
|
||||||
|
/**
|
||||||
|
* Return true to indicate no dependencies to other components
|
||||||
|
*/
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Instance
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Touch.prototype.updateInstance = function() {
|
||||||
|
GameLib.D3.Controls.prototype.updateInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Controls.Touch to a GameLib.D3.API.Controls
|
||||||
|
* @returns {GameLib.D3.API.Controls}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Touch.prototype.toApiObject = function() {
|
||||||
|
var apiControls = GameLib.D3.Controls.prototype.toApiObject.call(this);
|
||||||
|
/**
|
||||||
|
* add other properties here as this component develops...
|
||||||
|
*/
|
||||||
|
return apiControls;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct an Touch Controls object from data
|
||||||
|
* @param graphics
|
||||||
|
* @param objectControls
|
||||||
|
* @returns {GameLib.D3.Controls.Touch}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Controls.Touch.FromObject = function(graphics, objectControls) {
|
||||||
|
|
||||||
|
var apiControls = GameLib.D3.API.Controls.FromObject(objectControls);
|
||||||
|
|
||||||
|
return new GameLib.D3.Controls.Touch(
|
||||||
|
graphics,
|
||||||
|
apiControls
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
|
@ -5,7 +5,11 @@
|
||||||
*/
|
*/
|
||||||
GameLib.DomElement = function (apiDomElement) {
|
GameLib.DomElement = function (apiDomElement) {
|
||||||
|
|
||||||
if (apiDomElement instanceof GameLib.DomElement) {
|
if (GameLib.Utils.UndefinedOrNull(apiDomElement)) {
|
||||||
|
apiDomElement = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiDomElement instanceof GameLib.DomElement) {
|
||||||
return apiDomElement;
|
return apiDomElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,14 +39,14 @@ GameLib.DomElement.prototype.createInstance = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the instance vector, calls updateInstance on the parent object
|
* Updates instance domElement
|
||||||
*/
|
*/
|
||||||
GameLib.DomElement.prototype.updateInstance = function() {
|
GameLib.DomElement.prototype.updateInstance = function() {
|
||||||
this.instance = document.getElementById(this.domElementId);
|
this.instance = document.getElementById(this.domElementId);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts runtime vector to API Vector
|
* Converts runtime DomElement to API DomElement
|
||||||
* @returns {GameLib.API.DomElement}
|
* @returns {GameLib.API.DomElement}
|
||||||
*/
|
*/
|
||||||
GameLib.DomElement.prototype.toApiObject = function() {
|
GameLib.DomElement.prototype.toApiObject = function() {
|
||||||
|
@ -50,7 +54,7 @@ GameLib.DomElement.prototype.toApiObject = function() {
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
this.domElementId,
|
this.domElementId,
|
||||||
this.parentEntity
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -737,7 +737,18 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else if (property === 'materialType') {
|
} else if (property === 'cameraType') {
|
||||||
|
controllers.push(
|
||||||
|
folder.add(
|
||||||
|
object,
|
||||||
|
property,
|
||||||
|
{
|
||||||
|
'perspective' : GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE,
|
||||||
|
'orthographic' : GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (property === 'materialType') {
|
||||||
controllers.push(
|
controllers.push(
|
||||||
folder.add(
|
folder.add(
|
||||||
object,
|
object,
|
||||||
|
@ -1071,6 +1082,15 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
property === 'intensity'
|
property === 'intensity'
|
||||||
) {
|
) {
|
||||||
controllers.push(folder.add(object, property, 0, 10, 0.001));
|
controllers.push(folder.add(object, property, 0, 10, 0.001));
|
||||||
|
} else if (
|
||||||
|
property === 'minX' ||
|
||||||
|
property === 'minY' ||
|
||||||
|
property === 'minZ' ||
|
||||||
|
property === 'maxX' ||
|
||||||
|
property === 'maxY' ||
|
||||||
|
property === 'maxZ'
|
||||||
|
) {
|
||||||
|
controllers.push(folder.add(object, property, -100, 100, 1));
|
||||||
} else if (
|
} else if (
|
||||||
property === 'widthSegments' ||
|
property === 'widthSegments' ||
|
||||||
property === 'radiusSegments' ||
|
property === 'radiusSegments' ||
|
||||||
|
@ -1087,10 +1107,13 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
} else if (
|
} else if (
|
||||||
property === 'near' ||
|
property === 'near' ||
|
||||||
property === 'distanceGrain' ||
|
property === 'distanceGrain' ||
|
||||||
property === 'bumpScale' ||
|
|
||||||
property === 'envMapIntensity'
|
property === 'envMapIntensity'
|
||||||
) {
|
) {
|
||||||
controllers.push(folder.add(object, property, -10, 100, 0.001));
|
controllers.push(folder.add(object, property, -10, 100, 0.001));
|
||||||
|
} else if (
|
||||||
|
property === 'bumpScale'
|
||||||
|
) {
|
||||||
|
controllers.push(folder.add(object, property, 0, 20, 0.001));
|
||||||
} else if (
|
} else if (
|
||||||
property === 'heightOffset' ||
|
property === 'heightOffset' ||
|
||||||
property === 'rotationFactor'
|
property === 'rotationFactor'
|
||||||
|
|
|
@ -11,10 +11,10 @@ GameLib.System.Input = function(
|
||||||
apiSystem
|
apiSystem
|
||||||
);
|
);
|
||||||
|
|
||||||
this.meshMoveMode = false;
|
// this.meshMoveMode = false;
|
||||||
this.meshMoveXMode = false;
|
// this.meshMoveXMode = false;
|
||||||
this.meshMoveYMode = false;
|
// this.meshMoveYMode = false;
|
||||||
this.meshMoveZMode = false;
|
// this.meshMoveZMode = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We need new function pointers with scope bound to this so we can remove the
|
* We need new function pointers with scope bound to this so we can remove the
|
||||||
|
@ -31,7 +31,11 @@ GameLib.System.Input = function(
|
||||||
|
|
||||||
this.controlLeft = false;
|
this.controlLeft = false;
|
||||||
|
|
||||||
this.renderers = [];
|
this.renderers = [];
|
||||||
|
this.editorControls = [];
|
||||||
|
this.touchControls = [];
|
||||||
|
this.keyboardControls = [];
|
||||||
|
this.mouseControls = [];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,75 +49,97 @@ GameLib.System.Input.prototype.start = function() {
|
||||||
|
|
||||||
GameLib.System.prototype.start.call(this);
|
GameLib.System.prototype.start.call(this);
|
||||||
|
|
||||||
this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Renderer);
|
this.editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Editor);
|
||||||
|
|
||||||
this.renderers.map(
|
this.touchControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Touch);
|
||||||
function(renderer) {
|
|
||||||
|
|
||||||
var editorControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Editor);
|
this.keyboardControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Keyboard);
|
||||||
|
|
||||||
renderer.controls = editorControls.reduce(
|
this.mouseControls = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Controls.Mouse);
|
||||||
function(result, editorControls) {
|
|
||||||
if (editorControls.renderer === renderer) {
|
|
||||||
result = editorControls;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
renderer.mouseDown = this.onMouseDown(renderer, renderer.controls).bind(this);
|
/**
|
||||||
renderer.domElement.instance.addEventListener(
|
* If we have editor controls - start behaving like it...
|
||||||
'mousedown',
|
*/
|
||||||
renderer.mouseDown,
|
if (this.editorControls.length > 0) {
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
renderer.mouseMove = this.onMouseMove.bind(this);
|
this.renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.Renderer);
|
||||||
renderer.domElement.instance.addEventListener(
|
|
||||||
'mousemove',
|
|
||||||
renderer.mouseMove,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
renderer.keyDown = this.onKeyDown.bind(this);
|
this.renderers.map(
|
||||||
renderer.domElement.instance.addEventListener(
|
|
||||||
'keydown',
|
|
||||||
renderer.keyDown,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
renderer.keyUp = this.onKeyUp.bind(this);
|
function(renderer) {
|
||||||
renderer.domElement.instance.addEventListener(
|
|
||||||
'keyup',
|
|
||||||
renderer.keyUp,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
if (renderer.controls) {
|
renderer.controls = this.editorControls.reduce(
|
||||||
/**
|
function(result, editorControl) {
|
||||||
* Create the delayed instance here - it affects the order of event listeners attached to DOM
|
if (editorControl.renderer === renderer) {
|
||||||
*/
|
result = editorControl;
|
||||||
renderer.controls.instance = renderer.controls.delayedInstance();
|
}
|
||||||
} else {
|
return result;
|
||||||
console.warn('no third party controls for renderer : ' + renderer.name);
|
},
|
||||||
}
|
null
|
||||||
|
);
|
||||||
|
|
||||||
renderer.mouseWheel = this.onMouseWheel(renderer.camera).bind(this);
|
renderer.mouseDown = this.onMouseDown(renderer, renderer.controls).bind(this);
|
||||||
renderer.domElement.instance.addEventListener(
|
renderer.domElement.instance.addEventListener(
|
||||||
'mousewheel',
|
'mousedown',
|
||||||
renderer.mouseWheel,
|
renderer.mouseDown,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
renderer.mouseUp = this.onMouseUp(renderer.camera, renderer.controls).bind(this);
|
renderer.mouseMove = this.onMouseMove.bind(this);
|
||||||
renderer.domElement.instance.addEventListener(
|
renderer.domElement.instance.addEventListener(
|
||||||
'mouseup',
|
'mousemove',
|
||||||
renderer.mouseUp,
|
renderer.mouseMove,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
}.bind(this)
|
|
||||||
);
|
renderer.keyDown = this.onKeyDown.bind(this);
|
||||||
|
renderer.domElement.instance.addEventListener(
|
||||||
|
'keydown',
|
||||||
|
renderer.keyDown,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
renderer.keyUp = this.onKeyUp.bind(this);
|
||||||
|
renderer.domElement.instance.addEventListener(
|
||||||
|
'keyup',
|
||||||
|
renderer.keyUp,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
if (renderer.controls) {
|
||||||
|
/**
|
||||||
|
* Create the delayed instance here - it affects the order of event listeners attached to DOM
|
||||||
|
*/
|
||||||
|
renderer.controls.instance = renderer.controls.delayedInstance();
|
||||||
|
} else {
|
||||||
|
console.warn('no third party controls for renderer : ' + renderer.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.mouseWheel = this.onMouseWheel(renderer.camera).bind(this);
|
||||||
|
renderer.domElement.instance.addEventListener(
|
||||||
|
'mousewheel',
|
||||||
|
renderer.mouseWheel,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
renderer.mouseUp = this.onMouseUp(renderer.camera, renderer.controls).bind(this);
|
||||||
|
renderer.domElement.instance.addEventListener(
|
||||||
|
'mouseup',
|
||||||
|
renderer.mouseUp,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.touchControls.length > 0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.keyboardControls.length > 0) {
|
||||||
|
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -382,6 +408,7 @@ GameLib.System.Input.prototype.stop = function() {
|
||||||
* Now remove all input capabilities
|
* Now remove all input capabilities
|
||||||
*/
|
*/
|
||||||
this.renderers.map(
|
this.renderers.map(
|
||||||
|
|
||||||
function(renderer) {
|
function(renderer) {
|
||||||
|
|
||||||
renderer.domElement.instance.removeEventListener(
|
renderer.domElement.instance.removeEventListener(
|
||||||
|
|
|
@ -394,22 +394,25 @@ GameLib.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, inc
|
||||||
parentEntity = runtimeComponent;
|
parentEntity = runtimeComponent;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
runtimeComponent = fn(__system.coder, component);
|
runtimeComponent = fn(component);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
try {
|
try {
|
||||||
runtimeComponent = fn(__system.graphics, component);
|
runtimeComponent = fn(__system.coder, component);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
try {
|
try {
|
||||||
runtimeComponent = fn(__system.physics, component);
|
runtimeComponent = fn(__system.graphics, component);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
/**
|
try {
|
||||||
* ok - we don't cannot create this component
|
runtimeComponent = fn(__system.physics, component);
|
||||||
*/
|
} catch (error) {
|
||||||
}
|
/**
|
||||||
}
|
* ok - we don't cannot create this component
|
||||||
}
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!runtimeComponent) {
|
if (!runtimeComponent) {
|
||||||
if (clientErrorCallback) {
|
if (clientErrorCallback) {
|
||||||
clientErrorCallback('Could not create a runtime component: ' + component.name);
|
clientErrorCallback('Could not create a runtime component: ' + component.name);
|
||||||
|
|
Loading…
Reference in New Issue