FromObject deprecated

beta.r3js.org
-=yb4f310 2018-01-14 13:01:08 +01:00
parent 23a66225ef
commit 3c67d28eff
12 changed files with 118 additions and 198 deletions

View File

@ -11,30 +11,7 @@ GameLib.API.Component = function(
this.componentType = componentType;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
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);
}
}
}
parentEntity = null;
}
this.parentEntity = parentEntity;
};

View File

@ -1266,22 +1266,12 @@ GameLib.Component.ConstructFromObject = function(rawComponentObject) {
var info = GameLib.Component.GetComponentInfo(rawComponentObject.componentType);
var componentClass = info.constructor;
var fn = componentClass['FromObject'];
if (rawComponentObject.componentType === GameLib.Component.ENTITY) {
runtimeComponent = fn(rawComponentObject, GameLib.EntityManager.Instance);
var runtime = GameLib.Component.GetRuntimeObject(info.runtime);
if (runtime) {
runtimeComponent = new info.constructor(runtime, rawComponentObject);
} else {
var runtime = GameLib.Component.GetRuntimeObject(info.runtime);
if (runtime) {
runtimeComponent = fn(runtime, rawComponentObject);
} else {
runtimeComponent = fn(rawComponentObject);
}
runtimeComponent = new info.constructor(rawComponentObject);
}
return runtimeComponent;

View File

@ -91,9 +91,5 @@ GameLib.Canvas.prototype.toApiObject = function() {
* @returns {GameLib.Canvas}
*/
GameLib.Canvas.FromObject = function(objectCanvas) {
return new GameLib.Canvas(
GameLib.API.Canvas.FromObject(objectCanvas)
);
return new GameLib.Canvas(objectCanvas);
};

View File

@ -41,38 +41,23 @@ GameLib.D3.Camera = function(
apiCamera.parentEntity
);
if (this.position instanceof GameLib.API.Vector3) {
this.position = new GameLib.Vector3(
graphics,
this.position,
this
);
} else {
console.warn('position not instance of API.Vector3');
throw new Error('position not instance of API.Vector3');
}
this.position = new GameLib.Vector3(
graphics,
this.position,
this
);
if (this.quaternion instanceof GameLib.API.Quaternion) {
this.quaternion = new GameLib.Quaternion(
graphics,
this.quaternion,
this
);
} else {
console.warn('quaternion not instance of API.Quaternion');
throw new Error('quaternion not instance of API.Quaternion');
}
this.quaternion = new GameLib.Quaternion(
graphics,
this.quaternion,
this
);
if (this.lookAt instanceof GameLib.API.Vector3) {
this.lookAt = new GameLib.Vector3(
graphics,
this.lookAt,
this
);
} else {
console.warn('lookAt not instance of API.Vector3');
throw new Error('lookAt not instance of API.Vector3');
}
this.lookAt = new GameLib.Vector3(
graphics,
this.lookAt,
this
);
GameLib.Component.call(
this,

View File

@ -65,21 +65,15 @@ GameLib.D3.Face = function Face(
}
this.vertexNormals = this.vertexNormals.map(function(vertexNormal){
if (vertexNormal instanceof GameLib.Vector3) {
return vertexNormal;
}
if (vertexNormal instanceof GameLib.API.Vector3) {
return new GameLib.Vector3(
this.implementation,
vertexNormal,
this
)
}
console.warn('unknown vertex normal type', vertexNormal);
}.bind(this));
this.vertexNormals = this.vertexNormals.map(
function(vertexNormal) {
return new GameLib.Vector3(
this.implementation,
vertexNormal,
this
);
}.bind(this)
);
this.uvs = this.uvs.reduce(
@ -88,17 +82,13 @@ GameLib.D3.Face = function Face(
result[index] = uvArray.reduce(
function(uvResult, uv) {
if (uv instanceof GameLib.API.Vector2) {
uvResult.push(
new GameLib.Vector2(
this.implementation,
uv,
this
)
);
} else {
console.warn('unknown uv type');
}
uvResult.push(
new GameLib.Vector2(
this.implementation,
uv,
this
)
);
return uvResult;
}.bind(this),

View File

@ -45,27 +45,25 @@ GameLib.D3.Mesh = function (
this.faces = this.faces.map(
function(face) {
if (face instanceof GameLib.D3.API.Face) {
return new GameLib.D3.Face(
this.graphics,
face
)
} else {
return face;
}
return new GameLib.D3.Face(
this.graphics,
face
)
}.bind(this)
);
this.materials = this.materials.map(
function(material) {
if (material instanceof GameLib.D3.API.Material) {
return new GameLib.D3.Material(
this.graphics,
material
)
} else {
if (typeof material === 'string') {
return material;
}
return new GameLib.D3.Material(
this.graphics,
material
);
}.bind(this)
);
@ -77,10 +75,10 @@ GameLib.D3.Mesh = function (
}
this.vertices = this.vertices.map(
function (apiVertex) {
function (vertex) {
return new GameLib.D3.Vertex(
this.graphics,
apiVertex
vertex
);
}.bind(this)
);

View File

@ -36,17 +36,15 @@ GameLib.D3.Scene = function (
this.meshes = this.meshes.map(
function(apiMesh) {
if (apiMesh instanceof GameLib.D3.API.Mesh) {
if (typeof apiMesh === 'string') {
return apiMesh;
} else {
apiMesh.parentScene = this;
return new GameLib.D3.Mesh(
this.graphics,
apiMesh
);
} else {
return apiMesh;
}
}.bind(this)
@ -55,15 +53,14 @@ GameLib.D3.Scene = function (
this.lights = this.lights.map(
function(apiLight) {
if (apiLight instanceof GameLib.D3.API.Light) {
if (typeof apiLight === 'string') {
return apiLight;
} else {
return new GameLib.D3.Light(
this.graphics,
apiLight
);
} else {
return apiLight;
}
}.bind(this)
@ -72,72 +69,60 @@ GameLib.D3.Scene = function (
this.textures = this.textures.map(
function(apiTexture) {
if (apiTexture instanceof GameLib.D3.API.Texture) {
var texture = new GameLib.D3.Texture(
this.graphics,
apiTexture
);
return texture;
} else {
if (typeof apiTexture === 'string') {
return apiTexture;
}
return new GameLib.D3.Texture(
this.graphics,
apiTexture
);
}.bind(this)
);
this.materials = this.materials.map(
function(apiMaterial) {
if (apiMaterial instanceof GameLib.D3.API.Material) {
var material = new GameLib.D3.Material(
this.graphics,
apiMaterial
);
return material;
} else {
if (typeof apiMaterial === 'string') {
return apiMaterial;
}
return new GameLib.D3.Material(
this.graphics,
apiMaterial
);
}.bind(this)
);
this.images = this.images.map(
function(apiImage) {
if (apiImage instanceof GameLib.API.Image) {
var image = new GameLib.Image(
this.graphics,
apiImage
);
return image;
} else {
if (typeof apiImage === 'string') {
return apiImage;
}
return new GameLib.Image(
this.graphics,
apiImage
);
}.bind(this)
);
if (this.fog instanceof GameLib.D3.API.Fog) {
if (typeof this.fog !== 'string') {
this.fog = new GameLib.D3.Fog(
this.graphics,
this.fog
)
}
if (this.gridColor instanceof GameLib.API.Color) {
this.gridColor = new GameLib.Color(
this.graphics,
this.gridColor,
this
)
}
this.gridColor = new GameLib.Color(
this.graphics,
this.gridColor,
this
);
/**
* Runtime scenes have helpers (just used to store which helper belongs to which scene)

View File

@ -205,10 +205,8 @@ GameLib.Entity.prototype.toApiObject = function() {
*/
GameLib.Entity.FromObject = function(objectEntity) {
var apiEntity = GameLib.API.Entity.FromObject(objectEntity);
var entity = new GameLib.Entity(
apiEntity
objectEntity
);
GameLib.EntityManager.Instance.addEntity(entity);

View File

@ -40,17 +40,14 @@ GameLib.Matrix4 = function(
this.rows = this.rows.map(
function(row) {
if (row instanceof GameLib.API.Vector4) {
return new GameLib.Vector4(
this.graphics,
row,
this,
this.grain
);
} else {
console.warn('Attempted conversion of wrong instance');
throw new Error('Attempted conversion of wrong instance');
}
return new GameLib.Vector4(
this.graphics,
row,
this,
this.grain
);
}.bind(this)
);

View File

@ -411,28 +411,28 @@ GameLib.System.Input.prototype.registerMouseControls = function(mouseControl) {
};
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
// */
// this.mouseControls.map(
// function(mouseControl) {
// if (mouseControl.domElement.instance === editorControl.domElement.instance) {
// this.deRegisterMouseControls(mouseControl);
// }
// }.bind(this)
// );
//
// /**
// * If we already have keyboard controls, we don't want to add another event listener onto the DOM
// */
// this.keyboardControls.map(
// function(keyboardControl) {
// if (keyboardControl.domElement.instance === editorControl.domElement.instance) {
// this.deRegisterKeyboardControls(keyboardControl);
// }
// }.bind(this)
// );
/**
* If we already have mouse controls, we don't want to add another event listener onto the DOM
*/
this.mouseControls.map(
function(mouseControl) {
if (mouseControl.domElement.instance === editorControl.domElement.instance) {
this.deRegisterMouseControls(mouseControl);
}
}.bind(this)
);
/**
* If we already have keyboard controls, we don't want to add another event listener onto the DOM
*/
this.keyboardControls.map(
function(keyboardControl) {
if (keyboardControl.domElement.instance === editorControl.domElement.instance) {
this.deRegisterKeyboardControls(keyboardControl);
}
}.bind(this)
);
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?');

View File

@ -574,7 +574,11 @@ GameLib.System.Linking.prototype.imageChanged = function(data) {
var textures = material.getTextures();
if (textures.indexOf(data.texture) !== -1) {
material.updateInstance('diffuseMap');
if (material.loaded) {
material.updateInstance('diffuseMap');
}
}
});

View File

@ -289,7 +289,7 @@ GameLib.System.Storage.prototype.save = function(data) {
}));
},
function error(error){
console.log(error);
console.error(error);
}
);