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