85 lines
2.8 KiB
JavaScript
85 lines
2.8 KiB
JavaScript
/**
|
|
* API Component Interface - Do not construct objects of this type directly
|
|
* @param componentType
|
|
* @param linkedObjects
|
|
* @param loaded (indicates whether the linked Objects for this component has been loaded)
|
|
* @param parentEntity
|
|
* @constructor
|
|
*/
|
|
GameLib.API.Component = function(
|
|
componentType,
|
|
linkedObjects,
|
|
loaded,
|
|
parentEntity
|
|
) {
|
|
this.componentType = componentType;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(linkedObjects)) {
|
|
linkedObjects = {};
|
|
}
|
|
this.linkedObjects = linkedObjects;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(loaded)) {
|
|
loaded = false;
|
|
}
|
|
this.loaded = loaded;
|
|
|
|
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
|
|
parentEntity = null;
|
|
}
|
|
this.parentEntity = parentEntity;
|
|
};
|
|
|
|
/**
|
|
* 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) {
|
|
|
|
if (objectComponent.componentType == GameLib.Component.COMPONENT_PATH_FOLLOWING) {
|
|
return GameLib.D3.API.PathFollowing.FromObjectComponent(objectComponent);
|
|
}
|
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_RENDERER) {
|
|
return GameLib.D3.API.Renderer.FromObjectComponent(objectComponent);
|
|
}
|
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_COMPOSER) {
|
|
return GameLib.D3.API.Composer.FromObjectComponent(objectComponent);
|
|
}
|
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_PASS) {
|
|
return GameLib.D3.API.Pass.FromObjectComponent(objectComponent);
|
|
}
|
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_LOOK_AT) {
|
|
return GameLib.D3.API.LookAt.FromObjectComponent(objectComponent);
|
|
}
|
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_FOLLOW) {
|
|
return GameLib.D3.API.Follow.FromObjectComponent(objectComponent);
|
|
}
|
|
|
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_RENDER_TARGET) {
|
|
return GameLib.D3.API.RenderTarget.FromObjectComponent(objectComponent);
|
|
}
|
|
|
|
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;
|
|
}
|
|
};
|