systems to doms

beta.r3js.org
Theunis J. Botha 2017-01-20 13:40:27 +01:00
parent ba1aa215b7
commit c3d51b5549
17 changed files with 926 additions and 439 deletions

View File

@ -28,7 +28,7 @@ GameLib.Component = function(
GameLib.Component.prototype = Object.create(GameLib.API.Component.prototype); GameLib.Component.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.Component.prototype.constructor = GameLib.Component; GameLib.Component.prototype.constructor = GameLib.Component;
GameLib.Component.COMPONENT_PATH_FOLLOWING = 0x1; GameLib.Component.COMPONENT_PATH_FOLLOWING = 0x1;
GameLib.Component.COMPONENT_MATERIAL = 0x2; GameLib.Component.COMPONENT_MATERIAL = 0x2;
GameLib.Component.COMPONENT_RENDERER = 0x3; GameLib.Component.COMPONENT_RENDERER = 0x3;
GameLib.Component.COMPONENT_LOOK_AT = 0x5; GameLib.Component.COMPONENT_LOOK_AT = 0x5;
@ -54,6 +54,7 @@ GameLib.Component.COMPONENT_MOUSE = 0x18;
GameLib.Component.COMPONENT_SKELETON = 0x19; GameLib.Component.COMPONENT_SKELETON = 0x19;
GameLib.Component.COMPONENT_TEXTURE = 0x1a; GameLib.Component.COMPONENT_TEXTURE = 0x1a;
GameLib.Component.COMPONENT_ENTITY_MANAGER = 0x1b; GameLib.Component.COMPONENT_ENTITY_MANAGER = 0x1b;
GameLib.Component.COMPONENT_DOM_ELEMENT = 0x1c;
/** /**
* Components are linked at runtime - for storing, we just store the ID * Components are linked at runtime - for storing, we just store the ID

View File

@ -0,0 +1,60 @@
/**
* API DomElement
* @param id
* @param name
* @param domElementId
* @param parentEntity
* @constructor
*/
GameLib.API.DomElement = function(
id,
name,
domElementId,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
GameLib.Component.call(
this,
GameLib.Component.COMPONENT_DOM_ELEMENT,
null,
null,
parentEntity
);
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'DOM Element (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(domElementId)) {
domElementId = '';
}
this.domElementId = domElementId;
};
GameLib.API.DomElement.prototype = Object.create(GameLib.Component.prototype);
GameLib.API.DomElement.prototype.constructor = GameLib.API.DomElement;
/**
* Returns an API domElement from an Object domElement
* @param objectDomElement
* @constructor
*/
GameLib.API.DomElement.FromObjectDomElement = function (objectDomElement) {
return new GameLib.API.DomElement(
objectDomElement.id,
objectDomElement.name,
objectDomElement.domElementId,
objectDomElement.parentEntity
)
};

View File

@ -26,32 +26,6 @@ GameLib.API.Entity = function(
this.components = components; this.components = components;
}; };
/**
* Adds a components to the entity
* @param component GameLib.Component
*/
GameLib.API.Entity.prototype.addComponent = function(component) {
this.components.push(component);
};
/**
* Removes a component from this entity
* @param component GameLib.Component
*/
GameLib.API.Entity.prototype.removeComponent = function(component) {
var index = this.components.indexOf(component);
if (index == -1) {
console.log('failed to remove component');
return false;
}
this.components.splice(index, 1);
return true;
};
/** /**
* Returns an API entity from an Object entity * Returns an API entity from an Object entity
* @param objectEntity * @param objectEntity

View File

@ -4,6 +4,8 @@
* @param name String * @param name String
* @param systemType * @param systemType
* @param entityManager * @param entityManager
* @param domElement
* @param domStats
* @param parentEntity * @param parentEntity
* @constructor * @constructor
*/ */
@ -12,13 +14,19 @@ GameLib.API.System = function (
name, name,
systemType, systemType,
entityManager, entityManager,
domElement,
domStats,
parentEntity parentEntity
) { ) {
GameLib.Component.call( GameLib.Component.call(
this, this,
GameLib.Component.COMPONENT_SYSTEM, GameLib.Component.COMPONENT_SYSTEM,
null, {
'entityManager' : GameLib.EntityManager,
'domElement' : GameLib.DomElement,
'domStats' : GameLib.DomElement
},
null, null,
parentEntity parentEntity
); );
@ -42,6 +50,16 @@ GameLib.API.System = function (
entityManager = null; entityManager = null;
} }
this.entityManager = entityManager; 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); GameLib.API.System.prototype = Object.create(GameLib.Component.prototype);
@ -58,6 +76,8 @@ GameLib.API.System.FromObjectComponent = function(objectComponent) {
objectComponent.name, objectComponent.name,
objectComponent.systemType, objectComponent.systemType,
objectComponent.entityManager, objectComponent.entityManager,
objectComponent.domElement,
objectComponent.domStats,
objectComponent.parentEntity objectComponent.parentEntity
); );
}; };

View File

@ -2,28 +2,53 @@
* Raw Editor API object - should always correspond with the Editor Schema * Raw Editor API object - should always correspond with the Editor Schema
* @param id * @param id
* @param name * @param name
* @param game [GameLib.API.D3.Game] * @param baseUrl
* @param path
* @param games [GameLib.API.D3.Game]
* @param scenes
* @param cameras
* @param composers
* @param viewports
* @param renderers
* @param renderTargets
* @param systems
* @param entityManager
* @param allSelected * @param allSelected
* @param selectedObjects * @param selectedObjects
* @param viewports
* @param parentEntity * @param parentEntity
* @constructor * @constructor
*/ */
GameLib.D3.API.Editor = function( GameLib.D3.API.Editor = function(
id, id,
name, name,
game, baseUrl,
path,
games,
scenes,
cameras,
composers,
viewports,
renderers,
renderTargets,
systems,
entityManager,
allSelected, allSelected,
selectedObjects, selectedObjects,
viewports,
parentEntity parentEntity
) { ) {
GameLib.Component.call( GameLib.Component.call(
this, this,
GameLib.Component.COMPONENT_EDITOR, GameLib.Component.COMPONENT_EDITOR,
{ {
'game' : GameLib.D3.Game, 'games' : [GameLib.D3.Game],
'viewports' : [GameLib.D3.Viewport] 'scenes' : [GameLib.D3.Scene],
'cameras' : [GameLib.D3.Camera],
'composers' : [GameLib.D3.Composer],
'viewports' : [GameLib.D3.Viewport],
'renderers' : [GameLib.D3.Renderer],
'renderTargets' : [GameLib.D3.RenderTarget],
'systems' : [GameLib.System],
'entityManager' : GameLib.EntityManager
}, },
null, null,
parentEntity parentEntity
@ -39,11 +64,61 @@ GameLib.D3.API.Editor = function(
} }
this.name = name; this.name = name;
if (GameLib.Utils.UndefinedOrNull(game)) { if (GameLib.Utils.UndefinedOrNull(baseUrl)) {
game = null; baseUrl = '';
} }
this.game = game; this.baseUrl = baseUrl;
if (GameLib.Utils.UndefinedOrNull(path)) {
path = '';
}
this.path = path;
if (GameLib.Utils.UndefinedOrNull(games)) {
games = [];
}
this.games = games;
if (GameLib.Utils.UndefinedOrNull(scenes)) {
scenes = [];
}
this.scenes = scenes;
if (GameLib.Utils.UndefinedOrNull(cameras)) {
cameras = [];
}
this.cameras = cameras;
if (GameLib.Utils.UndefinedOrNull(composers)) {
composers = [];
}
this.composers = composers;
if (GameLib.Utils.UndefinedOrNull(viewports)) {
viewports = [];
}
this.viewports = viewports;
if (GameLib.Utils.UndefinedOrNull(renderers)) {
renderers = [];
}
this.renderers = renderers;
if (GameLib.Utils.UndefinedOrNull(renderTargets)) {
renderTargets = [];
}
this.renderTargets = renderTargets;
if (GameLib.Utils.UndefinedOrNull(systems)) {
systems = [];
}
this.systems = systems;
if (GameLib.Utils.UndefinedOrNull(entityManager)) {
entityManager = new GameLib.API.EntityManager();
}
this.entityManager = entityManager;
if (GameLib.Utils.UndefinedOrNull(allSelected)) { if (GameLib.Utils.UndefinedOrNull(allSelected)) {
allSelected = false; allSelected = false;
} }
@ -54,11 +129,6 @@ GameLib.D3.API.Editor = function(
} }
this.selectedObjects = selectedObjects; this.selectedObjects = selectedObjects;
if (GameLib.Utils.UndefinedOrNull(viewports)) {
viewports = [];
}
this.viewports = viewports;
}; };
GameLib.D3.API.Editor.prototype = Object.create(GameLib.Component.prototype); GameLib.D3.API.Editor.prototype = Object.create(GameLib.Component.prototype);
@ -70,14 +140,102 @@ GameLib.D3.API.Editor.prototype.constructor = GameLib.D3.API.Editor;
* @constructor * @constructor
*/ */
GameLib.D3.API.Editor.FromObjectEditor = function(objectEditor) { GameLib.D3.API.Editor.FromObjectEditor = function(objectEditor) {
var apiGames = [];
var apiScenes = [];
var apiCameras = [];
var apiComposers = [];
var apiViewports = [];
var apiRenderers = [];
var apiRenderTargets = [];
var apiSystems = [];
var apiEntityManager = null;
if (objectEditor.games) {
apiGames = objectEditor.games.map(
function(objectGame){
return GameLib.D3.API.Game.FromObjectGame(objectGame);
}
);
}
if (objectEditor.scenes) {
apiScenes = objectEditor.scenes.map(
function(objectScene){
return GameLib.D3.API.Scene.FromObjectScene(objectScene);
}
);
}
if (objectEditor.cameras) {
apiCameras = objectEditor.cameras.map(
function(objectCamera){
return GameLib.D3.API.Camera.FromObjectCamera(objectCamera);
}
);
}
if (objectEditor.composers) {
apiComposers = objectEditor.composers.map(
function(objectComposer){
return GameLib.D3.API.Composer.FromObjectComponent(objectComposer);
}
);
}
if (objectEditor.viewports) {
apiViewports = objectEditor.viewports.map(
function(objectViewport){
return GameLib.D3.API.Viewport.FromObjectViewport(objectViewport);
}
);
}
if (objectEditor.renderers) {
apiRenderers = objectEditor.renderers.map(
function(objectRenderer){
return GameLib.D3.API.Renderer.FromObjectComponent(objectRenderer);
}
);
}
if (objectEditor.renderTargets) {
apiRenderTargets = objectEditor.renderTargets.map(
function(objectRenderTarget){
return GameLib.D3.API.RenderTarget.FromObjectComponent(objectRenderTarget);
}
);
}
if (objectEditor.systems) {
apiSystems = objectEditor.systems.map(
function(objectSystem){
return GameLib.API.System.FromObjectComponent(objectSystem);
}
);
}
if (objectEditor.entityManager) {
apiEntityManager = GameLib.API.EntityManager.FromObjectEntityManager(objectEditor.entityManager);
}
return new GameLib.D3.API.Editor( return new GameLib.D3.API.Editor(
objectEditor.id, objectEditor.id,
objectEditor.name, objectEditor.name,
objectEditor.game, objectEditor.baseUrl,
objectEditor.path,
apiGames,
apiScenes,
apiCameras,
apiComposers,
apiViewports,
apiRenderers,
apiRenderTargets,
apiSystems,
apiEntityManager,
objectEditor.allSelected, objectEditor.allSelected,
objectEditor.selectedObjects, objectEditor.selectedObjects,
objectEditor.viewports, objectEditor.parentEntity
objectEditor.parentEntity
); );
}; };

View File

