r3-legacy/src/game-lib-d3-graphics.js

77 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-10-25 17:57:32 +02:00
/**
2017-01-13 16:19:51 +01:00
* Graphics
* @param id
* @param name
* @param graphicsType
2016-10-25 17:57:32 +02:00
* @constructor
*/
2016-11-21 16:08:39 +01:00
GameLib.D3.Graphics = function Graphics(
2017-01-13 16:19:51 +01:00
id,
name,
graphicsType
2016-10-25 17:57:32 +02:00
) {
2017-01-13 16:19:51 +01:00
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
2017-01-12 17:40:17 +01:00
}
2017-01-13 16:19:51 +01:00
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Graphics (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(graphicsType)) {
graphicsType = GameLib.D3.Graphics.GRAPHICS_TYPE_THREE;
}
this.graphicsType = graphicsType;
2017-01-12 17:40:17 +01:00
this.instance = this.createInstance();
};
/**
* GameLib.D3.Graphics Types
* @type {number}
*/
GameLib.D3.Graphics.GRAPHICS_TYPE_THREE = 0x1;
/**
* @returns {THREE.Graphics}
*/
GameLib.D3.Graphics.prototype.createInstance = function(update) {
var instance = null;
if (update) {
instance = this.instance;
} else {
instance = THREE;
}
return instance;
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Graphics.prototype.updateInstance = function() {
this.instance = this.createInstance(true);
};
2016-10-25 17:57:32 +02:00
/**
* True if THREE physics
* @returns {boolean}
*/
GameLib.D3.Graphics.prototype.isThree = function() {
return (this.graphicsType == GameLib.D3.Graphics.GRAPHICS_TYPE_THREE)
};
/**
* Logs a warning and throws an error if not cannon
*/
GameLib.D3.Graphics.prototype.isNotThreeThrow = function() {
if (this.graphicsType != GameLib.D3.Graphics.GRAPHICS_TYPE_THREE) {
console.warn('Only THREE supported for this function');
throw new Error('Only THREE supported for this function');
}
};