r3-legacy/src/game-lib-entity.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-10-28 15:30:15 +02:00
GameLib.D3.Entity = function(
meshId,
componentIds
) {
this.meshId = meshId;
if (typeof componentIds == 'undefined') {
componentIds = [];
}
this.componentIds = componentIds;
2016-11-01 09:43:36 +01:00
this.parentScene = null;
this.mesh = null;
};
GameLib.D3.Entity.prototype.onUpdate = function(
deltaTime
) {
for(var c in this.componentIds) {
var componentId = this.componentIds[c];
if(this.parentScene.componentIdToComponent[componentId]) {
this.parentScene.componentIdToComponent[componentId].onUpdate(deltaTime, this);
}
}
};
GameLib.D3.Entity.prototype.onLateUpdate = function(
deltaTime
) {
for(var c in this.componentIds) {
var componentId = this.componentIds[c];
if(this.parentScene.componentIdToComponent[componentId]) {
this.parentScene.componentIdToComponent[componentId].onLateUpdate(deltaTime, this);
}
}
};
GameLib.D3.Entity.prototype.onRegistered = function(
parentScene
) {
this.parentScene = parentScene;
if(this.meshId != null && parentScene.meshIdToMesh[this.meshId]) {
parentScene.threeScene.add(parentScene.meshIdToMesh[this.meshId]);
this.mesh = parentScene.meshIdToMesh[this.meshId];
}
};
GameLib.D3.Entity.prototype.addComponentId = function(
componentId
) {
this.componentIds.push(componentId);
};
GameLib.D3.Entity.prototype.addComponent = function(
component
) {
this.parentScene.registerComponent(component);
this.componentIds.push(component.componentId);
component.setParentEntity(this);
component.onSetParentEntity(this.parentScene, this);
2016-10-28 15:30:15 +02:00
};