-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathapp.js
3903 lines (3118 loc) · 93.3 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Production steps of ECMA-262, Edition 6, 22.1.2.1
// Reference: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.from
if (!Array.from) {
Array.from = (function () {
var toStr = Object.prototype.toString;
var isCallable = function (fn) {
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
};
var toInteger = function (value) {
var number = Number(value);
if (isNaN(number)) { return 0; }
if (number === 0 || !isFinite(number)) { return number; }
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
};
var maxSafeInteger = Math.pow(2, 53) - 1;
var toLength = function (value) {
var len = toInteger(value);
return Math.min(Math.max(len, 0), maxSafeInteger);
};
// The length property of the from method is 1.
return function from(arrayLike/*, mapFn, thisArg */) {
// 1. Let C be the this value.
var C = this;
// 2. Let items be ToObject(arrayLike).
var items = Object(arrayLike);
// 3. ReturnIfAbrupt(items).
if (arrayLike == null) {
throw new TypeError("Array.from requires an array-like object - not null or undefined");
}
// 4. If mapfn is undefined, then let mapping be false.
var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
var T;
if (typeof mapFn !== 'undefined') {
// 5. else
// 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
if (!isCallable(mapFn)) {
throw new TypeError('Array.from: when provided, the second argument must be a function');
}
// 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (arguments.length > 2) {
T = arguments[2];
}
}
// 10. Let lenValue be Get(items, "length").
// 11. Let len be ToLength(lenValue).
var len = toLength(items.length);
// 13. If IsConstructor(C) is true, then
// 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
// 14. a. Else, Let A be ArrayCreate(len).
var A = isCallable(C) ? Object(new C(len)) : new Array(len);
// 16. Let k be 0.
var k = 0;
// 17. Repeat, while k < len… (also steps a - h)
var kValue;
while (k < len) {
kValue = items[k];
if (mapFn) {
A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
} else {
A[k] = kValue;
}
k += 1;
}
// 18. Let putStatus be Put(A, "length", len, true).
A.length = len;
// 20. Return A.
return A;
};
}());
}
if (!Array.prototype.includes) {
Array.prototype.includes = function(searchElement /*, fromIndex*/ ) {
"use strict";
var O = Object(this);
var len = parseInt(O.length, 10) || 0;
if (len === 0) { return false; }
var n = parseInt(arguments[1], 10) || 0;
var k;
if (n >= 0) {
k = n;
} else {
k = len + n;
if (k < 0) {k = 0;}
}
var currentElement;
while (k < len) {
currentElement = O[k];
if (searchElement === currentElement) { // FIXME NaN !== NaN
return true;
}
k++;
}
return false;
};
}
if (!("classList" in document.documentElement) && window.Element) {
(function () {
var prototype = Array.prototype,
indexOf = prototype.indexOf,
slice = prototype.slice,
push = prototype.push,
splice = prototype.splice,
join = prototype.join;
function DOMTokenList(elm) {
this._element = elm;
if (elm.className == this._classCache) { return; }
this._classCache = elm.className;
if (!this._classCache) { return; }
var classes = this._classCache.replace(/^\s+|\s+$/g,'').split(/\s+/);
for (var i = 0; i < classes.length; i++) {
push.call(this, classes[i]);
}
}
window.DOMTokenList = DOMTokenList;
function setToClassName(el, classes) {
el.className = classes.join(" ");
}
DOMTokenList.prototype = {
add: function(token) {
if (this.contains(token)) { return; }
push.call(this, token);
setToClassName(this._element, slice.call(this, 0));
},
contains: function(token) {
return (indexOf.call(this, token) != -1);
},
item: function(index) {
return this[index] || null;
},
remove: function(token) {
var i = indexOf.call(this, token);
if (i == -1) { return; }
splice.call(this, i, 1);
setToClassName(this._element, slice.call(this, 0));
},
toString: function() {
return join.call(this, " ");
},
toggle: function(token) {
if (indexOf.call(this, token) == -1) {
this.add(token);
return true;
} else {
this.remove(token);
return false;
}
}
};
function defineElementGetter (obj, prop, getter) {
if (Object.defineProperty) {
Object.defineProperty(obj, prop, {
get: getter
});
} else {
obj.__defineGetter__(prop, getter);
}
}
defineElementGetter(Element.prototype, "classList", function() {
return new DOMTokenList(this);
});
})();
}
;(function() {
if (!window.SVGElement) { return; }
var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
if (!("classList" in svg)) {
var d = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "classList");
Object.defineProperty(SVGElement.prototype, "classList", d);
}
})();
;(function() {
var testElement = document.createElement("_");
testElement.classList.add("c1", "c2");
if (!testElement.classList.contains("c2")) {
var createMethod = function(method) {
var original = DOMTokenList.prototype[method];
DOMTokenList.prototype[method] = function(token) {
var i, len = arguments.length;
for (i = 0; i < len; i++) {
token = arguments[i];
original.call(this, token);
}
};
};
createMethod("add");
createMethod("remove");
}
testElement.classList.toggle("c3", false);
if (testElement.classList.contains("c3")) {
var _toggle = DOMTokenList.prototype.toggle;
DOMTokenList.prototype.toggle = function(token, force) {
if (1 in arguments && !this.contains(token) === !force) {
return force;
} else {
return _toggle.call(this, token);
}
};
}
testElement = null;
})();
if (!Object.assign) {
Object.defineProperty(Object, "assign", {
enumerable: false,
configurable: true,
writable: true,
value: function(target) {
if (target === undefined || target === null) {
throw new TypeError("Cannot convert first argument to object");
}
var to = Object(target);
for (var i = 1; i < arguments.length; i++) {
var nextSource = arguments[i];
if (nextSource === undefined || nextSource === null) {
continue;
}
nextSource = Object(nextSource);
var keysArray = Object.keys(Object(nextSource));
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
var nextKey = keysArray[nextIndex];
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
if (desc !== undefined && desc.enumerable) {
to[nextKey] = nextSource[nextKey];
}
}
}
return to;
}
});
}
/*
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
*/
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define([ "exports" ], factory);
} else if (typeof exports === "object") {
factory(exports);
} else {
factory(root);
}
}(this, function (exports) {
if (exports.Promise) { return; }
/**
* @class A promise - value to be resolved in the future.
* Implements the "Promises/A+ 1.1" specification.
* @param {function} [resolver]
*/
var Promise = function(resolver) {
this._state = 0; /* 0 = pending, 1 = fulfilled, 2 = rejected */
this._value = null; /* fulfillment / rejection value */
this._timeout = null;
this._cb = {
fulfilled: [],
rejected: []
}
this._thenPromises = []; /* promises returned by then() */
if (resolver) { this._invokeResolver(resolver); }
}
Promise.resolve = function(value) {
return new this(function(resolve, reject) {
resolve(value);
});
}
Promise.reject = function(reason) {
return new this(function(resolve, reject) {
reject(reason);
});
}
/**
* Wait for all these promises to complete. One failed => this fails too.
*/
Promise.all = Promise.when = function(all) {
return new this(function(resolve, reject) {
var counter = 0;
var results = [];
all.forEach(function(promise, index) {
counter++;
promise.then(function(result) {
results[index] = result;
counter--;
if (!counter) { resolve(results); }
}, function(reason) {
counter = 1/0;
reject(reason);
});
});
});
}
Promise.race = function(all) {
return new this(function(resolve, reject) {
all.forEach(function(promise) {
promise.then(resolve, reject);
});
});
}
/**
* @param {function} onFulfilled To be called once this promise gets fulfilled
* @param {function} onRejected To be called once this promise gets rejected
* @returns {Promise}
*/
Promise.prototype.then = function(onFulfilled, onRejected) {
this._cb.fulfilled.push(onFulfilled);
this._cb.rejected.push(onRejected);
var thenPromise = new Promise();
this._thenPromises.push(thenPromise);
if (this._state > 0) { this._schedule(); }
/* 2.2.7. then must return a promise. */
return thenPromise;
}
/**
* Fulfill this promise with a given value
* @param {any} value
*/
Promise.prototype.fulfill = function(value) {
if (this._state != 0) { return this; }
this._state = 1;
this._value = value;
if (this._thenPromises.length) { this._schedule(); }
return this;
}
/**
* Reject this promise with a given value
* @param {any} value
*/
Promise.prototype.reject = function(value) {
if (this._state != 0) { return this; }
this._state = 2;
this._value = value;
if (this._thenPromises.length) { this._schedule(); }
return this;
}
Promise.prototype.resolve = function(x) {
/* 2.3.1. If promise and x refer to the same object, reject promise with a TypeError as the reason. */
if (x == this) {
this.reject(new TypeError("Promise resolved by its own instance"));
return;
}
/* 2.3.2. If x is a promise, adopt its state */
if (x instanceof this.constructor) {
x.chain(this);
return;
}
/* 2.3.3. Otherwise, if x is an object or function, */
if (x !== null && (typeof(x) == "object" || typeof(x) == "function")) {
try {
var then = x.then;
} catch (e) {
/* 2.3.3.2. If retrieving the property x.then results in a thrown exception e, reject promise with e as the reason. */
this.reject(e);
return;
}
if (typeof(then) == "function") {
/* 2.3.3.3. If then is a function, call it */
var called = false;
var resolvePromise = function(y) {
/* 2.3.3.3.1. If/when resolvePromise is called with a value y, run [[Resolve]](promise, y). */
if (called) { return; }
called = true;
this.resolve(y);
}
var rejectPromise = function(r) {
/* 2.3.3.3.2. If/when rejectPromise is called with a reason r, reject promise with r. */
if (called) { return; }
called = true;
this.reject(r);
}
try {
then.call(x, resolvePromise.bind(this), rejectPromise.bind(this));
} catch (e) { /* 2.3.3.3.4. If calling then throws an exception e, */
/* 2.3.3.3.4.1. If resolvePromise or rejectPromise have been called, ignore it. */
if (called) { return; }
/* 2.3.3.3.4.2. Otherwise, reject promise with e as the reason. */
this.reject(e);
}
} else {
/* 2.3.3.4 If then is not a function, fulfill promise with x. */
this.fulfill(x);
}
return;
}
/* 2.3.4. If x is not an object or function, fulfill promise with x. */
this.fulfill(x);
}
/**
* Pass this promise's resolved value to another promise
* @param {Promise} promise
*/
Promise.prototype.chain = function(promise) {
var resolve = function(value) {
promise.resolve(value);
}
var reject = function(value) {
promise.reject(value);
}
return this.then(resolve, reject);
}
/**
* @param {function} onRejected To be called once this promise gets rejected
* @returns {Promise}
*/
Promise.prototype["catch"] = function(onRejected) {
return this.then(null, onRejected);
}
Promise.prototype._schedule = function() {
if (this._timeout) { return; } /* resolution already scheduled */
this._timeout = setTimeout(this._processQueue.bind(this), 0);
}
Promise.prototype._processQueue = function() {
this._timeout = null;
while (this._thenPromises.length) {
var onFulfilled = this._cb.fulfilled.shift();
var onRejected = this._cb.rejected.shift();
this._executeCallback(this._state == 1 ? onFulfilled : onRejected);
}
}
Promise.prototype._executeCallback = function(cb) {
var thenPromise = this._thenPromises.shift();
if (typeof(cb) != "function") {
if (this._state == 1) {
/* 2.2.7.3. If onFulfilled is not a function and promise1 is fulfilled, promise2 must be fulfilled with the same value. */
thenPromise.fulfill(this._value);
} else {
/* 2.2.7.4. If onRejected is not a function and promise1 is rejected, promise2 must be rejected with the same reason. */
thenPromise.reject(this._value);
}
return;
}
try {
var x = cb(this._value);
/* 2.2.7.1. If either onFulfilled or onRejected returns a value x, run the Promise Resolution Procedure [[Resolve]](promise2, x). */
thenPromise.resolve(x);
} catch (e) {
/* 2.2.7.2. If either onFulfilled or onRejected throws an exception, promise2 must be rejected with the thrown exception as the reason. */
thenPromise.reject(e);
}
}
Promise.prototype._invokeResolver = function(resolver) {
try {
resolver(this.resolve.bind(this), this.reject.bind(this));
} catch (e) {
this.reject(e);
}
}
exports.Promise = Promise;
}));
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; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
(function () {
'use strict';
var _COLORS, _SUFFIXES, _COMBAT_OPTIONS, _LABELS;
var XY = function () {
XY.fromString = function fromString(str) {
var numbers = str.split(",").map(Number);
return new (Function.prototype.bind.apply(this, [null].concat(numbers)))();
};
function XY() {
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
_classCallCheck(this, XY);
this.x = x;
this.y = y;
}
XY.prototype.clone = function clone() {
return new XY(this.x, this.y);
};
XY.prototype.toString = function toString() {
return this.x + "," + this.y;
};
XY.prototype.is = function is(xy) {
return this.x == xy.x && this.y == xy.y;
};
XY.prototype.norm8 = function norm8() {
return Math.max(Math.abs(this.x), Math.abs(this.y));
};
XY.prototype.norm4 = function norm4() {
return Math.abs(this.x) + Math.abs(this.y);
};
XY.prototype.norm = function norm() {
return Math.sqrt(this.x * this.x + this.y * this.y);
};
XY.prototype.dist8 = function dist8(xy) {
return this.minus(xy).norm8();
};
XY.prototype.dist4 = function dist4(xy) {
return this.minus(xy).norm4();
};
XY.prototype.dist = function dist(xy) {
return this.minus(xy).norm();
};
XY.prototype.lerp = function lerp(xy, frac) {
var diff = xy.minus(this);
return this.plus(diff.scale(frac));
};
XY.prototype.scale = function scale(sx) {
var sy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : sx;
return new XY(this.x * sx, this.y * sy);
};
XY.prototype.plus = function plus(xy) {
return new XY(this.x + xy.x, this.y + xy.y);
};
XY.prototype.minus = function minus(xy) {
return this.plus(xy.scale(-1));
};
XY.prototype.round = function round() {
return new XY(Math.round(this.x), Math.round(this.y));
};
XY.prototype.floor = function floor() {
return new XY(Math.floor(this.x), Math.floor(this.y));
};
XY.prototype.ceil = function ceil() {
return new XY(Math.ceil(this.x), Math.ceil(this.y));
};
XY.prototype.mod = function mod(xy) {
var x = this.x % xy.x;
if (x < 0) {
x += xy.x;
}
var y = this.y % xy.y;
if (y < 0) {
y += xy.y;
}
return new XY(x, y);
};
return XY;
}();
var SPEED = 10; // cells per second
var Animation = function () {
function Animation() {
_classCallCheck(this, Animation);
this._items = [];
this._ts = null;
this._resolve = null;
}
Animation.prototype.add = function add(item) {
this._items.push(item);
item.cell.animated = item.from;
};
Animation.prototype.start = function start(drawCallback) {
var _this = this;
var promise = new Promise(function (resolve) {
return _this._resolve = resolve;
});
this._drawCallback = drawCallback;
this._ts = Date.now();
this._step();
return promise;
};
Animation.prototype._step = function _step() {
var _this2 = this;
var time = Date.now() - this._ts;
var i = this._items.length;
while (i-- > 0) {
/* down so we can splice */
var item = this._items[i];
var finished = this._stepItem(item, time);
if (finished) {
this._items.splice(i, 1);
item.cell.animated = null;
}
}
this._drawCallback();
if (this._items.length > 0) {
requestAnimationFrame(function () {
return _this2._step();
});
} else {
this._resolve();
}
};
Animation.prototype._stepItem = function _stepItem(item, time) {
var dist = item.from.dist8(item.to);
var frac = time / 1000 * SPEED / dist;
var finished = false;
if (frac >= 1) {
finished = true;
frac = 1;
}
item.cell.animated = item.from.lerp(item.to, frac);
return finished;
};
return Animation;
}();
var BLOCKS_NONE = 0;
var BLOCKS_MOVEMENT = 1;
var BLOCKS_LIGHT = 2;
var Entity = function () {
function Entity(visual) {
_classCallCheck(this, Entity);
this._visual = visual;
this.blocks = BLOCKS_NONE;
}
Entity.prototype.getVisual = function getVisual() {
return this._visual;
};
Entity.prototype.toString = function toString() {
return this._visual.name;
};
Entity.prototype.describeThe = function describeThe() {
return "the " + this;
};
Entity.prototype.describeA = function describeA() {
var first = this._visual.name.charAt(0);
var article = first.match(/[aeiou]/i) ? "an" : "a";
return article + " " + this;
};
return Entity;
}();
String.format.map.the = "describeThe";
String.format.map.a = "describeA";
var storage = Object.create(null);
function publish(message, publisher, data) {
var subscribers = storage[message] || [];
subscribers.forEach(function (subscriber) {
typeof subscriber == "function" ? subscriber(message, publisher, data) : subscriber.handleMessage(message, publisher, data);
});
}
function subscribe(message, subscriber) {
if (!(message in storage)) {
storage[message] = [];
}
storage[message].push(subscriber);
}
var Inventory = function () {
function Inventory() {
_classCallCheck(this, Inventory);
this._items = [];
}
Inventory.prototype.getItems = function getItems() {
return this._items;
};
Inventory.prototype.getItemByType = function getItemByType(type) {
return this._items.filter(function (i) {
return i.getType() == type;
})[0];
};
Inventory.prototype.removeItem = function removeItem(item) {
var index = this._items.indexOf(item);
if (index > -1) {
this._items.splice(index, 1);
}
publish("status-change");
return this;
};
Inventory.prototype.addItem = function addItem(item) {
this._items.push(item);
publish("status-change");
return this;
};
return Inventory;
}();
var queue = [];
function add(actor) {
queue.push(actor);
}
function clear() {
queue = [];
}
function remove(actor) {
var index = queue.indexOf(actor);
if (index > -1) {
queue.splice(index, 1);
}
}
function loop() {
if (!queue.length) {
return;
} // endgame
var actor = queue.shift();
queue.push(actor);
actor.act().then(loop);
}
var node = void 0;
var current = null;
function add$1() {
var str = String.format.apply(String, arguments);
str = str.replace(/{(.*?)}(.*?){}/g, function (match, color, str) {
return "<span style=\"color:" + color + "\">" + str + "</span>";
});
str = str.replace(/\n/g, "<br/>");
var item = document.createElement("span");
item.innerHTML = str + " ";
current.appendChild(item);
}
function pause() {
if (current && current.childNodes.length == 0) {
return;
}
current = document.createElement("p");
node.appendChild(current);
while (node.childNodes.length > 50) {
node.removeChild(node.firstChild);
}
}
function init$2(n) {
node = n;
node.classList.remove("hidden");
pause();
setInterval(function () {
node.scrollTop += 3;
}, 20);
}
var Brambles = function (_Entity) {
_inherits(Brambles, _Entity);
function Brambles() {
_classCallCheck(this, Brambles);
return _possibleConstructorReturn(this, _Entity.call(this, { ch: "%", fg: "#483", name: "dense brambles" }));
}
Brambles.prototype.describeA = function describeA() {
return this.toString();
};
return Brambles;
}(Entity);
var Princess = function (_Entity2) {
_inherits(Princess, _Entity2);
function Princess() {
_classCallCheck(this, Princess);
var _this4 = _possibleConstructorReturn(this, _Entity2.call(this, { ch: "P", fg: "#ff0", name: "princess" }));
_this4.blocks = BLOCKS_MOVEMENT;
return _this4;
}
return Princess;
}(Entity);
var Pillar = function (_Entity3) {
_inherits(Pillar, _Entity3);
function Pillar() {
_classCallCheck(this, Pillar);
var _this5 = _possibleConstructorReturn(this, _Entity3.call(this, { ch: "T", fg: "#fff", name: "pillar" }));
_this5.blocks = BLOCKS_MOVEMENT;
return _this5;
}
return Pillar;
}(Entity);
var Floor = function (_Entity4) {
_inherits(Floor, _Entity4);
function Floor() {
_classCallCheck(this, Floor);
return _possibleConstructorReturn(this, _Entity4.call(this, { ch: ".", fg: "#aaa", name: "stone floor" }));
}
return Floor;
}(Entity);
var Wall = function (_Entity5) {
_inherits(Wall, _Entity5);
function Wall() {
_classCallCheck(this, Wall);
var _this7 = _possibleConstructorReturn(this, _Entity5.call(this, { ch: "#", fg: "#666", name: "solid wall" }));
_this7.blocks = BLOCKS_LIGHT;
return _this7;
}
return Wall;
}(Entity);
var Grass = function (_Entity6) {
_inherits(Grass, _Entity6);
function Grass(ch) {
_classCallCheck(this, Grass);
return _possibleConstructorReturn(this, _Entity6.call(this, { ch: ch, fg: "#693" }));
}
return Grass;
}(Entity);
var Tree = function (_Entity7) {
_inherits(Tree, _Entity7);
function Tree() {
_classCallCheck(this, Tree);
return _possibleConstructorReturn(this, _Entity7.call(this, { ch: "T", fg: "green" }));
}
return Tree;
}(Entity);
var Door = function (_Entity8) {
_inherits(Door, _Entity8);
function Door(closed) {
_classCallCheck(this, Door);
var _this10 = _possibleConstructorReturn(this, _Entity8.call(this, { ch: "/", fg: "#963" }));
closed ? _this10._close() : _this10._open();
return _this10;
}
Door.prototype.isOpen = function isOpen() {
return this._isOpen;
};
Door.prototype._close = function _close() {
this.blocks = BLOCKS_LIGHT;
this._visual.ch = "+";
this._isOpen = false;
this._visual.name = "closed door";
};
Door.prototype._open = function _open() {
this.blocks = BLOCKS_NONE;
this._visual.ch = "/";
this._isOpen = true;
this._visual.name = "open door";
};
Door.prototype.close = function close() {
this._close();
publish("topology-change", this);
};
Door.prototype.open = function open() {
this._open();
publish("topology-change", this);
};
return Door;
}(Entity);
var Staircase = function (_Entity9) {
_inherits(Staircase, _Entity9);
function Staircase(up, callback) {
_classCallCheck(this, Staircase);
var ch = up ? "<" : ">";
var fg = "#aaa";
var name = "staircase leading " + (up ? "up" : "down");
var _this11 = _possibleConstructorReturn(this, _Entity9.call(this, { ch: ch, fg: fg, name: name }));
_this11._callback = callback;
return _this11;
}
Staircase.prototype.activate = function activate(who) {