r3-legacy/src/game-lib-gui-runtime.js

60 lines
1.2 KiB
JavaScript

/**
* GUI
* @param id
* @param name
* @param guiType
* @constructor
*/
GameLib.GUIRuntime = function(
id,
name,
guiType
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'GUI (' + id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(guiType)) {
guiType = GameLib.GUIRuntime.TYPE_DAT_GUI;
}
this.guiType = guiType;
this.createInstance();
};
/**
* GameLib.GUIRuntime Types
* @type {number}
*/
GameLib.GUIRuntime.TYPE_DAT_GUI = 0x1;
GameLib.GUIRuntime.prototype.createInstance = function() {
if (this.guiType === GameLib.GUIRuntime.TYPE_DAT_GUI) {
this.instance = dat.GUI;
} else {
this.instance = null;
}
};
GameLib.GUIRuntime.prototype.updateInstance = function(property) {
if (property === 'guiType') {
this.createInstance();
}
};
/**
* Logs a warning and throws an error if not cannon
*/
GameLib.GUIRuntime.prototype.isNotDatGuiThrow = function() {
if (this.instance !== dat.GUI) {
console.error('Only dat.gui supported');
throw new Error('Only dat.gui supported');
}
};