UNPKG

3.3 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6
7var _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; }; })();
8
9function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
10
11function _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); } }
12
13function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
14
15var _constantsUnits = require('./constants/units');
16
17var _Floor = require('./Floor');
18
19var _Floor2 = _interopRequireDefault(_Floor);
20
21var LevelLoader = (function () {
22 function LevelLoader(level) {
23 _classCallCheck(this, LevelLoader);
24
25 this._level = level;
26 }
27
28 _createClass(LevelLoader, [{
29 key: 'load',
30 value: function load(config, profile) {
31 var _this = this;
32
33 this._level.timeBonus = config.timeBonus;
34
35 var _config$floor$size = config.floor.size;
36 var width = _config$floor$size.width;
37 var height = _config$floor$size.height;
38
39 this._level.floor = new _Floor2['default'](width, height);
40
41 var _config$floor$stairs = config.floor.stairs;
42 var x = _config$floor$stairs.x;
43 var y = _config$floor$stairs.y;
44
45 this._level.floor.placeStairs(x, y);
46
47 config.floor.units.forEach(function (unit) {
48 if (unit.type === 'warrior') {
49 var warriorName = profile.warriorName;
50 var playerCode = profile.playerCode;
51
52 var abilities = [].concat(_toConsumableArray(unit.abilities), _toConsumableArray(profile.abilities));
53 _this._placeWarrior(warriorName, playerCode, unit.x, unit.y, unit.facing, abilities);
54 } else {
55 _this._placeUnit(unit.type, unit.x, unit.y, unit.facing, unit.abilities);
56 }
57 });
58 }
59 }, {
60 key: '_placeUnit',
61 value: function _placeUnit(type, x, y, facing) {
62 var abilities = arguments.length <= 4 || arguments[4] === undefined ? [] : arguments[4];
63
64 if (!(type in _constantsUnits.UNITS)) {
65 throw new Error('Unknown unit \'' + type + '\'.');
66 }
67
68 var unit = new _constantsUnits.UNITS[type]();
69 unit.addAbilities(abilities);
70 this._level.floor.addUnit(unit, x, y, facing);
71 return unit;
72 }
73 }, {
74 key: '_placeWarrior',
75 value: function _placeWarrior(name, playerCode, x, y, facing, abilities) {
76 var warrior = this._placeUnit('warrior', x, y, facing, abilities);
77 warrior.name = name;
78 warrior.playerCode = playerCode;
79 this._level.warrior = warrior;
80 }
81 }]);
82
83 return LevelLoader;
84})();
85
86exports['default'] = LevelLoader;
87module.exports = exports['default'];
\No newline at end of file