naive extension of classes.

beta.r3js.org
polygonboutique 2016-11-01 10:30:55 +01:00
parent 92c7b6db6c
commit 2098af0c7e
4 changed files with 73 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -166,6 +166,30 @@ GameLib.D3.Color = function(r, g, b, a) {
this.b = b;
this.a = a;
};
GameLib.D3.ComponentColorFlash = function(
componentId
) {
this.componentId = componentId || GameLib.D3.Tools.RandomId();
this.parentEntity = null;
// Todo: this should be executed somewhere in game-lib-z, so that we don't execute it on every construction of an object.
GameLib.D3.Utils.Extend(GameLib.D3.ComponentColorFlash, GameLib.D3.ComponentInterface);
};
///////////////////////// Methods to override //////////////////////////
GameLib.D3.ComponentColorFlash.prototype.onUpdate = function(
deltaTime,
parentEntity
) {
this.parentEntity.mesh.material.color = new THREE.Color(Math.random(), Math.random(), Math.random());
};
GameLib.D3.ComponentColorFlash.prototype.onSetParentEntity = function(
parentScene,
parentEntity
) {
parentEntity.mesh.material = new THREE.MeshBasicMaterial();
};
GameLib.D3.ComponentInterface = function(
componentId
) {
@ -4763,6 +4787,17 @@ GameLib.D3.TriangleFace.prototype.equals = function(triangle) {
};
GameLib.D3.Utils = function() {};
GameLib.D3.Utils.Extend = function(
child, // child class
parent // parent class
) {
for(var prop in parent.prototype) {
if(!child.prototype[prop]) {
child.prototype[prop] = parent.prototype[prop];
}
}
};
GameLib.D3.Vector2 = function(x, y) {
this.x = 0;

View File

@ -0,0 +1,24 @@
GameLib.D3.ComponentColorFlash = function(
componentId
) {
this.componentId = componentId || GameLib.D3.Tools.RandomId();
this.parentEntity = null;
// Todo: this should be executed somewhere in game-lib-z, so that we don't execute it on every construction of an object.
GameLib.D3.Utils.Extend(GameLib.D3.ComponentColorFlash, GameLib.D3.ComponentInterface);
};
///////////////////////// Methods to override //////////////////////////
GameLib.D3.ComponentColorFlash.prototype.onUpdate = function(
deltaTime,
parentEntity
) {
this.parentEntity.mesh.material.color = new THREE.Color(Math.random(), Math.random(), Math.random());
};
GameLib.D3.ComponentColorFlash.prototype.onSetParentEntity = function(
parentScene,
parentEntity
) {
parentEntity.mesh.material = new THREE.MeshBasicMaterial();
};

11
src/game-lib-utils.js Normal file
View File

@ -0,0 +1,11 @@
GameLib.D3.Utils = function() {};
GameLib.D3.Utils.Extend = function(
child, // child class
parent // parent class
) {
for(var prop in parent.prototype) {
if(!child.prototype[prop]) {
child.prototype[prop] = parent.prototype[prop];
}
}
};