FromObject deprecated
parent
23a66225ef
commit
3c67d28eff
|
@ -11,30 +11,7 @@ GameLib.API.Component = function(
|
||||||
this.componentType = componentType;
|
this.componentType = componentType;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
||||||
|
parentEntity = null;
|
||||||
if (this instanceof GameLib.EntityManager) {
|
|
||||||
parentEntity = this.defaultEntity;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
parentEntity = GameLib.EntityManager.Instance.defaultEntity;
|
|
||||||
|
|
||||||
if (parentEntity) {
|
|
||||||
|
|
||||||
if (parentEntity.id === this.id) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the default entity, it cannot be the parent entity of itself - so terminate here.
|
|
||||||
*/
|
|
||||||
console.log('terminating here');
|
|
||||||
|
|
||||||
parentEntity = null;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
parentEntity.addComponent(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.parentEntity = parentEntity;
|
this.parentEntity = parentEntity;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1266,22 +1266,12 @@ GameLib.Component.ConstructFromObject = function(rawComponentObject) {
|
||||||
|
|
||||||
var info = GameLib.Component.GetComponentInfo(rawComponentObject.componentType);
|
var info = GameLib.Component.GetComponentInfo(rawComponentObject.componentType);
|
||||||
|
|
||||||
var componentClass = info.constructor;
|
var runtime = GameLib.Component.GetRuntimeObject(info.runtime);
|
||||||
|
|
||||||
var fn = componentClass['FromObject'];
|
|
||||||
|
|
||||||
if (rawComponentObject.componentType === GameLib.Component.ENTITY) {
|
|
||||||
|
|
||||||
runtimeComponent = fn(rawComponentObject, GameLib.EntityManager.Instance);
|
|
||||||
|
|
||||||
|
if (runtime) {
|
||||||
|
runtimeComponent = new info.constructor(runtime, rawComponentObject);
|
||||||
} else {
|
} else {
|
||||||
var runtime = GameLib.Component.GetRuntimeObject(info.runtime);
|
runtimeComponent = new info.constructor(rawComponentObject);
|
||||||
|
|
||||||
if (runtime) {
|
|
||||||
runtimeComponent = fn(runtime, rawComponentObject);
|
|
||||||
} else {
|
|
||||||
runtimeComponent = fn(rawComponentObject);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return runtimeComponent;
|
return runtimeComponent;
|
||||||
|
|
|
@ -91,9 +91,5 @@ GameLib.Canvas.prototype.toApiObject = function() {
|
||||||
* @returns {GameLib.Canvas}
|
* @returns {GameLib.Canvas}
|
||||||
*/
|
*/
|
||||||
GameLib.Canvas.FromObject = function(objectCanvas) {
|
GameLib.Canvas.FromObject = function(objectCanvas) {
|
||||||
|
return new GameLib.Canvas(objectCanvas);
|
||||||
return new GameLib.Canvas(
|
|
||||||
GameLib.API.Canvas.FromObject(objectCanvas)
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
};
|
|
@ -41,38 +41,23 @@ GameLib.D3.Camera = function(
|
||||||
apiCamera.parentEntity
|
apiCamera.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.position instanceof GameLib.API.Vector3) {
|
this.position = new GameLib.Vector3(
|
||||||
this.position = new GameLib.Vector3(
|
graphics,
|
||||||
graphics,
|
this.position,
|
||||||
this.position,
|
this
|
||||||
this
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.warn('position not instance of API.Vector3');
|
|
||||||
throw new Error('position not instance of API.Vector3');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.quaternion instanceof GameLib.API.Quaternion) {
|
this.quaternion = new GameLib.Quaternion(
|
||||||
this.quaternion = new GameLib.Quaternion(
|
graphics,
|
||||||
graphics,
|
this.quaternion,
|
||||||
this.quaternion,
|
this
|
||||||
this
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.warn('quaternion not instance of API.Quaternion');
|
|
||||||
throw new Error('quaternion not instance of API.Quaternion');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.lookAt instanceof GameLib.API.Vector3) {
|
this.lookAt = new GameLib.Vector3(
|
||||||
this.lookAt = new GameLib.Vector3(
|
graphics,
|
||||||
graphics,
|
this.lookAt,
|
||||||
this.lookAt,
|
this
|
||||||
this
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.warn('lookAt not instance of API.Vector3');
|
|
||||||
throw new Error('lookAt not instance of API.Vector3');
|
|
||||||
}
|
|
||||||
|
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
|
|
|
@ -65,21 +65,15 @@ GameLib.D3.Face = function Face(
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.vertexNormals = this.vertexNormals.map(function(vertexNormal){
|
this.vertexNormals = this.vertexNormals.map(
|
||||||
if (vertexNormal instanceof GameLib.Vector3) {
|
function(vertexNormal) {
|
||||||
return vertexNormal;
|
return new GameLib.Vector3(
|
||||||
}
|
this.implementation,
|
||||||
|
vertexNormal,
|
||||||
if (vertexNormal instanceof GameLib.API.Vector3) {
|
this
|
||||||
return new GameLib.Vector3(
|
);
|
||||||
this.implementation,
|
}.bind(this)
|
||||||
vertexNormal,
|
);
|
||||||
this
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
console.warn('unknown vertex normal type', vertexNormal);
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
this.uvs = this.uvs.reduce(
|
this.uvs = this.uvs.reduce(
|
||||||
|
|
||||||
|
@ -88,17 +82,13 @@ GameLib.D3.Face = function Face(
|
||||||
result[index] = uvArray.reduce(
|
result[index] = uvArray.reduce(
|
||||||
function(uvResult, uv) {
|
function(uvResult, uv) {
|
||||||
|
|
||||||
if (uv instanceof GameLib.API.Vector2) {
|
uvResult.push(
|
||||||
uvResult.push(
|
new GameLib.Vector2(
|
||||||
new GameLib.Vector2(
|
this.implementation,
|
||||||
this.implementation,
|
uv,
|
||||||
uv,
|
this
|
||||||
this
|
)
|
||||||
)
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.warn('unknown uv type');
|
|
||||||
}
|
|
||||||
|
|
||||||
return uvResult;
|
return uvResult;
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
|
|
|
@ -45,27 +45,25 @@ GameLib.D3.Mesh = function (
|
||||||
|
|
||||||
this.faces = this.faces.map(
|
this.faces = this.faces.map(
|
||||||
function(face) {
|
function(face) {
|
||||||
if (face instanceof GameLib.D3.API.Face) {
|
return new GameLib.D3.Face(
|
||||||
return new GameLib.D3.Face(
|
this.graphics,
|
||||||
this.graphics,
|
face
|
||||||
face
|
)
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return face;
|
|
||||||
}
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.materials = this.materials.map(
|
this.materials = this.materials.map(
|
||||||
function(material) {
|
function(material) {
|
||||||
if (material instanceof GameLib.D3.API.Material) {
|
|
||||||
return new GameLib.D3.Material(
|
if (typeof material === 'string') {
|
||||||
this.graphics,
|
|
||||||
material
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new GameLib.D3.Material(
|
||||||
|
this.graphics,
|
||||||
|
material
|
||||||
|
);
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -77,10 +75,10 @@ GameLib.D3.Mesh = function (
|
||||||
}
|
}
|
||||||
|
|
||||||
this.vertices = this.vertices.map(
|
this.vertices = this.vertices.map(
|
||||||
function (apiVertex) {
|
function (vertex) {
|
||||||
return new GameLib.D3.Vertex(
|
return new GameLib.D3.Vertex(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiVertex
|
vertex
|
||||||
);
|
);
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
|
@ -36,17 +36,15 @@ GameLib.D3.Scene = function (
|
||||||
this.meshes = this.meshes.map(
|
this.meshes = this.meshes.map(
|
||||||
function(apiMesh) {
|
function(apiMesh) {
|
||||||
|
|
||||||
if (apiMesh instanceof GameLib.D3.API.Mesh) {
|
if (typeof apiMesh === 'string') {
|
||||||
|
return apiMesh;
|
||||||
|
} else {
|
||||||
apiMesh.parentScene = this;
|
apiMesh.parentScene = this;
|
||||||
|
|
||||||
return new GameLib.D3.Mesh(
|
return new GameLib.D3.Mesh(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiMesh
|
apiMesh
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
|
||||||
return apiMesh;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
@ -55,15 +53,14 @@ GameLib.D3.Scene = function (
|
||||||
this.lights = this.lights.map(
|
this.lights = this.lights.map(
|
||||||
function(apiLight) {
|
function(apiLight) {
|
||||||
|
|
||||||
if (apiLight instanceof GameLib.D3.API.Light) {
|
if (typeof apiLight === 'string') {
|
||||||
|
return apiLight;
|
||||||
|
} else {
|
||||||
return new GameLib.D3.Light(
|
return new GameLib.D3.Light(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiLight
|
apiLight
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
|
||||||
return apiLight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
@ -72,72 +69,60 @@ GameLib.D3.Scene = function (
|
||||||
this.textures = this.textures.map(
|
this.textures = this.textures.map(
|
||||||
function(apiTexture) {
|
function(apiTexture) {
|
||||||
|
|
||||||
if (apiTexture instanceof GameLib.D3.API.Texture) {
|
if (typeof apiTexture === 'string') {
|
||||||
|
|
||||||
var texture = new GameLib.D3.Texture(
|
|
||||||
this.graphics,
|
|
||||||
apiTexture
|
|
||||||
);
|
|
||||||
|
|
||||||
return texture;
|
|
||||||
} else {
|
|
||||||
return apiTexture;
|
return apiTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new GameLib.D3.Texture(
|
||||||
|
this.graphics,
|
||||||
|
apiTexture
|
||||||
|
);
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.materials = this.materials.map(
|
this.materials = this.materials.map(
|
||||||
function(apiMaterial) {
|
function(apiMaterial) {
|
||||||
|
|
||||||
if (apiMaterial instanceof GameLib.D3.API.Material) {
|
if (typeof apiMaterial === 'string') {
|
||||||
|
|
||||||
var material = new GameLib.D3.Material(
|
|
||||||
this.graphics,
|
|
||||||
apiMaterial
|
|
||||||
);
|
|
||||||
|
|
||||||
return material;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return apiMaterial;
|
return apiMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new GameLib.D3.Material(
|
||||||
|
this.graphics,
|
||||||
|
apiMaterial
|
||||||
|
);
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.images = this.images.map(
|
this.images = this.images.map(
|
||||||
function(apiImage) {
|
function(apiImage) {
|
||||||
|
|
||||||
if (apiImage instanceof GameLib.API.Image) {
|
if (typeof apiImage === 'string') {
|
||||||
|
|
||||||
var image = new GameLib.Image(
|
|
||||||
this.graphics,
|
|
||||||
apiImage
|
|
||||||
);
|
|
||||||
|
|
||||||
return image;
|
|
||||||
} else {
|
|
||||||
return apiImage;
|
return apiImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new GameLib.Image(
|
||||||
|
this.graphics,
|
||||||
|
apiImage
|
||||||
|
);
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.fog instanceof GameLib.D3.API.Fog) {
|
if (typeof this.fog !== 'string') {
|
||||||
this.fog = new GameLib.D3.Fog(
|
this.fog = new GameLib.D3.Fog(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this.fog
|
this.fog
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.gridColor instanceof GameLib.API.Color) {
|
this.gridColor = new GameLib.Color(
|
||||||
this.gridColor = new GameLib.Color(
|
this.graphics,
|
||||||
this.graphics,
|
this.gridColor,
|
||||||
this.gridColor,
|
this
|
||||||
this
|
);
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runtime scenes have helpers (just used to store which helper belongs to which scene)
|
* Runtime scenes have helpers (just used to store which helper belongs to which scene)
|
||||||
|
|
|
@ -205,10 +205,8 @@ GameLib.Entity.prototype.toApiObject = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.Entity.FromObject = function(objectEntity) {
|
GameLib.Entity.FromObject = function(objectEntity) {
|
||||||
|
|
||||||
var apiEntity = GameLib.API.Entity.FromObject(objectEntity);
|
|
||||||
|
|
||||||
var entity = new GameLib.Entity(
|
var entity = new GameLib.Entity(
|
||||||
apiEntity
|
objectEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
GameLib.EntityManager.Instance.addEntity(entity);
|
GameLib.EntityManager.Instance.addEntity(entity);
|
||||||
|
|
|
@ -40,17 +40,14 @@ GameLib.Matrix4 = function(
|
||||||
|
|
||||||
this.rows = this.rows.map(
|
this.rows = this.rows.map(
|
||||||
function(row) {
|
function(row) {
|
||||||
if (row instanceof GameLib.API.Vector4) {
|
|
||||||
return new GameLib.Vector4(
|
return new GameLib.Vector4(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
row,
|
row,
|
||||||
this,
|
this,
|
||||||
this.grain
|
this.grain
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
console.warn('Attempted conversion of wrong instance');
|
|
||||||
throw new Error('Attempted conversion of wrong instance');
|
|
||||||
}
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -411,28 +411,28 @@ GameLib.System.Input.prototype.registerMouseControls = function(mouseControl) {
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Input.prototype.registerEditorControls = function(editorControl) {
|
GameLib.System.Input.prototype.registerEditorControls = function(editorControl) {
|
||||||
//
|
|
||||||
// /**
|
/**
|
||||||
// * If we already have mouse controls, we don't want to add another event listener onto the DOM
|
* If we already have mouse controls, we don't want to add another event listener onto the DOM
|
||||||
// */
|
*/
|
||||||
// this.mouseControls.map(
|
this.mouseControls.map(
|
||||||
// function(mouseControl) {
|
function(mouseControl) {
|
||||||
// if (mouseControl.domElement.instance === editorControl.domElement.instance) {
|
if (mouseControl.domElement.instance === editorControl.domElement.instance) {
|
||||||
// this.deRegisterMouseControls(mouseControl);
|
this.deRegisterMouseControls(mouseControl);
|
||||||
// }
|
}
|
||||||
// }.bind(this)
|
}.bind(this)
|
||||||
// );
|
);
|
||||||
//
|
|
||||||
// /**
|
/**
|
||||||
// * If we already have keyboard controls, we don't want to add another event listener onto the DOM
|
* If we already have keyboard controls, we don't want to add another event listener onto the DOM
|
||||||
// */
|
*/
|
||||||
// this.keyboardControls.map(
|
this.keyboardControls.map(
|
||||||
// function(keyboardControl) {
|
function(keyboardControl) {
|
||||||
// if (keyboardControl.domElement.instance === editorControl.domElement.instance) {
|
if (keyboardControl.domElement.instance === editorControl.domElement.instance) {
|
||||||
// this.deRegisterKeyboardControls(keyboardControl);
|
this.deRegisterKeyboardControls(keyboardControl);
|
||||||
// }
|
}
|
||||||
// }.bind(this)
|
}.bind(this)
|
||||||
// );
|
);
|
||||||
|
|
||||||
if (!editorControl.domElement || !editorControl.domElement.instance) {
|
if (!editorControl.domElement || !editorControl.domElement.instance) {
|
||||||
console.warn('no domElement at time of registration of editor controls - are you sure you know what you are doing?');
|
console.warn('no domElement at time of registration of editor controls - are you sure you know what you are doing?');
|
||||||
|
|
|
@ -574,7 +574,11 @@ 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('diffuseMap');
|
|
||||||
|
if (material.loaded) {
|
||||||
|
material.updateInstance('diffuseMap');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -289,7 +289,7 @@ GameLib.System.Storage.prototype.save = function(data) {
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
function error(error){
|
function error(error){
|
||||||
console.log(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue