From e2faf5be253bd2ee6ac747a65d8aa6b942ae150d Mon Sep 17 00:00:00 2001 From: "Theunis J. Botha" Date: Tue, 6 Jun 2017 11:25:02 +0200 Subject: [PATCH] render scenes for viewports if defined --- src/game-lib-api-entity.js | 5 ++++- src/game-lib-d3-api-viewport.js | 14 ++++++++++++-- src/game-lib-d3-viewport.js | 4 ++++ src/game-lib-entity.js | 4 ++++ src/game-lib-gui.js | 25 +++++++++++++++++++----- src/game-lib-system.js | 34 ++++++++++++++++++--------------- 6 files changed, 63 insertions(+), 23 deletions(-) diff --git a/src/game-lib-api-entity.js b/src/game-lib-api-entity.js index 01752c1..b5cee90 100644 --- a/src/game-lib-api-entity.js +++ b/src/game-lib-api-entity.js @@ -24,11 +24,14 @@ GameLib.API.Entity = function( } this.parentEntityManager = parentEntityManager; + this.activeComponent = null; + GameLib.Component.call( this, GameLib.Component.COMPONENT_ENTITY, { - 'components' : [GameLib.Component] + 'components' : [GameLib.Component], + 'activeComponent' : GameLib.Component }, null, parentEntity diff --git a/src/game-lib-d3-api-viewport.js b/src/game-lib-d3-api-viewport.js index 8e52a16..0a3fd64 100644 --- a/src/game-lib-d3-api-viewport.js +++ b/src/game-lib-d3-api-viewport.js @@ -6,6 +6,7 @@ * @param height * @param x * @param y + * @param scenes * @param parentEntity * @constructor */ @@ -16,12 +17,15 @@ GameLib.D3.API.Viewport = function( height, x, y, + scenes, parentEntity ) { GameLib.Component.call( this, GameLib.Component.COMPONENT_VIEWPORT, - null, + { + 'scenes' : [GameLib.D3.Scene] + }, null, parentEntity ); @@ -55,6 +59,11 @@ GameLib.D3.API.Viewport = function( y = 0; } this.y = y; + + if (GameLib.Utils.UndefinedOrNull(scenes)) { + scenes = []; + } + this.scenes = scenes; }; GameLib.D3.API.Viewport.prototype = Object.create(GameLib.Component.prototype); @@ -65,7 +74,7 @@ GameLib.D3.API.Viewport.prototype.constructor = GameLib.D3.API.Viewport; * @param objectViewport * @constructor */ -GameLib.D3.API.Viewport.FromObjectViewport = function(objectViewport) { +GameLib.D3.API.Viewport.FromObjectComponent = function(objectViewport) { return new GameLib.D3.API.Viewport( objectViewport.id, objectViewport.name, @@ -73,6 +82,7 @@ GameLib.D3.API.Viewport.FromObjectViewport = function(objectViewport) { objectViewport.height, objectViewport.x, objectViewport.y, + objectViewport.scenes, objectViewport.parentEntity ); }; diff --git a/src/game-lib-d3-viewport.js b/src/game-lib-d3-viewport.js index e6bf6f0..c13b8e2 100644 --- a/src/game-lib-d3-viewport.js +++ b/src/game-lib-d3-viewport.js @@ -28,6 +28,7 @@ GameLib.D3.Viewport = function ( apiViewport.height, apiViewport.x, apiViewport.y, + apiViewport.scenes, apiViewport.parentEntity ); @@ -77,6 +78,9 @@ GameLib.D3.Viewport.prototype.toApiObject = function() { this.height, this.x, this.y, + this.scenes.map(function(scene){ + return GameLib.Utils.IdOrNull(scene); + }), GameLib.Utils.IdOrNull(this.parentEntity) ); diff --git a/src/game-lib-entity.js b/src/game-lib-entity.js index 7bb2b25..f754ad2 100644 --- a/src/game-lib-entity.js +++ b/src/game-lib-entity.js @@ -170,6 +170,10 @@ GameLib.Entity.prototype.hasComponent = function(constructor) { */ GameLib.Entity.prototype.removeComponent = function(component) { + if (GameLib.Utils.UndefinedOrNull(component)) { + component = this.activeComponent; + } + component.parentEntity = null; var index = this.components.indexOf(component); diff --git a/src/game-lib-gui.js b/src/game-lib-gui.js index e4fe2b7..50650d1 100644 --- a/src/game-lib-gui.js +++ b/src/game-lib-gui.js @@ -770,6 +770,8 @@ GameLib.GUI.prototype.buildSelectControl = function(folder, object, property, en entityManager: entityManager } ); + + gui.build(entityManager); } else { /** * Old way of doing things @@ -781,7 +783,7 @@ GameLib.GUI.prototype.buildSelectControl = function(folder, object, property, en /** * Properties changed - rebuild GUI */ - gui.build(entityManager); + }; }(this) @@ -841,8 +843,15 @@ GameLib.GUI.prototype.buildEntitySelectionControlFromArray = function( ); folder.add(object, property, options).name(property).listen().onChange( - function(entityManager) { + function(entityManager, gui) { return function(value) { + + if (value !== 'null') { + object[property] = entityManager.findEntityById(value); + } else { + object[property] = null; + } + GameLib.Event.Emit( GameLib.Event.PARENT_ENTITY_CHANGE, { @@ -851,9 +860,15 @@ GameLib.GUI.prototype.buildEntitySelectionControlFromArray = function( object : object } ); - }; - }(entityManager) - ); + + this.initialValue = entityManager.findEntityById(value); + }; + }(entityManager, this) + ).onFinishChange(function(gui, entityManager){ + return function() { + gui.build(entityManager); + } + }(this, entityManager)); }; /** diff --git a/src/game-lib-system.js b/src/game-lib-system.js index 4744254..a0353c0 100644 --- a/src/game-lib-system.js +++ b/src/game-lib-system.js @@ -243,7 +243,7 @@ GameLib.System.prototype.update = function(deltaTime) { renderer.instance.clear(); viewports.map( - function(viewport){ + function(viewport){ renderer.instance.setViewport( viewport.x * renderer.width, @@ -252,21 +252,25 @@ GameLib.System.prototype.update = function(deltaTime) { viewport.height * renderer.height ); - scenes.map(function(scene){ + function renderScene(scene) { + if (scene.activeCamera) { + renderer.instance.render( + scene.instance, + scene.activeCamera.instance + ); + } else { + renderer.instance.render( + scene.instance, + camera.instance + ); + } + } - if (scene.activeCamera) { - renderer.instance.render( - scene.instance, - scene.activeCamera.instance - ); - } else { - renderer.instance.render( - scene.instance, - camera.instance - ); - } - - }); + if (viewport.scenes && viewport.scenes.length > 0) { + viewport.scenes.map(renderScene); + } else { + scenes.map(renderScene); + } } );