@ -7,10 +7,10 @@
* @param height * @param height
* @param baseUrl * @param baseUrl
* @param path * @param path
* @param scenes
* @param cameras * @param cameras
* @param renderers * @param renderers
* @param composers * @param composers
* @param renderTargets
* @param systems * @param systems
* @param viewports * @param viewports
* @param entityManager * @param entityManager
@ -26,12 +26,12 @@ GameLib.D3.API.Game = function(
gameType, gameType,
width, width,
height, height,
scenes,
cameras, cameras,
renderers,
composers, composers,
viewports,
renderers,
renderTargets,
systems, systems,
viewports,
entityManager, entityManager,
mouse, mouse,
parentEntity parentEntity
@ -40,12 +40,12 @@ GameLib.D3.API.Game = function(
this, this,
GameLib.Component.COMPONENT_GAME, GameLib.Component.COMPONENT_GAME,
{ {
'scenes' : [GameLib.D3.Scene],
'cameras' : [GameLib.D3.Camera], 'cameras' : [GameLib.D3.Camera],
'renderers' : [GameLib.D3.Renderer],
'composers' : [GameLib.D3.Composer], 'composers' : [GameLib.D3.Composer],
'viewports' : [GameLib.D3.Viewport],
'renderers' : [GameLib.D3.Renderer],
'renderTargets' : [GameLib.D3.RenderTarget],
'systems' : [GameLib.System], 'systems' : [GameLib.System],
'viewports' : [GameLib.D3.Viewport],
'entityManager' : GameLib.EntityManager, 'entityManager' : GameLib.EntityManager,
'mouse' : GameLib.Mouse 'mouse' : GameLib.Mouse
}, },
@ -70,7 +70,7 @@ GameLib.D3.API.Game = function(
this.baseUrl = baseUrl; this.baseUrl = baseUrl;
if (GameLib.Utils.UndefinedOrNull(path)) { if (GameLib.Utils.UndefinedOrNull(path)) {
path = null; path = '';
} }
this.path = path; this.path = path;
@ -89,36 +89,36 @@ GameLib.D3.API.Game = function(
} }
this.height = height; this.height = height;
if (GameLib.Utils.UndefinedOrNull(scenes)) {
scenes = [];
}
this.scenes = scenes;
if (GameLib.Utils.UndefinedOrNull(cameras)) { if (GameLib.Utils.UndefinedOrNull(cameras)) {
cameras = []; cameras = [];
} }
this.cameras = cameras; this.cameras = cameras;
if (GameLib.Utils.UndefinedOrNull(renderers)) {
renderers = [];
}
this.renderers = renderers;
if (GameLib.Utils.UndefinedOrNull(composers)) { if (GameLib.Utils.UndefinedOrNull(composers)) {
composers = []; composers = [];
} }
this.composers = composers; this.composers = composers;
if (GameLib.Utils.UndefinedOrNull(viewports)) {
viewports = [];
}
this.viewports = viewports;
if (GameLib.Utils.UndefinedOrNull(renderers)) {
renderers = [];
}
this.renderers = renderers;
if (GameLib.Utils.UndefinedOrNull(renderTargets)) {
renderTargets = [];
}
this.renderTargets = renderTargets;
if (GameLib.Utils.UndefinedOrNull(systems)) { if (GameLib.Utils.UndefinedOrNull(systems)) {
systems = []; systems = [];
} }
this.systems = systems; this.systems = systems;
if (GameLib.Utils.UndefinedOrNull(viewports)) {
viewports = [];
}
this.viewports = viewports;
if (GameLib.Utils.UndefinedOrNull(entityManager)) { if (GameLib.Utils.UndefinedOrNull(entityManager)) {
entityManager = new GameLib.API.EntityManager(); entityManager = new GameLib.API.EntityManager();
} }
@ -140,24 +140,16 @@ GameLib.D3.API.Game.prototype.constructor = GameLib.D3.API.Game;
*/ */
GameLib.D3.API.Game.FromObjectGame = function(objectGame) { GameLib.D3.API.Game.FromObjectGame = function(objectGame) {
var apiScenes = []; var apiCameras = [];
var apiCameras = []; var apiComposers = [];
var apiRenderers = []; var apiViewports = [];
var apiComposers = []; var apiRenderers = [];
var apiSystems = []; var apiRenderTargets = [];
var apiViewports = []; var apiSystems = [];
var apiEntityManager = null; var apiEntityManager = null;
var apiMouse = null; var apiMouse = null;
if (objectGame.scenes) {
apiScenes = objectGame.scenes.map(
function(objectScene){
return GameLib.D3.API.Scene.FromObjectScene(objectScene);
}
);
}
if (objectGame.cameras) { if (objectGame.cameras) {
apiCameras = objectGame.cameras.map( apiCameras = objectGame.cameras.map(
function(objectCamera){ function(objectCamera){
@ -166,14 +158,6 @@ GameLib.D3.API.Game.FromObjectGame = function(objectGame) {
); );
} }
if (objectGame.renderers) {
apiRenderers = objectGame.renderers.map(
function(objectRenderer){
return GameLib.D3.API.Renderer.FromObjectComponent(objectRenderer);
}
);
}
if (objectGame.composers) { if (objectGame.composers) {
apiComposers = objectGame.composers.map( apiComposers = objectGame.composers.map(
function(objectComposer){ function(objectComposer){
@ -182,6 +166,30 @@ GameLib.D3.API.Game.FromObjectGame = function(objectGame) {
); );
} }
if (objectGame.viewports) {
apiViewports = objectGame.viewports.map(
function(objectViewport){
return GameLib.D3.API.Viewport.FromObjectViewport(objectViewport);
}
);
}
if (objectGame.renderers) {
apiRenderers = objectGame.renderers.map(
function(objectRenderer){
return GameLib.D3.API.Renderer.FromObjectComponent(objectRenderer);
}
);
}
if (objectGame.renderTargets) {
apiRenderTargets = objectGame.renderTargets.map(
function(objectRenderTarget){
return GameLib.D3.API.RenderTarget.FromObjectComponent(objectRenderTarget);
}
);
}
if (objectGame.systems) { if (objectGame.systems) {
apiSystems = objectGame.systems.map( apiSystems = objectGame.systems.map(
function(objectSystem){ function(objectSystem){
@ -190,14 +198,6 @@ GameLib.D3.API.Game.FromObjectGame = function(objectGame) {
); );
} }
if (objectGame.viewports) {
apiViewports = objectGame.viewports.map(
function(objectViewport){
return GameLib.D3.API.Viewport.FromObjectViewport(objectViewport);
}
);
}
if (objectGame.entityManager) { if (objectGame.entityManager) {
apiEntityManager = GameLib.API.EntityManager.FromObjectEntityManager(objectGame.entityManager); apiEntityManager = GameLib.API.EntityManager.FromObjectEntityManager(objectGame.entityManager);
} }
@ -214,12 +214,12 @@ GameLib.D3.API.Game.FromObjectGame = function(objectGame) {
objectGame.gameType, objectGame.gameType,
objectGame.width, objectGame.width,
objectGame.height, objectGame.height,
apiScenes,
apiCameras, apiCameras,
apiRenderers,
apiComposers, apiComposers,
apiViewports,
apiRenderers,
apiRenderTargets,
apiSystems, apiSystems,
apiViewports,
apiEntityManager, apiEntityManager,
apiMouse, apiMouse,
objectGame.parentEntity objectGame.parentEntity

View File

@ -142,6 +142,7 @@ GameLib.D3.API.Material = function(
specularMap, specularMap,
parentEntity parentEntity
) { ) {
GameLib.Component.call( GameLib.Component.call(
this, this,
GameLib.Component.COMPONENT_MATERIAL, GameLib.Component.COMPONENT_MATERIAL,

View File

@ -27,7 +27,8 @@ GameLib.D3.API.Scene = function(
GameLib.Component.COMPONENT_SCENE, GameLib.Component.COMPONENT_SCENE,
{ {
'meshes' : [GameLib.D3.Mesh], 'meshes' : [GameLib.D3.Mesh],
'lights' : [GameLib.D3.Light] 'lights' : [GameLib.D3.Light],
'imageFactory' : GameLib.D3.ImageFactory
}, },
false, false,
parentEntity parentEntity

View File

@ -26,42 +26,156 @@ GameLib.D3.Editor = function(
this, this,
apiEditor.id, apiEditor.id,
apiEditor.name, apiEditor.name,
apiEditor.game, apiEditor.baseUrl,
apiEditor.path,
apiEditor.games,
apiEditor.scenes,
apiEditor.cameras,
apiEditor.composers,
apiEditor.viewports,
apiEditor.renderers,
apiEditor.renderTargets,
apiEditor.systems,
apiEditor.entityManager,
apiEditor.allSelected, apiEditor.allSelected,
apiEditor.selectedObjects, apiEditor.selectedObjects,
apiEditor.viewports,
apiEditor.parentEntity apiEditor.parentEntity
); );
if (this.game) { this.imageFactory = new GameLib.D3.ImageFactory(
if (this.game instanceof GameLib.D3.API.Game) { this.graphics,
this.game = new GameLib.D3.Game( this.baseUrl + this.path
this.graphics, );
this.game
)
}
else {
console.warn('Game not of type API.Game');
throw new Error('Game not of type API.Game');
}
}
this.viewports = this.viewports.map(
function(apiViewport) {
if (this.games) {
this.games = this.games.map(
function (apiGame) {
if (apiGame instanceof GameLib.D3.API.Game) {
return new GameLib.D3.Game(
this.graphics,
apiGame
)
}
else {
console.warn('game not of type API.Game');
throw new Error('game not of type API.Game');
}
}.bind(this)
)
}
this.scenes = this.scenes.map(
function (apiScene) {
if (apiScene instanceof GameLib.D3.API.Scene) {
return new GameLib.D3.Scene(
this.graphics,
apiScene,
this.imageFactory,
true
)
} else {
console.warn('apiScene not of type API.Scene');
throw new Error('apiScene not of type API.Scene');
}
}.bind(this)
);
this.cameras = this.cameras.map(
function (apiCamera) {
if (apiCamera instanceof GameLib.D3.API.Camera) {
return new GameLib.D3.Camera(
this.graphics,
apiCamera
)
} else {
console.warn('apiCamera not of type API.Camera');
throw new Error('apiCamera not of type API.Camera');
}
}.bind(this)
);
this.composers = this.composers.map(
function (apiComposer) {
if (apiComposer instanceof GameLib.D3.API.Composer) {
return new GameLib.D3.Composer(
this.graphics,
apiComposer
)
} else {
console.warn('apiComposer not of type API.Composer');
throw new Error('apiComposer not of type API.Composer');
}
}.bind(this)
);
this.viewports = this.viewports.map(
function (apiViewport) {
if (apiViewport instanceof GameLib.D3.API.Viewport) { if (apiViewport instanceof GameLib.D3.API.Viewport) {
return GameLib.D3.Viewport( return GameLib.D3.Viewport(
this.graphics, this.graphics,
apiViewport apiViewport
) )
} else { } else {
console.warn('Viewport not of type API.Viewport'); console.warn('apiViewport not of type API.Viewport');
throw new Error('Viewport not of type API.Viewport'); throw new Error('apiViewport not of type API.Viewport');
} }
}.bind(this) }.bind(this)
); );
this.renderers = this.renderers.map(
function (apiRenderer) {
if (apiRenderer instanceof GameLib.D3.API.Renderer) {
return GameLib.D3.Renderer(
this.graphics,
apiRenderer
)
} else {
console.warn('apiRenderer not of type API.Renderer');
throw new Error('apiRenderer not of type API.Renderer');
}
}.bind(this)
);
this.renderTargets = this.renderTargets.map(
function (apiRenderTarget) {
if (apiRenderTarget instanceof GameLib.D3.API.RenderTarget) {
return GameLib.D3.RenderTarget(
this.graphics,
apiRenderTarget
)
} else {
console.warn('apiRenderTarget not of type API.RenderTarget');
throw new Error('apiRenderTarget not of type API.RenderTarget');
}
}.bind(this)
);
this.systems = this.systems.map(
function (apiSystem) {
if (apiSystem instanceof GameLib.D3.API.System) {
return GameLib.D3.System(
this.graphics,
apiSystem
)
} else {
console.warn('apiSystem not of type API.System');
throw new Error('apiSystem not of type API.System');
}
}.bind(this)
);
if (this.entityManager) {
if (this.entityManager instanceof GameLib.API.EntityManager) {
this.entityManager = new GameLib.EntityManager(
this.graphics,
this.entityManager
);
} else {
console.warn('entityManager not of type API.EntityManager');
throw new Error('entityManager not of type API.EntityManager');
}
}
if (GameLib.Utils.UndefinedOrNull(onSelectionChanged)) { if (GameLib.Utils.UndefinedOrNull(onSelectionChanged)) {
onSelectionChanged = null; onSelectionChanged = null;
} }
@ -113,37 +227,145 @@ GameLib.D3.Editor.prototype.updateInstance = function() {
*/ */
GameLib.D3.Editor.prototype.toApiEditor = function() { GameLib.D3.Editor.prototype.toApiEditor = function() {
var apiGame = null; var apiGames = [];
if (this.game) { var apiScenes = [];
if (this.game instanceof GameLib.D3.Game) { var apiCameras = [];
apiGame = this.game.toApiGame(); var apiComposers = [];
} else { var apiViewports = [];
console.warn('Game not an instance of Game'); var apiRenderers = [];
throw new Error('Game not an instance of Game'); var apiRenderTargets = [];
var apiSystems = [];
var apiEntityManager = null;
if (this.games) {
apiGames = this.games.map(
function(game) {
if (game instanceof GameLib.D3.Game) {
return game.toApiGame();
} else {
console.warn('game not an instance of Game');
throw new Error('game not an instance of Game');
}
}
);
}
if (this.scenes) {
apiScenes = this.scenes.map(
function(scene) {
if (scene instanceof GameLib.D3.Scene) {
return scene.toApiScene();
} else {
console.warn('scene not an instance of Scene');
throw new Error('scene not an instance of Scene');
}
}
);
}
if (this.cameras) {
apiCameras = this.cameras.map(
function(camera) {
if (camera instanceof GameLib.D3.Camera) {
return camera.toApiCamera();
} else {
console.warn('camera not an instance of Camera');
throw new Error('camera not an instance of Camera');
}
}
);
}
if (this.composers) {
apiComposers = this.composers.map(
function(composer) {
if (composer instanceof GameLib.D3.Composer) {
return composer.toApiComponent();
} else {
console.warn('composer not an instance of Composer');
throw new Error('composer not an instance of Composer');
}
}
);
}
if (this.viewports) {
apiViewports = this.viewports.map(
function(viewport) {
if (viewport instanceof GameLib.D3.Viewport) {
return viewport.toApiComponent();
} else {
console.warn('viewport not an instance of Viewport');
throw new Error('viewport not an instance of Viewport');
}
}
);
}
if (this.renderers) {
apiRenderers = this.renderers.map(
function(renderer) {
if (renderer instanceof GameLib.D3.Renderer) {
return renderer.toApiComponent();
} else {
console.warn('renderer not an instance of Renderer');
throw new Error('renderer not an instance of Renderer');
}
}
);
}
if (this.renderTargets) {
apiRenderTargets = this.renderTargets.map(
function(renderTarget) {
if (renderTarget instanceof GameLib.D3.RenderTarget) {
return renderTarget.toApiComponent();
} else {
console.warn('renderTarget not an instance of RenderTarget');
throw new Error('renderTarget not an instance of RenderTarget');
}
}
);
}
if (this.systems) {
apiSystems = this.systems.map(
function(system) {
if (system instanceof GameLib.System) {
return system.toApiComponent();
} else {
console.warn('system not an instance of System');
throw new Error('system not an instance of System');
}
}
);
}
if (this.entityManager) {
if (this.entityManager instanceof GameLib.EntityManager) {
apiEntityManager = this.entityManager.toApiEntityManager();
} else {
console.warn('entityManager not an instance of EntityManager');
throw new Error('entityManager not an instance of EntityManager');
} }
} }
var apiViewports = [];
if (this.viewports) {
apiViewports = this.viewports.map(
function(viewport) {
if (viewport instanceof GameLib.D3.Viewport) {
return viewport.toApiComponent();
} else {
console.warn('Viewport not an instance of Viewport');
throw new Error('Viewport not an instance of Viewport');
}
}
);
}
return new GameLib.D3.API.Editor( return new GameLib.D3.API.Editor(
this.id, this.id,
this.name, this.name,
apiGame, this.baseUrl,
this.path,
apiGames,
apiScenes,
apiCameras,
apiComposers,
apiViewports,
apiRenderers,
apiRenderTargets,
apiSystems,
apiEntityManager,
this.allSelected, this.allSelected,
this.selectedObjects, this.selectedObjects,
apiViewports,
GameLib.Utils.IdOrNull(this.parentEntity) GameLib.Utils.IdOrNull(this.parentEntity)
); );

View File

@ -2,7 +2,7 @@
* Game Runtime * Game Runtime
* @param graphics GameLib.D3.Graphics * @param graphics GameLib.D3.Graphics
* @param apiGame GameLib.D3.API.Game * @param apiGame GameLib.D3.API.Game
* @param imageFactory * @param imageFactory GameLib.D3.ImageFactory
* @constructor * @constructor
*/ */
GameLib.D3.Game = function ( GameLib.D3.Game = function (
@ -22,136 +22,124 @@ GameLib.D3.Game = function (
this, this,
apiGame.id, apiGame.id,
apiGame.name, apiGame.name,
apiGame.baseUrl, apiGame.baseUrl,
apiGame.path, apiGame.path,
apiGame.gameType, apiGame.gameType,
apiGame.width, apiGame.width,
apiGame.height, apiGame.height,
apiGame.scenes,
apiGame.cameras, apiGame.cameras,
apiGame.renderers,
apiGame.composers, apiGame.composers,
apiGame.systems,
apiGame.viewports, apiGame.viewports,
apiGame.renderers,
apiGame.renderTargets,
apiGame.systems,
apiGame.entityManager, apiGame.entityManager,
apiGame.mouse, apiGame.mouse,
apiGame.parentEntity apiGame.parentEntity
); );
if (GameLib.Utils.UndefinedOrNull(imageFactory)) { if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
imageFactory = GameLib.D3.ImageFactory( imageFactory = GameLib.D3.ImageFactory(
this.graphics, this.graphics,
this.baseUrl this.baseUrl + this.path
); );
} }
this.imageFactory = imageFactory; this.imageFactory = imageFactory;
this.scenes = this.scenes.map( this.cameras = this.cameras.map(
function(apiScene) { function (apiCamera) {
if (apiCamera instanceof GameLib.D3.API.Camera) {
if (apiScene instanceof GameLib.D3.API.Scene) { return new GameLib.D3.Camera(
return new GameLib.D3.Scene( this.graphics,
this.graphics, apiCamera
apiScene, )
this.imageFactory, } else {
true console.warn('apiCamera not of type API.Camera');
) throw new Error('apiCamera not of type API.Camera');
} else { }
console.warn('Scene not of type API.Scene');
throw new Error('Scene not of type API.Scene');
}
}.bind(this) }.bind(this)
); );
this.cameras = this.cameras.map( this.composers = this.composers.map(
function(apiCamera) { function (apiComposer) {
if (apiComposer instanceof GameLib.D3.API.Composer) {
return new GameLib.D3.Composer(
this.graphics,
apiComposer
)
} else {
console.warn('apiComposer not of type API.Composer');
throw new Error('apiComposer not of type API.Composer');
}
}.bind(this)
);
if (apiCamera instanceof GameLib.D3.API.Camera) { this.viewports = this.viewports.map(
return new GameLib.D3.Camera( function (apiViewport) {
this.graphics, if (apiViewport instanceof GameLib.D3.API.Viewport) {
apiCamera return GameLib.D3.Viewport(
) this.graphics,
} else { apiViewport
console.warn('Camera not of type API.Camera'); )
throw new Error('Camera not of type API.Camera'); } else {
} console.warn('apiViewport not of type API.Viewport');
throw new Error('apiViewport not of type API.Viewport');
}
}.bind(this)
);
}.bind(this) this.renderers = this.renderers.map(
); function (apiRenderer) {
if (apiRenderer instanceof GameLib.D3.API.Renderer) {
return GameLib.D3.Renderer(
this.graphics,
apiRenderer
)
} else {
console.warn('apiRenderer not of type API.Renderer');
throw new Error('apiRenderer not of type API.Renderer');
}
}.bind(this)
);
this.renderers = this.renderers.map( this.renderTargets = this.renderTargets.map(
function(apiRenderer) { function (apiRenderTarget) {
if (apiRenderTarget instanceof GameLib.D3.API.RenderTarget) {
return GameLib.D3.RenderTarget(
this.graphics,
apiRenderTarget
)
} else {
console.warn('apiRenderTarget not of type API.RenderTarget');
throw new Error('apiRenderTarget not of type API.RenderTarget');
}
}.bind(this)
);
if (apiRenderer instanceof GameLib.D3.API.Renderer) { this.systems = this.systems.map(
return new GameLib.D3.Renderer( function (apiSystem) {
this.graphics, if (apiSystem instanceof GameLib.D3.API.System) {
apiRenderer return GameLib.D3.System(
) this.graphics,
} else { apiSystem
console.warn('Renderer not of type API.Renderer'); )
throw new Error('Renderer not of type API.Renderer'); } else {
} console.warn('apiSystem not of type API.System');
throw new Error('apiSystem not of type API.System');
}
}.bind(this)
);
}.bind(this) if (this.entityManager) {
); if (this.entityManager instanceof GameLib.API.EntityManager) {
this.entityManager = new GameLib.EntityManager(
this.composers = this.composers.map( this.graphics,
function(apiComposer) { this.entityManager
);
if (apiComposer instanceof GameLib.D3.API.Composer) { } else {
return new GameLib.D3.Composer( console.warn('entityManager not of type API.EntityManager');
this.graphics, throw new Error('entityManager not of type API.EntityManager');
apiComposer }
)
} else {
console.warn('Composer not of type API.Composer');
throw new Error('Composer not of type API.Composer');
}
}.bind(this)
);
this.systems = this.systems.map(
function(apiSystem) {
if (apiSystem instanceof GameLib.D3.API.System) {
return new GameLib.D3.System(
this.graphics,
apiSystem
)
} else {
console.warn('System not of type API.System');
throw new Error('System not of type API.System');
}
}.bind(this)
);
this.viewports = this.viewports.map(
function(apiViewport) {
if (apiViewport instanceof GameLib.D3.API.Viewport) {
return new GameLib.D3.Viewport(
this.graphics,
apiViewport
)
} else {
console.warn('Viewport not of type API.Viewport');
throw new Error('Viewport not of type API.Viewport');
}
}.bind(this)
);
if (this.entityManager instanceof GameLib.API.EntityManager) {
this.entityManager = new GameLib.EntityManager(
this.graphics,
this.entityManager
);
} else {
console.warn('EntityManager not of type API.EntityManager');
throw new Error('EntityManager not of type API.EntityManager');
} }
if (this.mouse instanceof GameLib.API.Mouse) { if (this.mouse instanceof GameLib.API.Mouse) {
@ -226,101 +214,102 @@ GameLib.D3.Game.prototype.updateInstance = function() {
*/ */
GameLib.D3.Game.prototype.toApiGame = function() { GameLib.D3.Game.prototype.toApiGame = function() {
var apiScenes = []; var apiCameras = [];
if (this.scenes) { var apiComposers = [];
apiScenes = this.scenes.map( var apiViewports = [];
function(scene) { var apiRenderers = [];
if (scene instanceof GameLib.D3.Scene) { var apiRenderTargets = [];
return scene.toApiScene(); var apiSystems = [];
} else { var apiEntityManager = null;
console.warn('Scene not an instance of Scene'); var apiMouse = null;
throw new Error('Scene not an instance of Scene');
}
}
);
}
var apiCameras = []; if (this.cameras) {
if (this.cameras) { apiCameras = this.cameras.map(
apiCameras = this.cameras.map( function(camera) {
function(camera) { if (camera instanceof GameLib.D3.Camera) {
if (camera instanceof GameLib.D3.Camera) { return camera.toApiCamera();
return camera.toApiCamera(); } else {
} else { console.warn('camera not an instance of Camera');
console.warn('Camera not an instance of Camera'); throw new Error('camera not an instance of Camera');
throw new Error('Camera not an instance of Camera'); }
} }
} );
); }
}
var apiRenderers = []; if (this.composers) {
if (this.renderers) { apiComposers = this.composers.map(
apiRenderers = this.renderers.map( function(composer) {
function(renderer) { if (composer instanceof GameLib.D3.Composer) {
if (renderer instanceof GameLib.D3.Renderer) { return composer.toApiComponent();
return renderer.toApiRenderer(); } else {
} else { console.warn('composer not an instance of Composer');
console.warn('Renderer not an instance of Renderer'); throw new Error('composer not an instance of Composer');
throw new Error('Renderer not an instance of Renderer'); }
} }
} );
); }
}
var apiComposers = []; if (this.viewports) {
if (this.composers) { apiViewports = this.viewports.map(
apiComposers = this.composers.map( function(viewport) {
function(composer) { if (viewport instanceof GameLib.D3.Viewport) {
if (composer instanceof GameLib.D3.Composer) { return viewport.toApiComponent();
return composer.toApiComposer(); } else {
} else { console.warn('viewport not an instance of Viewport');
console.warn('Composer not an instance of Composer'); throw new Error('viewport not an instance of Viewport');
throw new Error('Composer not an instance of Composer'); }
} }
} );
); }
}
var apiSystems = []; if (this.renderers) {
if (this.systems) { apiRenderers = this.renderers.map(
apiSystems = this.systems.map( function(renderer) {
function(system) { if (renderer instanceof GameLib.D3.Renderer) {
if (system instanceof GameLib.System) { return renderer.toApiComponent();
return system.toApiSystem(); } else {
} else { console.warn('renderer not an instance of Renderer');
console.warn('System not an instance of System'); throw new Error('renderer not an instance of Renderer');
throw new Error('System not an instance of System'); }
} }
} );
); }
}
var apiViewports = []; if (this.renderTargets) {
if (this.viewports) { apiRenderTargets = this.renderTargets.map(
apiViewports = this.viewports.map( function(renderTarget) {
function(viewport) { if (renderTarget instanceof GameLib.D3.RenderTarget) {
if (viewport instanceof GameLib.D3.Viewport) { return renderTarget.toApiComponent();
return viewport.toApiViewport(); } else {
} else { console.warn('renderTarget not an instance of RenderTarget');
console.warn('Viewport not an instance of Viewport'); throw new Error('renderTarget not an instance of RenderTarget');
throw new Error('Viewport not an instance of Viewport'); }
} }
} );
); }
}
var apiEntityManager = null; if (this.systems) {
if (this.entityManager) { apiSystems = this.systems.map(
if (this.entityManager instanceof GameLib.EntityManager) { function(system) {
apiEntityManager = this.entityManager.toApiEntityManager(); if (system instanceof GameLib.System) {
} else { return system.toApiComponent();
console.warn('EntityManager not an instance of EntityManager'); } else {
throw new Error('EntityManager not an instance of EntityManager'); console.warn('system not an instance of System');
} throw new Error('system not an instance of System');
} }
}
);
}
if (this.entityManager) {
if (this.entityManager instanceof GameLib.EntityManager) {
apiEntityManager = this.entityManager.toApiEntityManager();
} else {
console.warn('entityManager not an instance of EntityManager');
throw new Error('entityManager not an instance of EntityManager');
}
}
var apiMouse = null;
if (this.mouse) { if (this.mouse) {
if (this.mouse instanceof GameLib.Mouse) { if (this.mouse instanceof GameLib.Mouse) {
apiMouse = this.mouse.toApiMouse(); apiMouse = this.mouse.toApiMouse();
@ -338,12 +327,12 @@ GameLib.D3.Game.prototype.toApiGame = function() {
this.gameType, this.gameType,
this.width, this.width,
this.height, this.height,
apiScenes,
apiCameras, apiCameras,
apiRenderers,
apiComposers, apiComposers,
apiSystems,
apiViewports, apiViewports,
apiRenderers,
apiRenderTargets,
apiSystems,
apiEntityManager, apiEntityManager,
apiMouse, apiMouse,
GameLib.Utils.IdOrNull(this.parentEntity) GameLib.Utils.IdOrNull(this.parentEntity)

View File

@ -221,22 +221,16 @@ GameLib.D3.Input.Editor.prototype.onKeyPress = function(event) {
this.editor.selectedObjects = []; this.editor.selectedObjects = [];
if (this.editor.allSelected) { if (this.editor.allSelected) {
this.editor.games.map( for (var property in this.editor.idToObject) {
function(game) { if (this.editor.idToObject.hasOwnProperty(property)) {
this.editor.selectedObjects.push(
for (var property in game.idToObject) { new GameLib.D3.SelectedObject(
if (game.idToObject.hasOwnProperty(property)) { this.graphics,
this.editor.selectedObjects.push( this.editor.idToObject(property)
new GameLib.D3.SelectedObject( )
this.graphics, )
game.idToObject(property) }
) }
)
}
}
}.bind(this)
);
} }
if (this.editor.onSelectionChanged) { if (this.editor.onSelectionChanged) {
@ -310,18 +304,15 @@ GameLib.D3.Input.Editor.prototype.onMouseDown = function(event) {
event.stopPropagation(); event.stopPropagation();
} }
var meshCollections = this.editor.game.scenes.map( var meshes = [];
function(scene) {
return scene.meshes;
}
);
var meshes = meshCollections.reduce( for (var property in this.editor.idToObject) {
function(result, meshCollection) { if (this.editor.idToObject.hasOwnProperty(property)) {
return result.concat(meshCollection); if (this.editor.idToObject[property] instanceof GameLib.D3.Mesh) {
}, meshes.push(this.editor.idToObject[property]);
[] }
); }
}
var intersects = this.raycaster.getIntersectedObjects(meshes); var intersects = this.raycaster.getIntersectedObjects(meshes);

View File

@ -21,9 +21,10 @@ GameLib.D3.Material = function Material(
} }
if (GameLib.Utils.UndefinedOrNull(imageFactory)) { if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
console.warn('Cannot create a material without specifying an ImageFactory'); console.warn('Cannot create a Material fully without specifying an ImageFactory');
throw new Error('Cannot create a material without specifying an ImageFactory'); imageFactory = null;
} }
this.imageFactory = imageFactory;
GameLib.D3.API.Material.call( GameLib.D3.API.Material.call(
this, this,
@ -121,7 +122,7 @@ GameLib.D3.Material = function Material(
this.alphaMap = new GameLib.D3.Texture( this.alphaMap = new GameLib.D3.Texture(
this.graphics, this.graphics,
this.alphaMap, this.alphaMap,
imageFactory this.imageFactory
); );
} else { } else {
console.warn('this.alphaMap is not an instance of API.Texture'); console.warn('this.alphaMap is not an instance of API.Texture');
@ -134,7 +135,7 @@ GameLib.D3.Material = function Material(
this.aoMap = new GameLib.D3.Texture( this.aoMap = new GameLib.D3.Texture(
this.graphics, this.graphics,
this.aoMap, this.aoMap,
imageFactory this.imageFactory
); );
} else { } else {
console.warn('this.aoMap is not an instance of API.Texture'); console.warn('this.aoMap is not an instance of API.Texture');
@ -147,7 +148,7 @@ GameLib.D3.Material = function Material(
this.bumpMap = new GameLib.D3.Texture( this.bumpMap = new GameLib.D3.Texture(
this.graphics, this.graphics,
this.bumpMap, this.bumpMap,
imageFactory this.imageFactory
); );
} else { } else {
console.warn('this.bumpMap is not an instance of API.Texture'); console.warn('this.bumpMap is not an instance of API.Texture');
@ -160,7 +161,7 @@ GameLib.D3.Material = function Material(
this.diffuseMap = new GameLib.D3.Texture( this.diffuseMap = new GameLib.D3.Texture(
this.graphics, this.graphics,
this.diffuseMap, this.diffuseMap,
imageFactory this.imageFactory
); );
} else { } else {
console.warn('this.diffuseMap is not an instance of API.Texture'); console.warn('this.diffuseMap is not an instance of API.Texture');
@ -173,7 +174,7 @@ GameLib.D3.Material = function Material(
this.displacementMap = new GameLib.D3.Texture( this.displacementMap = new GameLib.D3.Texture(
this.graphics, this.graphics,
this.displacementMap, this.displacementMap,
imageFactory this.imageFactory
); );
} else { } else {
console.warn('this.displacementMap is not an instance of API.Texture'); console.warn('this.displacementMap is not an instance of API.Texture');
@ -186,7 +187,7 @@ GameLib.D3.Material = function Material(
this.emissiveMap = new GameLib.D3.Texture( this.emissiveMap = new GameLib.D3.Texture(
this.graphics, this.graphics,
this.emissiveMap, this.emissiveMap,
imageFactory this.imageFactory
); );
} else { } else {
console.warn('this.emissiveMap is not an instance of API.Texture'); console.warn('this.emissiveMap is not an instance of API.Texture');
@ -199,7 +200,7 @@ GameLib.D3.Material = function Material(
this.environmentMap = new GameLib.D3.Texture( this.environmentMap = new GameLib.D3.Texture(
this.graphics, this.graphics,
this.environmentMap, this.environmentMap,
imageFactory this.imageFactory
); );
} else { } else {
console.warn('this.environmentMap is not an instance of API.Texture'); console.warn('this.environmentMap is not an instance of API.Texture');
@ -212,7 +213,7 @@ GameLib.D3.Material = function Material(
this.lightMap = new GameLib.D3.Texture( this.lightMap = new GameLib.D3.Texture(
this.graphics, this.graphics,
this.lightMap, this.lightMap,
imageFactory this.imageFactory
); );
} else { } else {
console.warn('this.lightMap is not an instance of API.Texture'); console.warn('this.lightMap is not an instance of API.Texture');
@ -225,7 +226,7 @@ GameLib.D3.Material = function Material(
this.metalnessMap = new GameLib.D3.Texture( this.metalnessMap = new GameLib.D3.Texture(
this.graphics, this.graphics,
this.metalnessMap, this.metalnessMap,
imageFactory this.imageFactory
); );
} else { } else {
console.warn('this.metalnessMap is not an instance of API.Texture'); console.warn('this.metalnessMap is not an instance of API.Texture');
@ -238,7 +239,7 @@ GameLib.D3.Material = function Material(
this.normalMap = new GameLib.D3.Texture( this.normalMap = new GameLib.D3.Texture(
this.graphics, this.graphics,
this.normalMap, this.normalMap,
imageFactory this.imageFactory
); );
} else { } else {
console.warn('this.normalMap is not an instance of API.Texture'); console.warn('this.normalMap is not an instance of API.Texture');
@ -251,7 +252,7 @@ GameLib.D3.Material = function Material(
this.roughnessMap = new GameLib.D3.Texture( this.roughnessMap = new GameLib.D3.Texture(
this.graphics, this.graphics,
this.roughnessMap, this.roughnessMap,
imageFactory this.imageFactory
); );
} else { } else {
console.warn('this.roughnessMap is not an instance of API.Texture'); console.warn('this.roughnessMap is not an instance of API.Texture');
@ -264,7 +265,7 @@ GameLib.D3.Material = function Material(
this.specularMap = new GameLib.D3.Texture( this.specularMap = new GameLib.D3.Texture(
this.graphics, this.graphics,
this.specularMap, this.specularMap,
imageFactory this.imageFactory
); );
} else { } else {
console.warn('this.specularMap is not an instance of API.Texture'); console.warn('this.specularMap is not an instance of API.Texture');

View File

@ -1,16 +1,16 @@
/** /**
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created * Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
* @param graphics GameLib.D3.Graphics * @param graphics GameLib.D3.Graphics
* @param computeNormals Boolean
* @param apiMesh GameLib.D3.API.Mesh * @param apiMesh GameLib.D3.API.Mesh
* @param imageFactory GameLib.D3.ImageFactory * @param imageFactory GameLib.D3.ImageFactory
* @param computeNormals Boolean
* @constructor * @constructor
*/ */
GameLib.D3.Mesh = function ( GameLib.D3.Mesh = function (
graphics, graphics,
apiMesh, apiMesh,
computeNormals, imageFactory,
imageFactory computeNormals
) { ) {
this.graphics = graphics; this.graphics = graphics;
this.graphics.isNotThreeThrow(); this.graphics.isNotThreeThrow();
@ -25,9 +25,10 @@ GameLib.D3.Mesh = function (
this.computeNormals = computeNormals; this.computeNormals = computeNormals;
if (GameLib.Utils.UndefinedOrNull(imageFactory)) { if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
console.warn('Cannot create a Mesh without specifying an ImageFactory'); console.warn('Cannot create Meshes fully without specifying an ImageFactory for downloading Textures');
throw new Error('Cannot create a Mesh without specifying an ImageFactory'); imageFactory = null;
} }
this.imageFactory = imageFactory;
GameLib.D3.API.Mesh.call( GameLib.D3.API.Mesh.call(
this, this,
@ -62,7 +63,7 @@ GameLib.D3.Mesh = function (
return new GameLib.D3.Material( return new GameLib.D3.Material(
this.graphics, this.graphics,
apiMaterial, apiMaterial,
imageFactory this.imageFactory
) )
} else { } else {
console.warn('API material not of instance API.Material'); console.warn('API material not of instance API.Material');
@ -77,7 +78,6 @@ GameLib.D3.Mesh = function (
this.graphics, this.graphics,
this.skeleton this.skeleton
); );
} }
this.vertices = this.vertices.map( this.vertices = this.vertices.map(

View File

@ -41,12 +41,11 @@ GameLib.D3.Scene = function (
); );
if (GameLib.Utils.UndefinedOrNull(imageFactory)) { if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
console.warn('Cannot create a Scene without specifying an ImageFactory'); console.warn('Creating a scene without an ImageFactory');
throw new Error('Cannot create a Scene without specifying an ImageFactory'); imageFactory = null;
} }
this.imageFactory = imageFactory; this.imageFactory = imageFactory;
this.meshes = this.meshes.map( this.meshes = this.meshes.map(
function(apiMesh) { function(apiMesh) {
@ -173,16 +172,16 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
* Converts a scene Object to a GameLib.D3.Scene object * Converts a scene Object to a GameLib.D3.Scene object
* @param graphics GameLib.D3.Graphics * @param graphics GameLib.D3.Graphics
* @param objectScene Object * @param objectScene Object
* @param computeNormals boolean to indicate whether or not to recalculate normals
* @param imageFactory GameLib.D3.ImageFactory * @param imageFactory GameLib.D3.ImageFactory
* @param computeNormals boolean to indicate whether or not to recalculate normals
* @returns {GameLib.D3.Scene} * @returns {GameLib.D3.Scene}
* @constructor * @constructor
*/ */
GameLib.D3.Scene.FromObjectScene = function( GameLib.D3.Scene.FromObjectScene = function(
graphics, graphics,
objectScene, objectScene,
computeNormals, imageFactory,
imageFactory computeNormals
) { ) {
var apiScene = GameLib.D3.API.Scene.FromObjectScene(objectScene); var apiScene = GameLib.D3.API.Scene.FromObjectScene(objectScene);
@ -214,8 +213,8 @@ GameLib.D3.Scene.LoadScene = function(
var scene = GameLib.D3.Scene.FromObjectScene( var scene = GameLib.D3.Scene.FromObjectScene(
graphics, graphics,
objectScene, objectScene,
computeNormals, imageFactory,
imageFactory computeNormals
); );
onLoaded(scene); onLoaded(scene);

View File

@ -3,14 +3,12 @@
* created * created
* @param apiTexture * @param apiTexture
* @param graphics GameLib.D3.Graphics * @param graphics GameLib.D3.Graphics
* @param imageFactory GameLib.D3.ImageFactory result * @param imageFactory GameLib.D3.ImageFactory
* @constructor * @constructor
*/ */
GameLib.D3.Texture = function Texture( GameLib.D3.Texture = function Texture(
graphics, graphics,
apiTexture, apiTexture,
// parentMaterial,
// parentMaterialInstanceMapId,
imageFactory imageFactory
) { ) {
this.graphics = graphics; this.graphics = graphics;
@ -21,9 +19,10 @@ GameLib.D3.Texture = function Texture(
} }
if (GameLib.Utils.UndefinedOrNull(imageFactory)) { if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
console.warn('Cannot create a material without specifying an ImageFactory'); console.warn('Cannot create a Texture without specifying an ImageFactory');
throw new Error('Cannot create a material without specifying an ImageFactory'); imageFactory = null;
} }
this.imageFactory = imageFactory;
GameLib.D3.API.Texture.call( GameLib.D3.API.Texture.call(
this, this,
@ -63,15 +62,11 @@ GameLib.D3.Texture = function Texture(
this this
); );
// this.parentMaterial = parentMaterial;
//
// this.parentMaterialInstanceMapId = parentMaterialInstanceMapId;
this.imageInstance = null; this.imageInstance = null;
this.instance = null; this.instance = null;
this.loadTexture(imageFactory); this.loadTexture();
}; };
GameLib.D3.Texture.prototype = Object.create(GameLib.D3.API.Texture.prototype); GameLib.D3.Texture.prototype = Object.create(GameLib.D3.API.Texture.prototype);
@ -79,18 +74,15 @@ GameLib.D3.Texture.prototype.constructor = GameLib.D3.Texture;
/** /**
* Loads a texture from the image factory, it could already have downloaded, and then it updates the instance * Loads a texture from the image factory, it could already have downloaded, and then it updates the instance
* @param imageFactory
*/ */
GameLib.D3.Texture.prototype.loadTexture = function(imageFactory) { GameLib.D3.Texture.prototype.loadTexture = function() {
this.imageData = imageFactory(this.imagePath); this.imageData = this.imageFactory(this.imagePath);
this.imageData.then( this.imageData.then(
function (imageInstance){ function (imageInstance){
this.imageInstance = imageInstance; this.imageInstance = imageInstance;
this.instance = this.createInstance(); this.instance = this.createInstance();
// this.parentMaterial.instance[this.parentMaterialInstanceMapId] = this.instance;
// this.parentMaterial.instance.needsUpdate = true;
}.bind(this), }.bind(this),
function onRejected() { function onRejected() {
} }
@ -221,12 +213,6 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
instance.premultiplyAlpha = this.premultiplyAlpha; instance.premultiplyAlpha = this.premultiplyAlpha;
instance.textureType = this.textureType; instance.textureType = this.textureType;
// if (this.parentMaterial &&
// this.parentMaterial.instance &&
// this.parentMaterialInstanceMapId) {
// this.parentMaterial.instance[this.parentMaterialInstanceMapId] = instance;
// }
instance.needsUpdate = true; instance.needsUpdate = true;
return instance; return instance;
@ -290,8 +276,6 @@ GameLib.D3.Texture.prototype.toApiTexture = function() {
GameLib.D3.Texture.FromObjectTexture = function( GameLib.D3.Texture.FromObjectTexture = function(
graphics, graphics,
objectTexture, objectTexture,
// gameLibMaterial,
// instanceMapId,
imageFactory imageFactory
) { ) {
var apiTexture = GameLib.D3.API.Texture.FromObjectTexture(objectTexture); var apiTexture = GameLib.D3.API.Texture.FromObjectTexture(objectTexture);

View File

@ -0,0 +1,71 @@
/**
* Runtime domElement for updating instance objects
* @param graphics GameLib.D3.Graphics
* @param apiDomElement GameLib.API.DomElement
* @constructor
*/
GameLib.DomElement = function (graphics, apiDomElement) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
GameLib.API.DomElement.call(
this,
apiDomElement.id,
apiDomElement.name,
apiDomElement.domElementId,
apiDomElement.parentEntity
);
this.instance = this.createInstance();
};
GameLib.DomElement.prototype = Object.create(GameLib.API.DomElement.prototype);
GameLib.DomElement.prototype.constructor = GameLib.DomElement;
/**
* Creates an instance domElement
* @param update
* @returns {*}
*/
GameLib.DomElement.prototype.createInstance = function(update) {
var instance = document.getElementById(this.domElementId);
return instance;
};
/**
* Updates the instance vector, calls updateInstance on the parent object
*/
GameLib.DomElement.prototype.updateInstance = function() {
this.createInstance(true);
};
/**
* Converts runtime vector to API Vector
* @returns {GameLib.API.DomElement}
*/
GameLib.DomElement.prototype.toApiDomElement = function() {
return new GameLib.API.DomElement(
this.id,
this.name,
this.domElementId,
this.parentEntity
);
};
/**
* Appends domInstance to DOM instance
* @param domInstance
*/
GameLib.DomElement.prototype.append = function(domInstance) {
this.instance.appendChild(domInstance);
};
/**
* Clears DOM instance
*/
GameLib.DomElement.prototype.clear = function() {
this.instance.innerHTML = '';
};

View File

@ -1,34 +1,32 @@
/** /**
* System takes care of updating all the entities (based on their component data) * System takes care of updating all the entities (based on their component data)
* @param graphics
* @param apiSystem GameLib.API.System * @param apiSystem GameLib.API.System
* @param domElement
* @param domStats
* @constructor * @constructor
*/ */
GameLib.System = function( GameLib.System = function(
apiSystem, graphics,
domElement, apiSystem
domStats
) { ) {
GameLib.API.System.call( this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiSystem)) {
apiSystem = {};
}
GameLib.API.System.call(
this, this,
apiSystem.id, apiSystem.id,
apiSystem.name, apiSystem.name,
apiSystem.systemType, apiSystem.systemType,
apiSystem.entityManager, apiSystem.entityManager,
apiSystem.domElement,
apiSystem.domStats,
apiSystem.parentEntity apiSystem.parentEntity
); );
if (GameLib.Utils.UndefinedOrNull(domElement)){
domElement = null;
}
this.domElement = domElement;
if (GameLib.Utils.UndefinedOrNull(domStats)){
domStats = null;
}
this.domStats = domStats;
}; };
@ -174,3 +172,20 @@ GameLib.System.prototype.stop = function() {
} }
}; };
/**
* Converts runtime vector to API Vector
* @returns {GameLib.API.Mouse}
*/
GameLib.System.prototype.toApiSystem = function() {
//TODO
return new GameLib.API.System(
this.id,
this.name,
this.systemType,
this.domElement.toApiDo,
this.domStats,
GameLib.Utils.IdOrNull(this.parentEntity)
);
};