wicked systems
parent
67588f1e27
commit
21b79c6515
|
@ -334,15 +334,51 @@ GameLib.Component.prototype.clone = function() {
|
||||||
//var object = this.constructor.call(this, this.graphics, apiObject);
|
//var object = this.constructor.call(this, this.graphics, apiObject);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.Component.prototype.save = function() {
|
GameLib.Component.prototype.getStorageDependencies = function() {
|
||||||
|
|
||||||
if (!this.canSave) {
|
var dependencies = [];
|
||||||
return;
|
|
||||||
|
for (var property in this.linkedObjects) {
|
||||||
|
if (this.linkedObjects.hasOwnProperty(property)){
|
||||||
|
if (this.hasOwnProperty(property)) {
|
||||||
|
|
||||||
|
if (
|
||||||
|
this[property] instanceof Array &&
|
||||||
|
this.linkedObjects[property] instanceof Array
|
||||||
|
) {
|
||||||
|
this[property].map(
|
||||||
|
function(arrayProperty){
|
||||||
|
if (arrayProperty instanceof this.linkedObjects[0]) {
|
||||||
|
dependencies.push(GameLib.Utils.IdOrNull(arrayProperty));
|
||||||
|
}
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
} else if (this[property] instanceof this.linkedObjects[property]) {
|
||||||
|
dependencies.push(GameLib.Utils.IdOrNull(this[property]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.canSave = false;
|
return dependencies;
|
||||||
|
};
|
||||||
|
|
||||||
var apiObject = this.toApiObject(true);
|
GameLib.Component.prototype.save = function() {
|
||||||
|
//
|
||||||
|
// if (!this.canSave) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// this.canSave = false;
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
|
for (var property in this.idToObject) {
|
||||||
|
if (
|
||||||
|
this.idToObject.hasOwnProperty(property) &&
|
||||||
|
this.idToObject[property] instanceof GameLib.Component
|
||||||
|
) {
|
||||||
|
var apiObject = this.idToObject[property].toApiObject();
|
||||||
|
|
||||||
delete apiObject.linkedObjects;
|
delete apiObject.linkedObjects;
|
||||||
|
|
||||||
|
@ -352,5 +388,8 @@ GameLib.Component.prototype.save = function() {
|
||||||
GameLib.Event.SAVE,
|
GameLib.Event.SAVE,
|
||||||
apiObject
|
apiObject
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
|
@ -28,9 +28,6 @@ GameLib.System = function(
|
||||||
apiSystem.parentEntity
|
apiSystem.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
this.saveCallback = null;
|
|
||||||
this.loadCallback = null;
|
|
||||||
|
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_SYSTEM
|
GameLib.Component.COMPONENT_SYSTEM
|
||||||
|
@ -59,104 +56,9 @@ GameLib.System.prototype.createInstance = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.System.prototype.start = function() {
|
GameLib.System.prototype.start = function() {
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_INPUT) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hookup all editor input capabilities
|
|
||||||
*/
|
|
||||||
var entities = GameLib.EntityManager.Instance.query([GameLib.D3.Input.Editor]);
|
|
||||||
|
|
||||||
entities.map(function(entity){
|
|
||||||
|
|
||||||
var component = entity.getFirstComponent(GameLib.D3.Input.Editor);
|
|
||||||
|
|
||||||
component.mouseDown = component.onMouseDown(entity, GameLib.EntityManager.Instance).bind(component);
|
|
||||||
component.mouseMove = component.onMouseMove(entity).bind(component);
|
|
||||||
component.keyDown = component.onKeyDown(entity, GameLib.EntityManager.Instance).bind(component);
|
|
||||||
component.keyUp = component.onKeyUp(entity, GameLib.EntityManager.Instance).bind(component);
|
|
||||||
|
|
||||||
component.domElement.instance.addEventListener('mousedown', component.mouseDown, false);
|
|
||||||
component.domElement.instance.addEventListener('mousemove', component.mouseMove, false);
|
|
||||||
component.domElement.instance.addEventListener('keydown', component.keyDown, false);
|
|
||||||
component.domElement.instance.addEventListener('keyup', component.keyUp, false);
|
|
||||||
|
|
||||||
component.controls = new THREE.EditorControls(
|
|
||||||
component.camera.instance,
|
|
||||||
component.domElement.instance
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* After our mouse 'up' editor controls would have updated our camera
|
|
||||||
* instance, so we need to update our game-lib camera to reflect these
|
|
||||||
* changes - we override
|
|
||||||
*/
|
|
||||||
component.mouseUp = function(center) {
|
|
||||||
return function() {
|
|
||||||
var camera = entity.getFirstComponent(GameLib.D3.Camera);
|
|
||||||
camera.position.x = camera.instance.position.x;
|
|
||||||
camera.position.y = camera.instance.position.y;
|
|
||||||
camera.position.z = camera.instance.position.z;
|
|
||||||
|
|
||||||
camera.quaternion.x = camera.instance.quaternion.x;
|
|
||||||
camera.quaternion.y = camera.instance.quaternion.y;
|
|
||||||
camera.quaternion.z = camera.instance.quaternion.z;
|
|
||||||
camera.quaternion.w = camera.instance.quaternion.w;
|
|
||||||
|
|
||||||
camera.lookAt.x = center.x;
|
|
||||||
camera.lookAt.y = center.y;
|
|
||||||
camera.lookAt.z = center.z;
|
|
||||||
|
|
||||||
camera.lookAt.instance.copy(center);
|
|
||||||
};
|
|
||||||
}(component.controls.center).bind(component);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Same applies to our mouse 'scroll' event
|
|
||||||
*/
|
|
||||||
component.mouseWheel = function() {
|
|
||||||
return function() {
|
|
||||||
var camera = entity.getFirstComponent(GameLib.D3.Camera);
|
|
||||||
camera.position.x = camera.instance.position.x;
|
|
||||||
camera.position.y = camera.instance.position.y;
|
|
||||||
camera.position.z = camera.instance.position.z;
|
|
||||||
};
|
|
||||||
}.bind(component);
|
|
||||||
|
|
||||||
component.domElement.instance.addEventListener('mousewheel', component.mouseWheel, false);
|
|
||||||
component.domElement.instance.addEventListener('mouseup', component.mouseUp, false);
|
|
||||||
|
|
||||||
}.bind(this))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_RENDER) {
|
|
||||||
|
|
||||||
this.renderEntities = GameLib.EntityManager.Instance.query(
|
|
||||||
[
|
|
||||||
GameLib.D3.Viewport,
|
|
||||||
GameLib.D3.Scene,
|
|
||||||
GameLib.D3.Renderer,
|
|
||||||
GameLib.D3.Camera
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
this.renderEntities.map(
|
|
||||||
function(entity) {
|
|
||||||
var stats = entity.getFirstComponent(GameLib.D3.Stats);
|
|
||||||
stats.resize();
|
|
||||||
stats.domElement.instance.parentElement.appendChild(stats.instance.dom);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_GUI) {
|
|
||||||
|
|
||||||
var guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI);
|
|
||||||
|
|
||||||
guis.map(function(gui){
|
|
||||||
gui.domElement.instance.parentElement.appendChild(gui.instance.domElement);
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
||||||
// this.pathFollowingObjects = GameLib.EntityManager.Instance.query([GameLib.D3.PathFollowing]);
|
// this.pathFollowingObjects = GameLib.EntityManager.Instance.query([GameLib.D3.PathFollowing]);
|
||||||
|
@ -167,20 +69,6 @@ GameLib.System.prototype.start = function() {
|
||||||
// this.lightObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Light]);
|
// this.lightObjects = GameLib.EntityManager.Instance.query([GameLib.D3.Light]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_STORAGE) {
|
|
||||||
|
|
||||||
this.subscribe(
|
|
||||||
GameLib.Event.SAVE,
|
|
||||||
this.save
|
|
||||||
);
|
|
||||||
|
|
||||||
this.subscribe(
|
|
||||||
GameLib.Event.LOAD,
|
|
||||||
this.load
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.update();
|
this.update();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -191,13 +79,6 @@ GameLib.System.prototype.start = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.System.prototype.update = function(deltaTime) {
|
GameLib.System.prototype.update = function(deltaTime) {
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_INPUT) {
|
|
||||||
// this.driveInputObjects.forEach(
|
|
||||||
// function(object) {
|
|
||||||
// object.update(deltaTime);
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
||||||
|
|
||||||
|
@ -238,89 +119,7 @@ GameLib.System.prototype.update = function(deltaTime) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_RENDER) {
|
|
||||||
|
|
||||||
this.renderEntities.map(
|
|
||||||
|
|
||||||
function(renderEntity) {
|
|
||||||
|
|
||||||
var stats = renderEntity.getFirstComponent(GameLib.D3.Stats);
|
|
||||||
|
|
||||||
if (!stats.instance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var renderer = renderEntity.getFirstComponent(GameLib.D3.Renderer);
|
|
||||||
var camera = renderEntity.getFirstComponent(GameLib.D3.Camera);
|
|
||||||
var viewports = renderEntity.getComponents(GameLib.D3.Viewport);
|
|
||||||
var scenes = renderEntity.getComponents(GameLib.D3.Scene);
|
|
||||||
|
|
||||||
if (!renderer.instance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (viewports.length > 1) {
|
|
||||||
renderer.instance.autoClear = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scenes.length > 1) {
|
|
||||||
renderer.instance.autoClear = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.instance.clear();
|
|
||||||
|
|
||||||
viewports.map(
|
|
||||||
function(viewport){
|
|
||||||
|
|
||||||
renderer.instance.setViewport(
|
|
||||||
viewport.x * renderer.width,
|
|
||||||
viewport.y * renderer.height,
|
|
||||||
viewport.width * renderer.width,
|
|
||||||
viewport.height * renderer.height
|
|
||||||
);
|
|
||||||
|
|
||||||
function renderScene(scene) {
|
|
||||||
|
|
||||||
if (!scene.instance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scene.activeCamera) {
|
|
||||||
|
|
||||||
if (!scene.activeCamera.instance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.instance.render(
|
|
||||||
scene.instance,
|
|
||||||
scene.activeCamera.instance
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (!camera.instance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.instance.render(
|
|
||||||
scene.instance,
|
|
||||||
camera.instance
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (viewport.scenes && viewport.scenes.length > 0) {
|
|
||||||
viewport.scenes.map(renderScene);
|
|
||||||
} else {
|
|
||||||
scenes.map(renderScene);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
stats.instance.end();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -330,48 +129,6 @@ GameLib.System.prototype.update = function(deltaTime) {
|
||||||
*/
|
*/
|
||||||
GameLib.System.prototype.stop = function() {
|
GameLib.System.prototype.stop = function() {
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_INPUT) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Now remove all editor input capabilities
|
|
||||||
*/
|
|
||||||
var entities = GameLib.EntityManager.Instance.query([GameLib.D3.Input.Editor]);
|
|
||||||
|
|
||||||
entities.map(function(entity){
|
|
||||||
var component = entity.getFirstComponent(GameLib.D3.Input.Editor);
|
|
||||||
component.domElement.instance.removeEventListener('mousedown', component.mouseDown, false);
|
|
||||||
component.domElement.instance.removeEventListener('mousemove', component.mouseMove, false);
|
|
||||||
component.domElement.instance.removeEventListener('keydown', component.keyDown, false);
|
|
||||||
component.domElement.instance.removeEventListener('keyup', component.keyUp, false);
|
|
||||||
component.controls.dispose();
|
|
||||||
component.domElement.instance.removeEventListener('mouseup', component.mouseUp, false);
|
|
||||||
component.domElement.instance.removeEventListener('mousewheel', component.mouseWheel, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('stopped all input systems');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_GUI) {
|
|
||||||
console.log('stopping GUI system');
|
|
||||||
var guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI);
|
|
||||||
|
|
||||||
guis.map(function(gui){
|
|
||||||
gui.domElement.instance.parentElement.removeChild(gui.instance.domElement);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_RENDER) {
|
|
||||||
|
|
||||||
this.renderEntities.map(
|
|
||||||
function(entity) {
|
|
||||||
var stats = entity.getFirstComponent(GameLib.D3.Stats);
|
|
||||||
stats.domElement.instance.parentElement.removeChild(stats.instance.dom);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.renderEntities = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
if (this.systemType === GameLib.System.SYSTEM_TYPE_ANIMATION) {
|
||||||
// this.pathFollowingObjects = [];
|
// this.pathFollowingObjects = [];
|
||||||
// this.followObjects = [];
|
// this.followObjects = [];
|
||||||
|
@ -380,20 +137,6 @@ GameLib.System.prototype.stop = function() {
|
||||||
// this.cameraObjects = [];
|
// this.cameraObjects = [];
|
||||||
// this.lightObjects = [];
|
// this.lightObjects = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.systemType === GameLib.System.SYSTEM_TYPE_STORAGE) {
|
|
||||||
|
|
||||||
this.unsubscribe(
|
|
||||||
GameLib.Event.SAVE,
|
|
||||||
this.save
|
|
||||||
);
|
|
||||||
|
|
||||||
this.unsubscribe(
|
|
||||||
GameLib.Event.LOAD,
|
|
||||||
this.load
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -401,7 +144,6 @@ GameLib.System.prototype.stop = function() {
|
||||||
* @returns {GameLib.API.System}
|
* @returns {GameLib.API.System}
|
||||||
*/
|
*/
|
||||||
GameLib.System.prototype.toApiObject = function() {
|
GameLib.System.prototype.toApiObject = function() {
|
||||||
|
|
||||||
return new GameLib.API.System(
|
return new GameLib.API.System(
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/**
|
||||||
|
* System takes care of updating all the entities (based on their component data)
|
||||||
|
* @param graphics
|
||||||
|
* @param apiSystem GameLib.API.System
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.System.GUI = function(
|
||||||
|
graphics,
|
||||||
|
apiSystem
|
||||||
|
) {
|
||||||
|
GameLib.System.call(
|
||||||
|
this,
|
||||||
|
graphics,
|
||||||
|
apiSystem
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.System.GUI.prototype = Object.create(GameLib.System.prototype);
|
||||||
|
GameLib.System.GUI.prototype.constructor = GameLib.System.GUI;
|
||||||
|
|
||||||
|
GameLib.System.GUI.prototype.start = function() {
|
||||||
|
|
||||||
|
var guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI);
|
||||||
|
|
||||||
|
guis.map(function(gui){
|
||||||
|
gui.domElement.instance.parentElement.appendChild(gui.instance.domElement);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.System.GUI.prototype.stop = function() {
|
||||||
|
|
||||||
|
var guis = GameLib.EntityManager.Instance.queryComponents(GameLib.GUI);
|
||||||
|
|
||||||
|
guis.map(function(gui){
|
||||||
|
gui.domElement.instance.parentElement.removeChild(gui.instance.domElement);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
/**
|
||||||
|
* System takes care of updating all the entities (based on their component data)
|
||||||
|
* @param graphics
|
||||||
|
* @param apiSystem GameLib.API.System
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.System.Input = function(
|
||||||
|
graphics,
|
||||||
|
apiSystem
|
||||||
|
) {
|
||||||
|
GameLib.System.call(
|
||||||
|
this,
|
||||||
|
graphics,
|
||||||
|
apiSystem
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.System.Input.prototype = Object.create(GameLib.System.prototype);
|
||||||
|
GameLib.System.Input.prototype.constructor = GameLib.System.Input;
|
||||||
|
|
||||||
|
GameLib.System.Input.prototype.start = function() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hookup all editor input capabilities
|
||||||
|
*/
|
||||||
|
var entities = GameLib.EntityManager.Instance.query([GameLib.D3.Input.Editor]);
|
||||||
|
|
||||||
|
entities.map(function(entity){
|
||||||
|
|
||||||
|
var component = entity.getFirstComponent(GameLib.D3.Input.Editor);
|
||||||
|
|
||||||
|
component.mouseDown = component.onMouseDown(entity, GameLib.EntityManager.Instance).bind(component);
|
||||||
|
component.mouseMove = component.onMouseMove(entity).bind(component);
|
||||||
|
component.keyDown = component.onKeyDown(entity, GameLib.EntityManager.Instance).bind(component);
|
||||||
|
component.keyUp = component.onKeyUp(entity, GameLib.EntityManager.Instance).bind(component);
|
||||||
|
|
||||||
|
component.domElement.instance.addEventListener('mousedown', component.mouseDown, false);
|
||||||
|
component.domElement.instance.addEventListener('mousemove', component.mouseMove, false);
|
||||||
|
component.domElement.instance.addEventListener('keydown', component.keyDown, false);
|
||||||
|
component.domElement.instance.addEventListener('keyup', component.keyUp, false);
|
||||||
|
|
||||||
|
component.controls = new THREE.EditorControls(
|
||||||
|
component.camera.instance,
|
||||||
|
component.domElement.instance
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After our mouse 'up' editor controls would have updated our camera
|
||||||
|
* instance, so we need to update our game-lib camera to reflect these
|
||||||
|
* changes - we override
|
||||||
|
*/
|
||||||
|
component.mouseUp = function(center) {
|
||||||
|
return function() {
|
||||||
|
var camera = entity.getFirstComponent(GameLib.D3.Camera);
|
||||||
|
camera.position.x = camera.instance.position.x;
|
||||||
|
camera.position.y = camera.instance.position.y;
|
||||||
|
camera.position.z = camera.instance.position.z;
|
||||||
|
|
||||||
|
camera.quaternion.x = camera.instance.quaternion.x;
|
||||||
|
camera.quaternion.y = camera.instance.quaternion.y;
|
||||||
|
camera.quaternion.z = camera.instance.quaternion.z;
|
||||||
|
camera.quaternion.w = camera.instance.quaternion.w;
|
||||||
|
|
||||||
|
camera.lookAt.x = center.x;
|
||||||
|
camera.lookAt.y = center.y;
|
||||||
|
camera.lookAt.z = center.z;
|
||||||
|
|
||||||
|
camera.lookAt.instance.copy(center);
|
||||||
|
};
|
||||||
|
}(component.controls.center).bind(component);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same applies to our mouse 'scroll' event
|
||||||
|
*/
|
||||||
|
component.mouseWheel = function() {
|
||||||
|
return function() {
|
||||||
|
var camera = entity.getFirstComponent(GameLib.D3.Camera);
|
||||||
|
camera.position.x = camera.instance.position.x;
|
||||||
|
camera.position.y = camera.instance.position.y;
|
||||||
|
camera.position.z = camera.instance.position.z;
|
||||||
|
};
|
||||||
|
}.bind(component);
|
||||||
|
|
||||||
|
component.domElement.instance.addEventListener('mousewheel', component.mouseWheel, false);
|
||||||
|
component.domElement.instance.addEventListener('mouseup', component.mouseUp, false);
|
||||||
|
|
||||||
|
}.bind(this))
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.System.Input.prototype.stop = function() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Now remove all editor input capabilities
|
||||||
|
*/
|
||||||
|
var entities = GameLib.EntityManager.Instance.query([GameLib.D3.Input.Editor]);
|
||||||
|
|
||||||
|
entities.map(function(entity){
|
||||||
|
var component = entity.getFirstComponent(GameLib.D3.Input.Editor);
|
||||||
|
component.domElement.instance.removeEventListener('mousedown', component.mouseDown, false);
|
||||||
|
component.domElement.instance.removeEventListener('mousemove', component.mouseMove, false);
|
||||||
|
component.domElement.instance.removeEventListener('keydown', component.keyDown, false);
|
||||||
|
component.domElement.instance.removeEventListener('keyup', component.keyUp, false);
|
||||||
|
component.controls.dispose();
|
||||||
|
component.domElement.instance.removeEventListener('mouseup', component.mouseUp, false);
|
||||||
|
component.domElement.instance.removeEventListener('mousewheel', component.mouseWheel, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,141 @@
|
||||||
|
/**
|
||||||
|
* System takes care of updating all the entities (based on their component data)
|
||||||
|
* @param graphics
|
||||||
|
* @param apiSystem GameLib.API.System
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.System.Render = function(
|
||||||
|
graphics,
|
||||||
|
apiSystem
|
||||||
|
) {
|
||||||
|
|
||||||
|
GameLib.System.call(
|
||||||
|
this,
|
||||||
|
graphics,
|
||||||
|
apiSystem
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.System.Render.prototype = Object.create(GameLib.System.prototype);
|
||||||
|
GameLib.System.Render.prototype.constructor = GameLib.System.Render;
|
||||||
|
|
||||||
|
GameLib.System.Render.prototype.start = function() {
|
||||||
|
|
||||||
|
this.renderEntities = GameLib.EntityManager.Instance.query(
|
||||||
|
[
|
||||||
|
GameLib.D3.Viewport,
|
||||||
|
GameLib.D3.Scene,
|
||||||
|
GameLib.D3.Renderer,
|
||||||
|
GameLib.D3.Camera
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
this.renderEntities.map(
|
||||||
|
function(entity) {
|
||||||
|
var stats = entity.getFirstComponent(GameLib.D3.Stats);
|
||||||
|
stats.resize();
|
||||||
|
stats.domElement.instance.parentElement.appendChild(stats.instance.dom);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update script
|
||||||
|
*/
|
||||||
|
GameLib.System.Render.prototype.update = function() {
|
||||||
|
|
||||||
|
this.renderEntities.map(
|
||||||
|
|
||||||
|
function (renderEntity) {
|
||||||
|
|
||||||
|
var stats = renderEntity.getFirstComponent(GameLib.D3.Stats);
|
||||||
|
|
||||||
|
if (!stats.instance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var renderer = renderEntity.getFirstComponent(GameLib.D3.Renderer);
|
||||||
|
var camera = renderEntity.getFirstComponent(GameLib.D3.Camera);
|
||||||
|
var viewports = renderEntity.getComponents(GameLib.D3.Viewport);
|
||||||
|
var scenes = renderEntity.getComponents(GameLib.D3.Scene);
|
||||||
|
|
||||||
|
if (!renderer.instance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (viewports.length > 1) {
|
||||||
|
renderer.instance.autoClear = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scenes.length > 1) {
|
||||||
|
renderer.instance.autoClear = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.instance.clear();
|
||||||
|
|
||||||
|
viewports.map(
|
||||||
|
function (viewport) {
|
||||||
|
|
||||||
|
renderer.instance.setViewport(
|
||||||
|
viewport.x * renderer.width,
|
||||||
|
viewport.y * renderer.height,
|
||||||
|
viewport.width * renderer.width,
|
||||||
|
viewport.height * renderer.height
|
||||||
|
);
|
||||||
|
|
||||||
|
function renderScene(scene) {
|
||||||
|
|
||||||
|
if (!scene.instance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scene.activeCamera) {
|
||||||
|
|
||||||
|
if (!scene.activeCamera.instance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.instance.render(
|
||||||
|
scene.instance,
|
||||||
|
scene.activeCamera.instance
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (!camera.instance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.instance.render(
|
||||||
|
scene.instance,
|
||||||
|
camera.instance
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (viewport.scenes && viewport.scenes.length > 0) {
|
||||||
|
viewport.scenes.map(renderScene);
|
||||||
|
} else {
|
||||||
|
scenes.map(renderScene);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
stats.instance.end();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.System.Render.prototype.stop = function() {
|
||||||
|
|
||||||
|
this.renderEntities.map(
|
||||||
|
function(entity) {
|
||||||
|
var stats = entity.getFirstComponent(GameLib.D3.Stats);
|
||||||
|
stats.domElement.instance.parentElement.removeChild(stats.instance.dom);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.renderEntities = [];
|
||||||
|
};
|
||||||
|
|
|
@ -29,18 +29,34 @@ GameLib.System.Storage = function(
|
||||||
}
|
}
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
|
||||||
this.subscribe(
|
this.loginSubscription = null;
|
||||||
GameLib.Event.LOGGED_IN,
|
this.saveSubscription = null;
|
||||||
function(data) {
|
this.loadSubscription = null;
|
||||||
this.token = data.token;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Storage.prototype = Object.create(GameLib.System.prototype);
|
GameLib.System.Storage.prototype = Object.create(GameLib.System.prototype);
|
||||||
GameLib.System.Storage.prototype.constructor = GameLib.System.Storage;
|
GameLib.System.Storage.prototype.constructor = GameLib.System.Storage;
|
||||||
|
|
||||||
|
GameLib.System.Storage.prototype.start = function() {
|
||||||
|
|
||||||
|
this.loginSubscription = this.subscribe(
|
||||||
|
GameLib.Event.LOGGED_IN,
|
||||||
|
function(data) {
|
||||||
|
this.token = data.token;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.saveSubscription = this.subscribe(
|
||||||
|
GameLib.Event.SAVE,
|
||||||
|
this.save
|
||||||
|
);
|
||||||
|
|
||||||
|
this.loadSubscription = this.subscribe(
|
||||||
|
GameLib.Event.LOAD,
|
||||||
|
this.load
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 'Saves' data to baseURL
|
* 'Saves' data to baseURL
|
||||||
|
@ -132,3 +148,10 @@ GameLib.System.Storage.prototype.load = function(data) {
|
||||||
|
|
||||||
xhr.send();
|
xhr.send();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.System.Storage.prototype.stop = function() {
|
||||||
|
this.loginSubscription.remove();
|
||||||
|
this.loadSubscription.remove();
|
||||||
|
this.saveSubscription.remove();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue