component refactoring nearing completion

beta.r3js.org
-=yb4f310 2017-12-04 21:04:24 +01:00
parent 8068dcf3ef
commit 6586de1757
12 changed files with 223 additions and 141 deletions

24
build/game-lib-min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
// COMPILE TIME DEFINITIONS (Generated via gulp) // COMPILE TIME DEFINITIONS (Generated via gulp)
var __DATE__ = "Mon Dec 04 2017 14:10:07 GMT+0100 (CET)"; var __DATE__ = "Mon Dec 04 2017 21:03:18 GMT+0100 (CET)";
// END COMPILE TIME DEFINITIONS // END COMPILE TIME DEFINITIONS
/** /**
@ -111,7 +111,7 @@ GameLib.Event.COMPONENTS_LINKED = 0x1d;
GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE = 0x1e; GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE = 0x1e;
GameLib.Event.REGISTER_UPDATE = 0x1f; GameLib.Event.REGISTER_UPDATE = 0x1f;
GameLib.Event.BUILD_GUI = 0x20; GameLib.Event.BUILD_GUI = 0x20;
GameLib.Event.REMOVE_MESH = 0x21; GameLib.Event.REMOVE_MESH = 0x21;
GameLib.Event.MESH_SELECTED = 0x22; GameLib.Event.MESH_SELECTED = 0x22;
GameLib.Event.MESH_DESELECTED = 0x23; GameLib.Event.MESH_DESELECTED = 0x23;
GameLib.Event.COMPONENT_REGISTER = 0x24; GameLib.Event.COMPONENT_REGISTER = 0x24;
@ -130,7 +130,7 @@ GameLib.Event.PARENT_ENTITY_CHANGED = 0x30;
GameLib.Event.MATERIAL_TEXTURES_UPDATED = 0x31; GameLib.Event.MATERIAL_TEXTURES_UPDATED = 0x31;
GameLib.Event.DELETE_COMPONENT_ERROR = 0x32; GameLib.Event.DELETE_COMPONENT_ERROR = 0x32;
GameLib.Event.COMPONENT_DELETED = 0x33; GameLib.Event.COMPONENT_DELETED = 0x33;
GameLib.Event.COMPONENT_TYPES_UPDATED = 0x34; GameLib.Event.COMPONENT_TYPES_FETCHED = 0x34;
GameLib.Event.AUDIO_ENDED = 0x35; GameLib.Event.AUDIO_ENDED = 0x35;
GameLib.Event.COMPONENT_LINKED = 0x36; GameLib.Event.COMPONENT_LINKED = 0x36;
GameLib.Event.DONE_SAVING = 0x37; GameLib.Event.DONE_SAVING = 0x37;
@ -156,7 +156,7 @@ GameLib.Event.TOUCH_END = 0x4a;
GameLib.Event.TOUCH_MOVE = 0x4b; GameLib.Event.TOUCH_MOVE = 0x4b;
GameLib.Event.TOUCH_CANCEL = 0x4c; GameLib.Event.TOUCH_CANCEL = 0x4c;
GameLib.Event.GET_REMOTE_API_URL = 0x4d; GameLib.Event.GET_REMOTE_API_URL = 0x4d;
//GameLib.Event.GET_GRAPHICS_RUNTIME = 0x4e; GameLib.Event.COMPONENT_TYPES_UPDATE = 0x4e;
GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f; GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f;
//GameLib.Event.GET_CODER_IMPLEMENTATION = 0x50; //GameLib.Event.GET_CODER_IMPLEMENTATION = 0x50;
GameLib.Event.ANIMATION_MESH_ADDED = 0x51; GameLib.Event.ANIMATION_MESH_ADDED = 0x51;
@ -276,7 +276,7 @@ GameLib.Event.GetEventName = function(number) {
case 0x4b : return 'touch_move'; case 0x4b : return 'touch_move';
case 0x4c : return 'touch_cancel'; case 0x4c : return 'touch_cancel';
case 0x4d : return 'get_remote_api_url'; case 0x4d : return 'get_remote_api_url';
case 0x4e : return 'unused';//'get_graphics_implementation'; case 0x4e : return 'component_types_update';
case 0x4f : return 'delayed_instance_encountered'; case 0x4f : return 'delayed_instance_encountered';
case 0x50 : return 'unused';//'get_coder_implementation'; case 0x50 : return 'unused';//'get_coder_implementation';
case 0x51 : return 'animation_mesh_added'; case 0x51 : return 'animation_mesh_added';
@ -1260,18 +1260,23 @@ GameLib.Utils.UpperCaseWordsSpaces = function(word) {
).trim(); ).trim();
}; };
/**
* @return {string}
*/
GameLib.Utils.UpperCaseUnderscore = function(word) { GameLib.Utils.UpperCaseUnderscore = function(word) {
var str = ''; var str = '';
word.map(function(letter){ word.split('').map(function(letter){
if (letter === letter.toUpperCase()) { if (letter == letter.toUpperCase()) {
str += '_' + letter; str += '_' + letter;
} else { } else {
str += letter.toUpperCase(); str += letter.toUpperCase();
} }
}); });
str = str.replace(new RegExp('^_'),'');
return str; return str;
}; };
/** /**
@ -1899,49 +1904,49 @@ GameLib.Component.GetComponentInfo = function(number) {
constructor : GameLib.D3.Mesh.Cylinder constructor : GameLib.D3.Mesh.Cylinder
}; };
case 0x41 : return { case 0x41 : return {
name : 'GameLib.D3.System.Animation', name : 'GameLib.System.Animation',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Animation constructor : GameLib.System.Animation
}; };
case 0x42 : return { case 0x42 : return {
name : 'GameLib.D3.System.CustomCode', name : 'GameLib.System.CustomCode',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.CustomCode constructor : GameLib.System.CustomCode
}; };
case 0x43 : return { case 0x43 : return {
name : 'GameLib.D3.System.GUI', name : 'GameLib.System.GUI',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.GUI constructor : GameLib.System.GUI
}; };
case 0x44 : return { case 0x44 : return {
name : 'GameLib.D3.System.Input', name : 'GameLib.System.Input',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Input constructor : GameLib.System.Input
}; };
case 0x45 : return { case 0x45 : return {
name : 'GameLib.D3.System.Linking', name : 'GameLib.System.Linking',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Linking constructor : GameLib.System.Linking
}; };
case 0x46 : return { case 0x46 : return {
name : 'GameLib.D3.System.Physics', name : 'GameLib.System.Physics',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Physics constructor : GameLib.System.Physics
}; };
case 0x47 : return { case 0x47 : return {
name : 'GameLib.D3.System.Render', name : 'GameLib.System.Render',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Render constructor : GameLib.System.Render
}; };
case 0x48 : return { case 0x48 : return {
name : 'GameLib.D3.System.Storage', name : 'GameLib.System.Storage',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Storage constructor : GameLib.System.Storage
}; };
case 0x49 : return { case 0x49 : return {
name : 'GameLib.D3.System.Visualization', name : 'GameLib.System.Visualization',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Visualization constructor : GameLib.System.Visualization
}; };
case 0x50 : return { case 0x50 : return {
name : 'GameLib.D3.Fog', name : 'GameLib.D3.Fog',
@ -1959,9 +1964,9 @@ GameLib.Component.GetComponentInfo = function(number) {
constructor : GameLib.D3.ParticleEngine constructor : GameLib.D3.ParticleEngine
}; };
case 0x53 : return { case 0x53 : return {
name : 'GameLib.D3.System.Particle', name : 'GameLib.System.Particle',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Particle constructor : GameLib.System.Particle
}; };
case 0x54 : return { case 0x54 : return {
name : 'GameLib.D3.Particle', name : 'GameLib.D3.Particle',
@ -4993,7 +4998,7 @@ GameLib.CoderRuntime.prototype.updateInstance = function(property) {
* Logs a warning and throws an error if not cannon * Logs a warning and throws an error if not cannon
*/ */
GameLib.CoderRuntime.prototype.isNotCodeMirrorThrow = function() { GameLib.CoderRuntime.prototype.isNotCodeMirrorThrow = function() {
if (!(this.instance instanceof CodeMirror)) { if (this.instance !== CodeMirror) {
console.error('Only CodeMirror supported'); console.error('Only CodeMirror supported');
throw new Error('Only CodeMirror supported'); throw new Error('Only CodeMirror supported');
} }
@ -23104,6 +23109,13 @@ GameLib.EntityManager.prototype.registerComponent = function(data) {
if (GameLib.Utils.UndefinedOrNull(this.register[data.component.componentType])) { if (GameLib.Utils.UndefinedOrNull(this.register[data.component.componentType])) {
this.register[data.component.componentType] = {}; this.register[data.component.componentType] = {};
GameLib.Event.Emit(
GameLib.Event.COMPONENT_TYPES_UPDATE,
{
componentType : data.component.componentType,
componentTypes : Object.keys(this.register)
}
);
updated = true; updated = true;
} }
@ -23123,7 +23135,8 @@ GameLib.EntityManager.prototype.registerComponent = function(data) {
{ {
componentType : data.component.componentType, componentType : data.component.componentType,
components : this.register[data.component.componentType], components : this.register[data.component.componentType],
idRegister : this.idRegister idRegister : this.idRegister,
register : this.register
} }
); );
} }
@ -23141,6 +23154,18 @@ GameLib.EntityManager.prototype.removeComponent = function(data) {
updated = false; updated = false;
} else { } else {
delete this.register[data.component.componentType][data.component.id]; delete this.register[data.component.componentType][data.component.id];
if (GameLib.Utils.IsEmpty(this.register[data.component.componentType])) {
delete this.register[data.component.componentType];
GameLib.Event.Emit(
GameLib.Event.COMPONENT_TYPES_UPDATE,
{
componentType : data.component.componentType,
componentTypes : Object.keys(this.register)
}
);
}
delete this.idRegister[data.component.id]; delete this.idRegister[data.component.id];
} }
@ -23150,7 +23175,8 @@ GameLib.EntityManager.prototype.removeComponent = function(data) {
{ {
componentType : data.component.componentType, componentType : data.component.componentType,
components : this.register[data.component.componentType], components : this.register[data.component.componentType],
idRegister : this.idRegister idRegister : this.idRegister,
register : this.register
} }
); );
} }
@ -23211,6 +23237,10 @@ GameLib.EntityManager.prototype.findComponentById = function(id) {
GameLib.EntityManager.prototype.findHelperByObject = function(object) { GameLib.EntityManager.prototype.findHelperByObject = function(object) {
if (typeof this.register[GameLib.Component.HELPER] === 'undefined') {
return null;
}
return Object.keys(this.register[GameLib.Component.HELPER]).reduce( return Object.keys(this.register[GameLib.Component.HELPER]).reduce(
function(result, helperId) { function(result, helperId) {
@ -23334,6 +23364,11 @@ GameLib.EntityManager.prototype.queryComponents = function(componentTypes) {
if (componentTypes instanceof Array) { if (componentTypes instanceof Array) {
componentTypes.map( componentTypes.map(
function(componentType) { function(componentType) {
if (typeof this.register[componentType] === 'undefined') {
return;
}
Object.keys(this.register[componentType]).map( Object.keys(this.register[componentType]).map(
function(componentId) { function(componentId) {
result.push(this.register[componentType][componentId]); result.push(this.register[componentType][componentId]);
@ -23342,6 +23377,11 @@ GameLib.EntityManager.prototype.queryComponents = function(componentTypes) {
}.bind(this) }.bind(this)
) )
} else { } else {
if (typeof this.register[componentTypes] === 'undefined') {
return result;
}
Object.keys(this.register[componentTypes]).map( Object.keys(this.register[componentTypes]).map(
function(componentId) { function(componentId) {
result.push(this.register[componentTypes][componentId]); result.push(this.register[componentTypes][componentId]);
@ -23973,6 +24013,16 @@ GameLib.Image.prototype.updateInstance = function(property) {
} }
}; };
GameLib.Image.prototype.updateFromRawObject = function(rawObject) {
this.id = rawObject.id;
this.name = rawObject.name;
this.fileName = rawObject.fileName;
this.extension = rawObject.extension;
this.path = rawObject.path;
this.contentType = rawObject.contentType;
this.size = rawObject.size;
};
/** /**
* *
* @returns {GameLib.API.Image} * @returns {GameLib.API.Image}
@ -24672,7 +24722,7 @@ GameLib.SocketsRuntime.prototype.updateInstance = function(property) {
* Logs a warning and throws an error if not cannon * Logs a warning and throws an error if not cannon
*/ */
GameLib.SocketsRuntime.prototype.isNotWebSocketThrow = function() { GameLib.SocketsRuntime.prototype.isNotWebSocketThrow = function() {
if (!(this.instance instanceof stats)) { if (this.instance !== WebSocket) {
console.error('Only WebSocket supported'); console.error('Only WebSocket supported');
throw new Error('Only WebSocket supported'); throw new Error('Only WebSocket supported');
} }
@ -29276,8 +29326,8 @@ GameLib.System.Input.prototype.onMouseDownEdit = function(event) {
return; return;
} }
this.mouse.position.x = (event.offsetX / event.target.width ) * 2 - 1; this.mouse.x = (event.offsetX / event.target.width ) * 2 - 1;
this.mouse.position.y = -(event.offsetY / event.target.height) * 2 + 1; this.mouse.y = -(event.offsetY / event.target.height) * 2 + 1;
var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE); var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE);
@ -29286,7 +29336,7 @@ GameLib.System.Input.prototype.onMouseDownEdit = function(event) {
function (result, scene) { function (result, scene) {
editorControl.raycaster.instance.setFromCamera( editorControl.raycaster.instance.setFromCamera(
this.mouse.position, this.mouse,
editorControl.camera.instance editorControl.camera.instance
); );
@ -30192,7 +30242,7 @@ GameLib.System.Linking.prototype.imageChanged = function(data) {
var textures = material.getTextures(); var textures = material.getTextures();
if (textures.indexOf(data.texture) !== -1) { if (textures.indexOf(data.texture) !== -1) {
material.updateInstance(); material.updateInstance('diffuseMap');
} }
}); });
@ -30310,12 +30360,13 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) {
function(componentId) { function(componentId) {
if (GameLib.EntityManager.Instance.idRegister[componentId].parentMesh === data.component.id) { if (GameLib.EntityManager.Instance.idRegister[componentId].parentMesh === data.component.id) {
GameLib.EntityManager.Instance.idRegister[componentId].parentMesh = data.component; GameLib.EntityManager.Instance.idRegister[componentId].parentMesh = data.component;
}
/** /**
* Check if a component has this mesh as a parent * Check if a component has this mesh as a parent
*/ */
if (GameLib.EntityManager.Instance.idRegister[componentId] instanceof GameLib.D3.Mesh) { if (GameLib.EntityManager.Instance.idRegister[componentId] instanceof GameLib.D3.Mesh) {
GameLib.EntityManager.Instance.idRegister[componentId].setParentMesh(data.component); GameLib.EntityManager.Instance.idRegister[componentId].setParentMesh(data.component);
}
} }
} }
); );
@ -31919,39 +31970,29 @@ GameLib.System.Storage.prototype.fetchComponents = function(data, clientCallback
*/ */
GameLib.System.Storage.prototype.imageUploadComplete = function(data) { GameLib.System.Storage.prototype.imageUploadComplete = function(data) {
var runtimeImages = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.IMAGE);
/** /**
* Process all images - we have to load them in addition to creating their runtime components * Process all images - we have to load them in addition to creating their runtime components
*/ */
data.images.map(function(imageData){ data.images.map(function(rawImage){
var image = null; var image = GameLib.EntityManager.Instance.findComponentById(rawImage.id);
if (imageData) { if (image) {
/**
GameLib.Component.Construct(imageData); * We are updating an existing image
*/
} else { image.updateFromRawObject(rawImage);
image = runtimeImages.reduce(
function(result, runtimeImage){
if (imageData.id === runtimeImage.id) {
result = runtimeImage;
}
return result;
},
null
);
/** /**
* Even though the path did not technically change, this should trigger an image reload * Our symbolic path has changed server side, even though it looks the same
*/ */
image.updateInstance('path'); image.updateInstance('path');
} else {
/**
* We are creating a new image
*/
GameLib.Component.Construct(rawImage);
} }
}.bind(this)); }.bind(this));

View File

@ -47,7 +47,7 @@ GameLib.Event.COMPONENTS_LINKED = 0x1d;
GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE = 0x1e; GameLib.Event.UNRESOLVED_DEPENDENCIES_UPDATE = 0x1e;
GameLib.Event.REGISTER_UPDATE = 0x1f; GameLib.Event.REGISTER_UPDATE = 0x1f;
GameLib.Event.BUILD_GUI = 0x20; GameLib.Event.BUILD_GUI = 0x20;
GameLib.Event.REMOVE_MESH = 0x21; GameLib.Event.REMOVE_MESH = 0x21;
GameLib.Event.MESH_SELECTED = 0x22; GameLib.Event.MESH_SELECTED = 0x22;
GameLib.Event.MESH_DESELECTED = 0x23; GameLib.Event.MESH_DESELECTED = 0x23;
GameLib.Event.COMPONENT_REGISTER = 0x24; GameLib.Event.COMPONENT_REGISTER = 0x24;
@ -66,7 +66,7 @@ GameLib.Event.PARENT_ENTITY_CHANGED = 0x30;
GameLib.Event.MATERIAL_TEXTURES_UPDATED = 0x31; GameLib.Event.MATERIAL_TEXTURES_UPDATED = 0x31;
GameLib.Event.DELETE_COMPONENT_ERROR = 0x32; GameLib.Event.DELETE_COMPONENT_ERROR = 0x32;
GameLib.Event.COMPONENT_DELETED = 0x33; GameLib.Event.COMPONENT_DELETED = 0x33;
GameLib.Event.COMPONENT_TYPES_UPDATED = 0x34; GameLib.Event.COMPONENT_TYPES_FETCHED = 0x34;
GameLib.Event.AUDIO_ENDED = 0x35; GameLib.Event.AUDIO_ENDED = 0x35;
GameLib.Event.COMPONENT_LINKED = 0x36; GameLib.Event.COMPONENT_LINKED = 0x36;
GameLib.Event.DONE_SAVING = 0x37; GameLib.Event.DONE_SAVING = 0x37;
@ -92,7 +92,7 @@ GameLib.Event.TOUCH_END = 0x4a;
GameLib.Event.TOUCH_MOVE = 0x4b; GameLib.Event.TOUCH_MOVE = 0x4b;
GameLib.Event.TOUCH_CANCEL = 0x4c; GameLib.Event.TOUCH_CANCEL = 0x4c;
GameLib.Event.GET_REMOTE_API_URL = 0x4d; GameLib.Event.GET_REMOTE_API_URL = 0x4d;
//GameLib.Event.GET_GRAPHICS_RUNTIME = 0x4e; GameLib.Event.COMPONENT_TYPES_UPDATE = 0x4e;
GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f; GameLib.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f;
//GameLib.Event.GET_CODER_IMPLEMENTATION = 0x50; //GameLib.Event.GET_CODER_IMPLEMENTATION = 0x50;
GameLib.Event.ANIMATION_MESH_ADDED = 0x51; GameLib.Event.ANIMATION_MESH_ADDED = 0x51;
@ -212,7 +212,7 @@ GameLib.Event.GetEventName = function(number) {
case 0x4b : return 'touch_move'; case 0x4b : return 'touch_move';
case 0x4c : return 'touch_cancel'; case 0x4c : return 'touch_cancel';
case 0x4d : return 'get_remote_api_url'; case 0x4d : return 'get_remote_api_url';
case 0x4e : return 'unused';//'get_graphics_implementation'; case 0x4e : return 'component_types_update';
case 0x4f : return 'delayed_instance_encountered'; case 0x4f : return 'delayed_instance_encountered';
case 0x50 : return 'unused';//'get_coder_implementation'; case 0x50 : return 'unused';//'get_coder_implementation';
case 0x51 : return 'animation_mesh_added'; case 0x51 : return 'animation_mesh_added';

View File

@ -729,17 +729,22 @@ GameLib.Utils.UpperCaseWordsSpaces = function(word) {
).trim(); ).trim();
}; };
/**
* @return {string}
*/
GameLib.Utils.UpperCaseUnderscore = function(word) { GameLib.Utils.UpperCaseUnderscore = function(word) {
var str = ''; var str = '';
word.map(function(letter){ word.split('').map(function(letter){
if (letter === letter.toUpperCase()) { if (letter == letter.toUpperCase()) {
str += '_' + letter; str += '_' + letter;
} else { } else {
str += letter.toUpperCase(); str += letter.toUpperCase();
} }
}); });
str = str.replace(new RegExp('^_'),'');
return str; return str;
}; };

View File

@ -603,49 +603,49 @@ GameLib.Component.GetComponentInfo = function(number) {
constructor : GameLib.D3.Mesh.Cylinder constructor : GameLib.D3.Mesh.Cylinder
}; };
case 0x41 : return { case 0x41 : return {
name : 'GameLib.D3.System.Animation', name : 'GameLib.System.Animation',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Animation constructor : GameLib.System.Animation
}; };
case 0x42 : return { case 0x42 : return {
name : 'GameLib.D3.System.CustomCode', name : 'GameLib.System.CustomCode',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.CustomCode constructor : GameLib.System.CustomCode
}; };
case 0x43 : return { case 0x43 : return {
name : 'GameLib.D3.System.GUI', name : 'GameLib.System.GUI',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.GUI constructor : GameLib.System.GUI
}; };
case 0x44 : return { case 0x44 : return {
name : 'GameLib.D3.System.Input', name : 'GameLib.System.Input',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Input constructor : GameLib.System.Input
}; };
case 0x45 : return { case 0x45 : return {
name : 'GameLib.D3.System.Linking', name : 'GameLib.System.Linking',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Linking constructor : GameLib.System.Linking
}; };
case 0x46 : return { case 0x46 : return {
name : 'GameLib.D3.System.Physics', name : 'GameLib.System.Physics',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Physics constructor : GameLib.System.Physics
}; };
case 0x47 : return { case 0x47 : return {
name : 'GameLib.D3.System.Render', name : 'GameLib.System.Render',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Render constructor : GameLib.System.Render
}; };
case 0x48 : return { case 0x48 : return {
name : 'GameLib.D3.System.Storage', name : 'GameLib.System.Storage',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Storage constructor : GameLib.System.Storage
}; };
case 0x49 : return { case 0x49 : return {
name : 'GameLib.D3.System.Visualization', name : 'GameLib.System.Visualization',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Visualization constructor : GameLib.System.Visualization
}; };
case 0x50 : return { case 0x50 : return {
name : 'GameLib.D3.Fog', name : 'GameLib.D3.Fog',
@ -663,9 +663,9 @@ GameLib.Component.GetComponentInfo = function(number) {
constructor : GameLib.D3.ParticleEngine constructor : GameLib.D3.ParticleEngine
}; };
case 0x53 : return { case 0x53 : return {
name : 'GameLib.D3.System.Particle', name : 'GameLib.System.Particle',
runtime : GameLib.Component.DEFAULT_RUNTIME, runtime : GameLib.Component.DEFAULT_RUNTIME,
constructor : GameLib.D3.System.Particle constructor : GameLib.System.Particle
}; };
case 0x54 : return { case 0x54 : return {
name : 'GameLib.D3.Particle', name : 'GameLib.D3.Particle',

View File

@ -52,7 +52,7 @@ GameLib.CoderRuntime.prototype.updateInstance = function(property) {
* Logs a warning and throws an error if not cannon * Logs a warning and throws an error if not cannon
*/ */
GameLib.CoderRuntime.prototype.isNotCodeMirrorThrow = function() { GameLib.CoderRuntime.prototype.isNotCodeMirrorThrow = function() {
if (!(this.instance instanceof CodeMirror)) { if (this.instance !== CodeMirror) {
console.error('Only CodeMirror supported'); console.error('Only CodeMirror supported');
throw new Error('Only CodeMirror supported'); throw new Error('Only CodeMirror supported');
} }

View File

@ -65,6 +65,13 @@ GameLib.EntityManager.prototype.registerComponent = function(data) {
if (GameLib.Utils.UndefinedOrNull(this.register[data.component.componentType])) { if (GameLib.Utils.UndefinedOrNull(this.register[data.component.componentType])) {
this.register[data.component.componentType] = {}; this.register[data.component.componentType] = {};
GameLib.Event.Emit(
GameLib.Event.COMPONENT_TYPES_UPDATE,
{
componentType : data.component.componentType,
componentTypes : Object.keys(this.register)
}
);
updated = true; updated = true;
} }
@ -84,7 +91,8 @@ GameLib.EntityManager.prototype.registerComponent = function(data) {
{ {
componentType : data.component.componentType, componentType : data.component.componentType,
components : this.register[data.component.componentType], components : this.register[data.component.componentType],
idRegister : this.idRegister idRegister : this.idRegister,
register : this.register
} }
); );
} }
@ -102,6 +110,18 @@ GameLib.EntityManager.prototype.removeComponent = function(data) {
updated = false; updated = false;
} else { } else {
delete this.register[data.component.componentType][data.component.id]; delete this.register[data.component.componentType][data.component.id];
if (GameLib.Utils.IsEmpty(this.register[data.component.componentType])) {
delete this.register[data.component.componentType];
GameLib.Event.Emit(
GameLib.Event.COMPONENT_TYPES_UPDATE,
{
componentType : data.component.componentType,
componentTypes : Object.keys(this.register)
}
);
}
delete this.idRegister[data.component.id]; delete this.idRegister[data.component.id];
} }
@ -111,7 +131,8 @@ GameLib.EntityManager.prototype.removeComponent = function(data) {
{ {
componentType : data.component.componentType, componentType : data.component.componentType,
components : this.register[data.component.componentType], components : this.register[data.component.componentType],
idRegister : this.idRegister idRegister : this.idRegister,
register : this.register
} }
); );
} }
@ -172,6 +193,10 @@ GameLib.EntityManager.prototype.findComponentById = function(id) {
GameLib.EntityManager.prototype.findHelperByObject = function(object) { GameLib.EntityManager.prototype.findHelperByObject = function(object) {
if (typeof this.register[GameLib.Component.HELPER] === 'undefined') {
return null;
}
return Object.keys(this.register[GameLib.Component.HELPER]).reduce( return Object.keys(this.register[GameLib.Component.HELPER]).reduce(
function(result, helperId) { function(result, helperId) {
@ -295,6 +320,11 @@ GameLib.EntityManager.prototype.queryComponents = function(componentTypes) {
if (componentTypes instanceof Array) { if (componentTypes instanceof Array) {
componentTypes.map( componentTypes.map(
function(componentType) { function(componentType) {
if (typeof this.register[componentType] === 'undefined') {
return;
}
Object.keys(this.register[componentType]).map( Object.keys(this.register[componentType]).map(
function(componentId) { function(componentId) {
result.push(this.register[componentType][componentId]); result.push(this.register[componentType][componentId]);
@ -303,6 +333,11 @@ GameLib.EntityManager.prototype.queryComponents = function(componentTypes) {
}.bind(this) }.bind(this)
) )
} else { } else {
if (typeof this.register[componentTypes] === 'undefined') {
return result;
}
Object.keys(this.register[componentTypes]).map( Object.keys(this.register[componentTypes]).map(
function(componentId) { function(componentId) {
result.push(this.register[componentTypes][componentId]); result.push(this.register[componentTypes][componentId]);

View File

@ -75,6 +75,16 @@ GameLib.Image.prototype.updateInstance = function(property) {
} }
}; };
GameLib.Image.prototype.updateFromRawObject = function(rawObject) {
this.id = rawObject.id;
this.name = rawObject.name;
this.fileName = rawObject.fileName;
this.extension = rawObject.extension;
this.path = rawObject.path;
this.contentType = rawObject.contentType;
this.size = rawObject.size;
};
/** /**
* *
* @returns {GameLib.API.Image} * @returns {GameLib.API.Image}

View File

@ -52,7 +52,7 @@ GameLib.SocketsRuntime.prototype.updateInstance = function(property) {
* Logs a warning and throws an error if not cannon * Logs a warning and throws an error if not cannon
*/ */
GameLib.SocketsRuntime.prototype.isNotWebSocketThrow = function() { GameLib.SocketsRuntime.prototype.isNotWebSocketThrow = function() {
if (!(this.instance instanceof stats)) { if (this.instance !== WebSocket) {
console.error('Only WebSocket supported'); console.error('Only WebSocket supported');
throw new Error('Only WebSocket supported'); throw new Error('Only WebSocket supported');
} }

View File

@ -881,8 +881,8 @@ GameLib.System.Input.prototype.onMouseDownEdit = function(event) {
return; return;
} }
this.mouse.position.x = (event.offsetX / event.target.width ) * 2 - 1; this.mouse.x = (event.offsetX / event.target.width ) * 2 - 1;
this.mouse.position.y = -(event.offsetY / event.target.height) * 2 + 1; this.mouse.y = -(event.offsetY / event.target.height) * 2 + 1;
var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE); var scenes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SCENE);
@ -891,7 +891,7 @@ GameLib.System.Input.prototype.onMouseDownEdit = function(event) {
function (result, scene) { function (result, scene) {
editorControl.raycaster.instance.setFromCamera( editorControl.raycaster.instance.setFromCamera(
this.mouse.position, this.mouse,
editorControl.camera.instance editorControl.camera.instance
); );

View File

@ -540,7 +540,7 @@ GameLib.System.Linking.prototype.imageChanged = function(data) {
var textures = material.getTextures(); var textures = material.getTextures();
if (textures.indexOf(data.texture) !== -1) { if (textures.indexOf(data.texture) !== -1) {
material.updateInstance(); material.updateInstance('diffuseMap');
} }
}); });
@ -658,12 +658,13 @@ GameLib.System.Linking.prototype.instanceCreated = function(data) {
function(componentId) { function(componentId) {
if (GameLib.EntityManager.Instance.idRegister[componentId].parentMesh === data.component.id) { if (GameLib.EntityManager.Instance.idRegister[componentId].parentMesh === data.component.id) {
GameLib.EntityManager.Instance.idRegister[componentId].parentMesh = data.component; GameLib.EntityManager.Instance.idRegister[componentId].parentMesh = data.component;
}
/** /**
* Check if a component has this mesh as a parent * Check if a component has this mesh as a parent
*/ */
if (GameLib.EntityManager.Instance.idRegister[componentId] instanceof GameLib.D3.Mesh) { if (GameLib.EntityManager.Instance.idRegister[componentId] instanceof GameLib.D3.Mesh) {
GameLib.EntityManager.Instance.idRegister[componentId].setParentMesh(data.component); GameLib.EntityManager.Instance.idRegister[componentId].setParentMesh(data.component);
}
} }
} }
); );

View File

@ -710,39 +710,29 @@ GameLib.System.Storage.prototype.fetchComponents = function(data, clientCallback
*/ */
GameLib.System.Storage.prototype.imageUploadComplete = function(data) { GameLib.System.Storage.prototype.imageUploadComplete = function(data) {
var runtimeImages = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.IMAGE);
/** /**
* Process all images - we have to load them in addition to creating their runtime components * Process all images - we have to load them in addition to creating their runtime components
*/ */
data.images.map(function(imageData){ data.images.map(function(rawImage){
var image = null; var image = GameLib.EntityManager.Instance.findComponentById(rawImage.id);
if (imageData) { if (image) {
/**
GameLib.Component.Construct(imageData); * We are updating an existing image
*/
} else { image.updateFromRawObject(rawImage);
image = runtimeImages.reduce(
function(result, runtimeImage){
if (imageData.id === runtimeImage.id) {
result = runtimeImage;
}
return result;
},
null
);
/** /**
* Even though the path did not technically change, this should trigger an image reload * Our symbolic path has changed server side, even though it looks the same
*/ */
image.updateInstance('path'); image.updateInstance('path');
} else {
/**
* We are creating a new image
*/
GameLib.Component.Construct(rawImage);
} }
}.bind(this)); }.bind(this));