2017-01-06 16:53:53 +01:00
|
|
|
/**
|
|
|
|
* API Component Interface - Do not construct objects of this type directly
|
|
|
|
* @param componentType
|
|
|
|
* @param parentEntity
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.API.Component = function(
|
|
|
|
componentType,
|
2017-06-13 14:09:18 +02:00
|
|
|
parentEntity
|
2017-01-06 16:53:53 +01:00
|
|
|
) {
|
|
|
|
this.componentType = componentType;
|
2017-02-01 16:09:34 +01:00
|
|
|
|
2017-01-06 16:53:53 +01:00
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
|
|
parentEntity = null;
|
|
|
|
}
|
|
|
|
this.parentEntity = parentEntity;
|
2017-05-16 11:50:06 +02:00
|
|
|
|
2017-01-06 16:53:53 +01:00
|
|
|
};
|
|
|
|
|
2017-06-01 16:58:22 +02:00
|
|
|
GameLib.API.Component.prototype = Object.create(GameLib.Event.prototype);
|
|
|
|
GameLib.API.Component.prototype.constructor = GameLib.API.Component;
|
|
|
|
|
2017-01-06 16:53:53 +01:00
|
|
|
/**
|
|
|
|
* Returns an API component from an object component
|
|
|
|
* @param objectComponent (should be an ID string - components get loaded and linked)
|
|
|
|
* @returns {GameLib.API.Component}
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
GameLib.API.Component.FromObjectComponent = function(objectComponent) {
|
|
|
|
if (objectComponent instanceof Object) {
|
|
|
|
|
2017-01-19 17:50:11 +01:00
|
|
|
if (objectComponent.componentType == GameLib.Component.COMPONENT_PATH_FOLLOWING) {
|
2017-01-06 16:53:53 +01:00
|
|
|
return GameLib.D3.API.PathFollowing.FromObjectComponent(objectComponent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_RENDERER) {
|
|
|
|
return GameLib.D3.API.Renderer.FromObjectComponent(objectComponent);
|
|
|
|
}
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_COMPOSER) {
|
|
|
|
return GameLib.D3.API.Composer.FromObjectComponent(objectComponent);
|
2017-01-09 15:20:48 +01:00
|
|
|
}
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_PASS) {
|
|
|
|
return GameLib.D3.API.Pass.FromObjectComponent(objectComponent);
|
2017-01-09 15:20:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_LOOK_AT) {
|
2017-01-06 16:53:53 +01:00
|
|
|
return GameLib.D3.API.LookAt.FromObjectComponent(objectComponent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_FOLLOW) {
|
|
|
|
return GameLib.D3.API.Follow.FromObjectComponent(objectComponent);
|
|
|
|
}
|
|
|
|
|
2017-01-10 17:04:30 +01:00
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_RENDER_TARGET) {
|
|
|
|
return GameLib.D3.API.RenderTarget.FromObjectComponent(objectComponent);
|
2017-01-06 16:53:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_SPLINE) {
|
|
|
|
return GameLib.D3.API.Spline.FromObjectComponent(objectComponent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_INPUT_DRIVE) {
|
|
|
|
return GameLib.D3.API.Input.Drive.FromObjectComponent(objectComponent);
|
|
|
|
}
|
|
|
|
|
|
|
|
console.warn('No API Component was associated with this Object');
|
|
|
|
throw new Error('No API Component was associated with this Object');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return objectComponent;
|
|
|
|
}
|
|
|
|
};
|