71 lines
1.7 KiB
JavaScript
71 lines
1.7 KiB
JavaScript
|
/**
|
||
|
* Graphics
|
||
|
* @constructor
|
||
|
* @param apiGraphics
|
||
|
*/
|
||
|
GameLib.GraphicsRuntime = function(
|
||
|
apiGraphics
|
||
|
) {
|
||
|
|
||
|
if (GameLib.Utils.UndefinedOrNull(apiGraphics)) {
|
||
|
apiGraphics = {
|
||
|
graphicsType : GameLib.API.GraphicsRuntime.GRAPHICS_TYPE_NONE
|
||
|
};
|
||
|
}
|
||
|
|
||
|
GameLib.API.GraphicsRuntime.call(
|
||
|
this,
|
||
|
apiGraphics.id,
|
||
|
apiGraphics.name,
|
||
|
apiGraphics.graphicsType,
|
||
|
apiGraphics.parentEntity
|
||
|
);
|
||
|
|
||
|
GameLib.Component.call(this);
|
||
|
};
|
||
|
|
||
|
GameLib.GraphicsRuntime.prototype = Object.create(GameLib.Component.prototype);
|
||
|
GameLib.GraphicsRuntime.prototype.constructor = GameLib.GraphicsRuntime;
|
||
|
|
||
|
GameLib.GraphicsRuntime.prototype.createInstance = function() {
|
||
|
console.log(this.graphicsType + ' graphics runtime created');
|
||
|
GameLib.Component.prototype.createInstance.call(this);
|
||
|
};
|
||
|
|
||
|
GameLib.GraphicsRuntime.prototype.updateInstance = function(property) {
|
||
|
|
||
|
if (property === 'graphicsType') {
|
||
|
var componentType = GameLib.API.Renderer.GetComponentType(this.graphicsType);
|
||
|
|
||
|
this.replace(componentType);
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||
|
};
|
||
|
|
||
|
GameLib.GraphicsRuntime.prototype.toApiObject = function(property) {
|
||
|
|
||
|
return new GameLib.API.GraphicsRuntime(
|
||
|
this.id,
|
||
|
this.name,
|
||
|
this.graphicsType,
|
||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||
|
);
|
||
|
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Logs a warning and throws an error if not cannon
|
||
|
*/
|
||
|
GameLib.GraphicsRuntime.prototype.isNotThreeThrow = function() {
|
||
|
if (this.instance !== THREE) {
|
||
|
console.error('Only THREE supported');
|
||
|
throw new Error('Only THREE supported');
|
||
|
}
|
||
|
};
|
||
|
|
||
|
GameLib.GraphicsRuntime.prototype.isThree = function() {
|
||
|
return (this.instance === THREE);
|
||
|
};
|