From eb5e45bed68d6db55be24940885914202cb1d725 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Mon, 22 May 2017 11:34:18 +0200 Subject: [PATCH] GUI system --- src/game-lib-api-system.js | 20 +------ src/game-lib-d3-stats.js | 4 ++ src/game-lib-entity.js | 104 ++++++++++++++++++------------------- src/game-lib-gui.js | 8 ++- src/game-lib-system.js | 64 +++++++++++------------ 5 files changed, 94 insertions(+), 106 deletions(-) diff --git a/src/game-lib-api-system.js b/src/game-lib-api-system.js index feed0c3..81dc393 100644 --- a/src/game-lib-api-system.js +++ b/src/game-lib-api-system.js @@ -4,8 +4,6 @@ * @param name String * @param systemType * @param entityManager - * @param domElement - * @param domStats * @param parentEntity * @constructor */ @@ -14,8 +12,6 @@ GameLib.API.System = function ( name, systemType, entityManager, - domElement, - domStats, parentEntity ) { @@ -23,9 +19,7 @@ GameLib.API.System = function ( this, GameLib.Component.COMPONENT_SYSTEM, { - 'entityManager' : GameLib.EntityManager, - 'domElement' : GameLib.DomElement, - 'domStats' : GameLib.DomElement + 'entityManager' : GameLib.EntityManager }, null, parentEntity @@ -50,16 +44,6 @@ GameLib.API.System = function ( entityManager = null; } this.entityManager = entityManager; - - if (GameLib.Utils.UndefinedOrNull(domElement)){ - domElement = null; - } - this.domElement = domElement; - - if (GameLib.Utils.UndefinedOrNull(domStats)){ - domStats = null; - } - this.domStats = domStats; }; GameLib.API.System.prototype = Object.create(GameLib.Component.prototype); @@ -76,8 +60,6 @@ GameLib.API.System.FromObjectComponent = function(objectComponent) { objectComponent.name, objectComponent.systemType, objectComponent.entityManager, - objectComponent.domElement, - objectComponent.domStats, objectComponent.parentEntity ); }; diff --git a/src/game-lib-d3-stats.js b/src/game-lib-d3-stats.js index 8b59b28..f73944f 100644 --- a/src/game-lib-d3-stats.js +++ b/src/game-lib-d3-stats.js @@ -51,6 +51,10 @@ GameLib.D3.Stats = function( GameLib.D3.Stats.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.Stats.prototype.constructor = GameLib.D3.Stats; +GameLib.D3.Stats.prototype.resize = function() { + console.log('override stats resize per implementation'); +}; + /** * Creates a helper instance * @param update diff --git a/src/game-lib-entity.js b/src/game-lib-entity.js index 9f09310..d90da4f 100644 --- a/src/game-lib-entity.js +++ b/src/game-lib-entity.js @@ -29,58 +29,58 @@ GameLib.Entity = function ( this.componentToCreate = 0; - this.components = this.components.map( - - function (apiComponent) { - - if (apiComponent instanceof GameLib.D3.API.PathFollowing) { - return new GameLib.D3.PathFollowing(this.graphics, apiComponent); - } - - if (apiComponent instanceof GameLib.D3.API.Renderer) { - return new GameLib.D3.Renderer(this.graphics, apiComponent); - } - - if (apiComponent instanceof GameLib.D3.API.RenderTarget) { - return new GameLib.D3.RenderTarget(this.graphics, apiComponent); - } - - if (apiComponent instanceof GameLib.D3.API.Pass) { - return new GameLib.D3.Pass(this.graphics, apiComponent); - } - - if (apiComponent instanceof GameLib.D3.API.Composer) { - return new GameLib.D3.Composer(this.graphics, apiComponent); - } - - if (apiComponent instanceof GameLib.D3.API.Camera) { - return new GameLib.D3.Camera(this.graphics, apiComponent); - } - - if (apiComponent instanceof GameLib.D3.API.LookAt) { - return new GameLib.D3.LookAt(this.graphics, apiComponent); - } - - if (apiComponent instanceof GameLib.D3.API.Follow) { - return new GameLib.D3.Follow(this.graphics, apiComponent); - } - - if (apiComponent instanceof GameLib.D3.API.Input.Editor) { - return new GameLib.D3.Input.Editor(this.graphics, apiComponent); - } - - if (apiComponent instanceof GameLib.D3.API.Input.Drive) { - return new GameLib.D3.Input.Drive(this.graphics, apiComponent); - } - - if (apiComponent instanceof GameLib.D3.API.Spline) { - return new GameLib.D3.Spline(this.graphics, apiComponent); - } - - return apiComponent; - - }.bind(this) - ); + // this.components = this.components.map( + // + // function (apiComponent) { + // + // if (apiComponent instanceof GameLib.D3.API.PathFollowing) { + // return new GameLib.D3.PathFollowing(this.graphics, apiComponent); + // } + // + // if (apiComponent instanceof GameLib.D3.API.Renderer) { + // return new GameLib.D3.Renderer(this.graphics, apiComponent); + // } + // + // if (apiComponent instanceof GameLib.D3.API.RenderTarget) { + // return new GameLib.D3.RenderTarget(this.graphics, apiComponent); + // } + // + // if (apiComponent instanceof GameLib.D3.API.Pass) { + // return new GameLib.D3.Pass(this.graphics, apiComponent); + // } + // + // if (apiComponent instanceof GameLib.D3.API.Composer) { + // return new GameLib.D3.Composer(this.graphics, apiComponent); + // } + // + // if (apiComponent instanceof GameLib.D3.API.Camera) { + // return new GameLib.D3.Camera(this.graphics, apiComponent); + // } + // + // if (apiComponent instanceof GameLib.D3.API.LookAt) { + // return new GameLib.D3.LookAt(this.graphics, apiComponent); + // } + // + // if (apiComponent instanceof GameLib.D3.API.Follow) { + // return new GameLib.D3.Follow(this.graphics, apiComponent); + // } + // + // if (apiComponent instanceof GameLib.D3.API.Input.Editor) { + // return new GameLib.D3.Input.Editor(this.graphics, apiComponent); + // } + // + // if (apiComponent instanceof GameLib.D3.API.Input.Drive) { + // return new GameLib.D3.Input.Drive(this.graphics, apiComponent); + // } + // + // if (apiComponent instanceof GameLib.D3.API.Spline) { + // return new GameLib.D3.Spline(this.graphics, apiComponent); + // } + // + // return apiComponent; + // + // }.bind(this) + // ); this.instance = this.createInstance(); }; diff --git a/src/game-lib-gui.js b/src/game-lib-gui.js index b0acee6..a50e0fb 100644 --- a/src/game-lib-gui.js +++ b/src/game-lib-gui.js @@ -54,7 +54,6 @@ GameLib.GUI = function( } }; - GameLib.Component.call( this, GameLib.Component.COMPONENT_GUI, @@ -92,6 +91,13 @@ GameLib.GUI = function( GameLib.GUI.prototype = Object.create(GameLib.Component.prototype); GameLib.GUI.prototype.constructor = GameLib.GUI; +/** + * Resize function + */ +GameLib.GUI.prototype.resize = function() { + console.log('override me per implementation'); +}; + /** * Creates a helper instance * @param update diff --git a/src/game-lib-system.js b/src/game-lib-system.js index b38237c..1001224 100644 --- a/src/game-lib-system.js +++ b/src/game-lib-system.js @@ -26,8 +26,6 @@ GameLib.System = function( apiSystem.name, apiSystem.systemType, apiSystem.entityManager, - apiSystem.domElement, - apiSystem.domStats, apiSystem.parentEntity ); @@ -38,11 +36,6 @@ GameLib.System = function( ); } - if (this.domElement instanceof GameLib.API.DomElement) { - this.domElement = new GameLib.DomElement( - this.domElement - ); - } }; GameLib.System.prototype = Object.create(GameLib.API.System.prototype); @@ -53,6 +46,7 @@ GameLib.System.SYSTEM_TYPE_RENDER = 0x1; GameLib.System.SYSTEM_TYPE_ANIMATION = 0x2; GameLib.System.SYSTEM_TYPE_INPUT = 0x4; GameLib.System.SYSTEM_TYPE_STORAGE = 0x8; +GameLib.System.SYSTEM_TYPE_GUI = 0x10; GameLib.System.SYSTEM_TYPE_ALL = 0xFFFF; /** @@ -102,19 +96,20 @@ GameLib.System.prototype.start = function() { this.renderEntities.map( function(entity) { var stats = entity.getFirstComponent(GameLib.D3.Stats); - stats.instance.dom.style.position = 'absolute'; - stats.instance.dom.style.top = '34px'; - stats.instance.dom.style.left = '0px'; + stats.resize(); stats.domElement.instance.parentElement.appendChild(stats.instance.dom); - - var gui = entity.getFirstComponent(GameLib.GUI); - gui.instance.domElement.style.position = 'absolute'; - gui.instance.domElement.style.top = '34px'; - gui.instance.domElement.style.right = '0px'; - gui.instance.domElement.getElementsByTagName('ul')[0].style.maxHeight = window.innerHeight - 93 + 'px'; - gui.domElement.instance.parentElement.appendChild(gui.instance.domElement); } ) + } + + if (this.systemType === GameLib.System.SYSTEM_TYPE_GUI) { + + var guis = this.entityManager.queryComponents(GameLib.GUI); + + guis.map(function(gui){ + gui.resize(); + gui.domElement.instance.parentElement.appendChild(gui.instance.domElement); + }) } @@ -245,18 +240,31 @@ GameLib.System.prototype.stop = function() { 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('contextmenu', component.contextMenu, false); component.controls.dispose(); }); console.log('stopped all input systems'); } + if (this.systemType === GameLib.System.SYSTEM_TYPE_GUI) { + console.log('stopping GUI system'); + var guis = this.entityManager.queryComponents(GameLib.GUI); + + guis.map(function(gui){ + gui.domElement.instance.parentElement.removeChild(gui.instance.domElement); + }) + } + if (this.systemType === GameLib.System.SYSTEM_TYPE_RENDER) { - this.domElement.innerHTML = 'Rendering System Stopped'; - this.renderers = []; - this.viewports = []; - this.meshes = []; + + 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) { @@ -276,23 +284,11 @@ GameLib.System.prototype.stop = function() { */ GameLib.System.prototype.toApiObject = function() { - var apiDomElement = null; - if (this.domElement instanceof GameLib.DomElement) { - apiDomElement = this.domElement.toApiObject(); - } - - var apiDomStats = null; - if (this.domStats instanceof GameLib.DomElement) { - apiDomStats = this.domStats.toApiObject(); - } - return new GameLib.API.System( this.id, this.name, this.systemType, GameLib.Utils.IdOrNull(this.entityManager), - apiDomElement, - apiDomStats, GameLib.Utils.IdOrNull(this.parentEntity) ); };