maniajs
Version:
ManiaPlanet (Dedicated) Server Controller.
206 lines (159 loc) • 7.87 kB
JavaScript
/**
* UI Facade
*/
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _path = require('path');
var path = _interopRequireWildcard(_path);
var _async = require('async');
var async = _interopRequireWildcard(_async);
var _baseFacade = require('./../lib/base-facade');
var _baseFacade2 = _interopRequireDefault(_baseFacade);
var _uiManager = require('./ui-manager');
var _uiManager2 = _interopRequireDefault(_uiManager);
var _interface = require('./interface');
var _interface2 = _interopRequireDefault(_interface);
var _generic = require('./generic');
var _generic2 = _interopRequireDefault(_generic);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/**
* UI Facade
*
* @class UIFacade
* @type {UIFacade}
*
* @property {{}} interfaces Interfaces, indexed by player login.
* @property {UIManager|{}} manager UI Manager
*/
var UIFacade = function (_Facade) {
_inherits(UIFacade, _Facade);
function UIFacade(app) {
_classCallCheck(this, UIFacade);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(UIFacade).call(this, app));
_this.manager = new _uiManager2.default(app);
_this.generic = new _generic2.default(app);
_this.stack = [];
return _this;
}
/**
* Prepare Component
*
* @return {Promise}
*/
_createClass(UIFacade, [{
key: 'init',
value: function init() {
return Promise.resolve();
}
/**
* Run Component
* @return {Promise}
*/
}, {
key: 'run',
value: function run() {
// Starting, will start the loop for checking and updating UI.
this.manager.start();
return Promise.resolve();
}
/**
* Exit Handling.
*/
}, {
key: 'stop',
value: function stop() {}
/**
* Get a builder instance.
*
* @param {{}} context Give the plugin class, or app class (for core).
* @param {string} viewName View File Name.
* @param {number} [version] Optional manialink version (defaults to 2)
* @param {string} [idSuffix] Optional unique id suffix.
*/
}, {
key: 'build',
value: function build(context, viewName, version, idSuffix) {
version = version || 2;
idSuffix = idSuffix || '';
// Determinate if running from plugin.
var plugin = false;
var baseDirectory = __dirname + '/view/';
if (context.hasOwnProperty('directory')) {
plugin = context;
baseDirectory = context.directory + '/view/';
}
if (!viewName.endsWith('.hbs')) {
viewName += '.hbs';
}
return new _interface2.default(this.app, this, path.normalize(baseDirectory + viewName), plugin, version, idSuffix);
}
/**
* Prepare List Interface for given column metadata, and given data. To Display, do .display().
*
* => Click on column > subscribe on events you provided with the event in columns.
* => Returning parameter will be the record on that position.
*
* When close is called the view will be vanished automatically! But you still need to cleanup your variables!
* When next/prev is called, the data will be automatically sliced and used. (the events will still be called).
*
* @param {string} title Title of list.
* @param {string} player Player Login (single login!).
* @param {[{name: {string}, field: {string}, width: {number}, [level]: {number}, [event]: {string}}]} columns Columns to define.
* @param {[{}]} data Array with objects. Give a custom manialink with the 'custom' key. This will be injected into the row!
*
* @returns {InterfaceBuilder|boolean} Interface on success, false on failure!
*/
}, {
key: 'list',
value: function list(title, player, columns, data) {
return this.generic.list(title, player, columns, data);
}
/**
* Prepare and make Alert interface. To display call .display() on the result.
*
* @param {string} title Title Text
* @param {string} message Message Text
* @param {string[]|string} players Player Logins to display to, empty for all players, single string for only one login
* @param {string} [size] Size, could be 'sm', 'md' or 'lg'. (small to big). Default 'md'.
* @param {string} [button] Button text, default 'OK'
* @param {string} [iconstyle] Icon Style, default 'Icons128x128_1'
* @param {string} [iconsubstyle] Icon Sub Style, default 'Editor'
*
* @returns {InterfaceBuilder} Interface Object, call .display() to display to the login(s).
*/
}, {
key: 'alert',
value: function alert(title, message, players, size, button, iconstyle, iconsubstyle) {
return this.generic.alert(title, message, players, size, button, iconstyle, iconsubstyle);
}
/**
* Prepare and make Confirm interface. To display call .display() on the result.
* To get answer, subscribe on the interface with .once('core_button_yes', function()); or core_button_no
*
* @param {string} title Title Text
* @param {string} message Message Text
* @param {string[]|string} players Player Logins to display to, empty for all players, single string for only one login
* @param {string} [size] Size, could be 'sm', 'md' or 'lg'. (small to big). Default 'md'.
* @param {string} [buttonYes] Button text, default 'Yes'
* @param {string} [buttonNo] Button text, default 'No'
* @param {string} [iconstyle] Icon Style, default 'Icons128x128_1'
* @param {string} [iconsubstyle] Icon Sub Style, default 'Options'
*
* @returns {InterfaceBuilder} Interface Object, call .display() to display to the login(s).
*/
}, {
key: 'confirm',
value: function confirm(title, message, players, size, buttonYes, buttonNo, iconstyle, iconsubstyle) {
return this.generic.confirm(title, message, players, size, buttonYes, buttonNo, iconstyle, iconsubstyle);
}
}]);
return UIFacade;
}(_baseFacade2.default);
exports.default = UIFacade;