warriorjs-engine
Version:
The bowels of WarriorJS
89 lines (74 loc) • 3.48 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
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 _directions = require('../constants/directions');
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Ability = function () {
function Ability(unit) {
_classCallCheck(this, Ability);
this._unit = unit;
}
_createClass(Ability, [{
key: 'passTurn',
value: function passTurn() {
// Callback which is triggered every turn
}
}, {
key: 'perform',
value: function perform() {
// To be overriden by subclass
}
}, {
key: '_offset',
value: function _offset(direction) {
var forward = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1];
var right = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
if (direction === _directions.FORWARD) {
return [forward, -right];
} else if (direction === _directions.BACKWARD) {
return [-forward, right];
} else if (direction === _directions.RIGHT) {
return [right, forward];
} else if (direction === _directions.LEFT) {
return [-right, -forward];
}
throw new Error('Unknown direction \'' + direction + '\'.');
}
}, {
key: '_getSpace',
value: function _getSpace(direction) {
var _unit$position;
var forward = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1];
var right = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
return (_unit$position = this._unit.position).getRelativeSpace.apply(_unit$position, _toConsumableArray(this._offset(direction, forward, right)));
}
}, {
key: '_getUnit',
value: function _getUnit(direction) {
var forward = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1];
var right = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
return this._getSpace(direction, forward, right).unit;
}
}, {
key: '_verifyDirection',
value: function _verifyDirection(direction) {
if (!_directions.RELATIVE_DIRECTION_ARRAY.includes(direction)) {
var validDirections = _directions.RELATIVE_DIRECTION_ARRAY.map(function (validDirection) {
return '\'' + validDirection + '\'';
}).join(', ');
throw new Error('Unknown direction \'' + direction + '\'. Should be one of: ' + validDirections + '.');
}
}
}, {
key: 'description',
get: function get() {
return this._description;
}
}]);
return Ability;
}();
exports.default = Ability;
;