-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathink.js
7008 lines (5964 loc) · 212 KB
/
ink.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
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.inkjs = {})));
}(this, (function (exports) { 'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
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 _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
var inherits = function (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;
};
var possibleConstructorReturn = function (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;
};
var Path$1 = function () {
function Path() /*polymorphic constructor*/{
classCallCheck(this, Path);
this._isRelative;
this._components = [];
this._componentsString = null;
if (typeof arguments[0] == 'string') {
this.componentsString = arguments[0];
} else if (arguments[0] instanceof Component && arguments[1] instanceof Path) {
this._components.push(arguments[0]);
this._components = this._components.concat(arguments[1]._components);
} else if (arguments[0] instanceof Array) {
this._components = this._components.concat(arguments[0]);
this._isRelative = !!arguments[1];
}
}
createClass(Path, [{
key: "GetComponent",
value: function GetComponent(index) {
return this._components[index];
}
}, {
key: "PathByAppendingPath",
value: function PathByAppendingPath(pathToAppend) {
var p = new Path();
var upwardMoves = 0;
for (var i = 0; i < pathToAppend._components.length; ++i) {
if (pathToAppend._components[i].isParent) {
upwardMoves++;
} else {
break;
}
}
for (var i = 0; i < this._components.length - upwardMoves; ++i) {
p._components.push(this._components[i]);
}
for (var i = upwardMoves; i < pathToAppend._components.length; ++i) {
p._components.push(pathToAppend._components[i]);
}
return p;
}
}, {
key: "toString",
value: function toString() {
return this.componentsString;
}
}, {
key: "Equals",
value: function Equals(otherPath) {
if (otherPath == null) return false;
if (otherPath._components.length != this._components.length) return false;
if (otherPath.isRelative != this.isRelative) return false;
//the original code uses SequenceEqual here, so we need to iterate over the components manually.
for (var i = 0, l = otherPath._components.length; i < l; i++) {
//it's not quite clear whether this test should use Equals or a simple == operator, see https://github.com/y-lohse/inkjs/issues/22
if (!otherPath._components[i].Equals(this._components[i])) return false;
}
return true;
}
}, {
key: "PathByAppendingComponent",
value: function PathByAppendingComponent(c) {
var p = new Path();
p._components.push.apply(p._components, this._components);
p._components.push(c);
return p;
}
}, {
key: "isRelative",
get: function get$$1() {
return this._isRelative;
}
}, {
key: "componentCount",
get: function get$$1() {
return this._components.length;
}
}, {
key: "head",
get: function get$$1() {
if (this._components.length > 0) {
return this._components[0];
} else {
return null;
}
}
}, {
key: "tail",
get: function get$$1() {
if (this._components.length >= 2) {
var tailComps = this._components.slice(1, this._components.length); //careful, the original code uses length-1 here. This is because the second argument of List.GetRange is a number of elements to extract, wherease Array.slice uses an index
return new Path(tailComps);
} else {
return Path.self;
}
}
}, {
key: "length",
get: function get$$1() {
return this._components.length;
}
}, {
key: "lastComponent",
get: function get$$1() {
var lastComponentIdx = this._components.length - 1;
if (lastComponentIdx >= 0) {
return this._components[lastComponentIdx];
} else {
return null;
}
}
}, {
key: "containsNamedComponent",
get: function get$$1() {
for (var i = 0, l = this.components.length; i < l; i++) {
if (!this.components[i].isIndex) {
return true;
}
}
return false;
}
}, {
key: "componentsString",
get: function get$$1() {
if (this._componentsString == null) {
this._componentsString = this._components.join(".");
if (this.isRelative) this._componentsString = "." + this._componentsString;
}
return this._componentsString;
},
set: function set$$1(value) {
var _this = this;
this._components.length = 0;
this._componentsString = value;
if (this._componentsString == null || this._componentsString == '') return;
// When components start with ".", it indicates a relative path, e.g.
// .^.^.hello.5
// is equivalent to file system style path:
// ../../hello/5
if (this._componentsString[0] == '.') {
this._isRelative = true;
this._componentsString = this._componentsString.substring(1);
}
var componentStrings = this._componentsString.split('.');
componentStrings.forEach(function (str) {
//we need to distinguish between named components that start with a number, eg "42somewhere", and indexed components
//the normal parseInt won't do for the detection because it's too relaxed.
//see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
if (/^(\-|\+)?([0-9]+|Infinity)$/.test(str)) {
_this._components.push(new Component(parseInt(str)));
} else {
_this._components.push(new Component(str));
}
});
}
}], [{
key: "self",
get: function get$$1() {
var path = new Path();
path._isRelative = true;
return path;
}
}]);
return Path;
}();
var Component = function () {
function Component(indexOrName) {
classCallCheck(this, Component);
if (typeof indexOrName == 'string') {
this._index = -1;
this._name = indexOrName;
} else {
this._index = parseInt(indexOrName);
this._name = null;
}
}
createClass(Component, [{
key: "toString",
value: function toString() {
if (this.isIndex) {
return this.index.toString();
} else {
return this.name;
}
}
}, {
key: "Equals",
value: function Equals(otherComp) {
if (otherComp != null && otherComp.isIndex == this.isIndex) {
if (this.isIndex) {
return this.index == otherComp.index;
} else {
return this.name == otherComp.name;
}
}
return false;
}
}, {
key: "index",
get: function get$$1() {
return this._index;
}
}, {
key: "name",
get: function get$$1() {
return this._name;
}
}, {
key: "isIndex",
get: function get$$1() {
return this.index >= 0;
}
}, {
key: "isParent",
get: function get$$1() {
return this.name == Path$1.parentId;
}
}], [{
key: "ToParent",
value: function ToParent() {
return new Component(Path$1.parentId);
}
}]);
return Component;
}();
Path$1.parentId = "^";
Path$1.Component = Component;
var Object$1 = function () {
function Object() {
classCallCheck(this, Object);
this.parent = null;
this._path = null;
}
createClass(Object, [{
key: 'ResolvePath',
value: function ResolvePath(path) {
if (path.isRelative) {
var nearestContainer = this;
if (nearestContainer instanceof Container === false) {
if (this.parent == null) console.warn("Can't resolve relative path because we don't have a parent");
nearestContainer = this.parent;
if (nearestContainer.constructor.name !== 'Container') console.warn("Expected parent to be a container");
//Debug.Assert (path.GetComponent(0).isParent);
path = path.tail;
}
return nearestContainer.ContentAtPath(path);
} else {
return this.rootContentContainer.ContentAtPath(path);
}
}
}, {
key: 'ConvertPathToRelative',
value: function ConvertPathToRelative(globalPath) {
var ownPath = this.path;
var minPathLength = Math.min(globalPath.componentCount, ownPath.componentCount);
var lastSharedPathCompIndex = -1;
for (var i = 0; i < minPathLength; ++i) {
var ownComp = ownPath.GetComponent(i);
var otherComp = globalPath.GetComponent(i);
if (ownComp.Equals(otherComp)) {
lastSharedPathCompIndex = i;
} else {
break;
}
}
// No shared path components, so just use global path
if (lastSharedPathCompIndex == -1) return globalPath;
var numUpwardsMoves = ownPath.componentCount - 1 - lastSharedPathCompIndex;
var newPathComps = [];
for (var up = 0; up < numUpwardsMoves; ++up) {
newPathComps.push(Path$1.Component.ToParent());
}for (var down = lastSharedPathCompIndex + 1; down < globalPath.componentCount; ++down) {
newPathComps.push(globalPath.GetComponent(down));
}var relativePath = new Path$1(newPathComps, true);
return relativePath;
}
}, {
key: 'CompactPathString',
value: function CompactPathString(otherPath) {
var globalPathStr = null;
var relativePathStr = null;
if (otherPath.isRelative) {
relativePathStr = otherPath.componentsString;
globalPathStr = this.path.PathByAppendingPath(otherPath).componentsString;
} else {
var relativePath = this.ConvertPathToRelative(otherPath);
relativePathStr = relativePath.componentsString;
globalPathStr = otherPath.componentsString;
}
if (relativePathStr.length < globalPathStr.length) return relativePathStr;else return globalPathStr;
}
}, {
key: 'Copy',
value: function Copy() {
throw "Not Implemented";
}
//SetCHild works slightly diferently in the js implementation. SInce we can't pass an objets property by reference, we instead pass the object and the property string.
}, {
key: 'SetChild',
value: function SetChild(obj, prop, value) {
if (obj[prop]) obj[prop] = null;
obj[prop] = value;
if (obj[prop]) obj[prop].parent = this;
}
}, {
key: 'path',
get: function get$$1() {
if (this._path == null) {
if (this.parent == null) {
this._path = new Path$1();
} else {
// Maintain a Stack so that the order of the components
// is reversed when they're added to the Path.
// We're iterating up the hierarchy from the leaves/children to the root.
var comps = [];
var child = this;
// Container container = child.parent as Container;
var container = child.parent;
while (container instanceof Container) {
var namedChild = child;
if (namedChild.name && namedChild.hasValidName) {
comps.unshift(new Path$1.Component(namedChild.name));
} else {
comps.unshift(new Path$1.Component(container.content.indexOf(child)));
}
child = container;
// container = container.parent as Container;
container = container.parent;
}
this._path = new Path$1(comps);
}
}
return this._path;
}
}, {
key: 'rootContentContainer',
get: function get$$1() {
var ancestor = this;
while (ancestor.parent) {
ancestor = ancestor.parent;
}
return ancestor;
}
}]);
return Object;
}();
var StringBuilder = function () {
function StringBuilder(str) {
classCallCheck(this, StringBuilder);
str = typeof str !== 'undefined' ? str.toString() : '';
this._string = str;
}
createClass(StringBuilder, [{
key: 'Append',
value: function Append(str) {
this._string += str;
}
}, {
key: 'AppendLine',
value: function AppendLine(str) {
if (typeof str !== 'undefined') this.Append(str);
this._string += "\n";
}
}, {
key: 'AppendFormat',
value: function AppendFormat(format) {
//taken from http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format
var args = Array.prototype.slice.call(arguments, 1);
this._string += format.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined' ? args[number] : match;
});
}
}, {
key: 'toString',
value: function toString() {
return this._string;
}
}, {
key: 'Length',
get: function get$$1() {
return this._string.length;
}
}]);
return StringBuilder;
}();
var InkListItem = function () {
function InkListItem(fullNameOrOriginName, itemName) {
classCallCheck(this, InkListItem);
if (itemName !== undefined) {
this.originName = fullNameOrOriginName;
this.itemName = itemName;
} else {
var nameParts = fullNameOrOriginName.toString().split('.');
this.originName = nameParts[0];
this.itemName = nameParts[1];
}
}
createClass(InkListItem, [{
key: 'isNull',
value: function isNull() {
return this.originName == null && this.itemName == null;
}
}, {
key: 'toString',
value: function toString() {
return this.fullname;
}
}, {
key: 'Equals',
value: function Equals(obj) {
if (obj instanceof InkListItem) {
// var otherItem = (InkListItem)obj;
var otherItem = obj;
return otherItem.itemName == this.itemName && otherItem.originName == this.originName;
}
return false;
}
//GetHashCode not implemented
}, {
key: 'toString',
value: function toString() {
//WARNING: experimental. InkListItem are structs and are used as keys inside hashes. In js, we can't use an object as a key, as the key needs to be a string. C# gets around that with the internal GetHashCode, and the js equivalent to that is toString. So here, toString acts as C#'s GetHashCode
var originCode = '0';
var itemCode = this.itemName ? this.itemName.toString() : 'null';
if (this.originName != null) originCode = this.originName.toString();
return originCode + "." + itemCode;
}
}, {
key: 'fullName',
get: function get$$1() {
return (this.originName !== null ? this.originName : "?") + "." + this.itemName;
}
}], [{
key: 'Null',
value: function Null() {
return new InkListItem(null, null);
}
}]);
return InkListItem;
}();
//in C#, rawlists are based on dictionnary; the equivalent of a dictionnary in js is Object, but we can't use that or it will conflate dictionnary items and InkList class properties.
//instead InkList-js has a special _values property wich contains the actual "Dictionnary", and a few Dictionnary methods are re-implemented on InkList. This also means directly iterating over the InkList won't work as expected. Maybe we can return a proxy if that's required.
//@TODO: actually we could use a Map for this.
var InkList = function () {
function InkList(polymorphicArgument, originStory) {
var _this = this;
classCallCheck(this, InkList);
this._keys = {};
this._values = {};
this.origins = null;
this._originNames = null;
//polymorphioc constructor
if (polymorphicArgument) {
if (polymorphicArgument instanceof InkList) {
var otherList = polymorphicArgument;
otherList.forEach(function (kv) {
_this.Add(kv.Key, kv.Value);
});
this._originNames = otherList._originNames;
} else if (typeof polymorphicArgument === 'string') {
this.SetInitialOriginName(polymorphicArgument);
var def = null;
if (def = originStory.listDefinitions.TryGetListDefinition(polymorphicArgument, def)) {
this.origins = [def];
} else {
throw new Error("InkList origin could not be found in story when constructing new list: " + singleOriginListName);
}
} else if (polymorphicArgument.hasOwnProperty('Key') && polymorphicArgument.hasOwnProperty('Value')) {
var singleElement = polymorphicArgument;
this.Add(singleElement.Key, singleElement.Value);
}
}
}
createClass(InkList, [{
key: 'forEach',
value: function forEach(fn) {
for (var key in this._values) {
fn({
Key: this._keys[key],
Value: this._values[key]
});
}
}
}, {
key: 'AddItem',
value: function AddItem(itemOrItemName) {
var _this2 = this;
if (itemOrItemName instanceof InkListItem) {
var item = itemOrItemName;
if (item.originName == null) {
this.AddItem(item.itemName);
return;
}
this.origins.forEach(function (origin) {
if (origin.name == item.originName) {
var intVal;
intVal = origin.TryGetValueForItem(item, intVal);
if (intVal !== undefined) {
_this2.Add(item, intVal);
return;
} else {
throw "Could not add the item " + item + " to this list because it doesn't exist in the original list definition in ink.";
}
}
});
throw "Failed to add item to list because the item was from a new list definition that wasn't previously known to this list. Only items from previously known lists can be used, so that the int value can be found.";
} else {
var itemName = itemOrItemName;
var foundListDef = null;
this.origins.forEach(function (origin) {
if (origin.ContainsItemWithName(itemName)) {
if (foundListDef != null) {
throw "Could not add the item " + itemName + " to this list because it could come from either " + origin.name + " or " + foundListDef.name;
} else {
foundListDef = origin;
}
}
});
if (foundListDef == null) throw "Could not add the item " + itemName + " to this list because it isn't known to any list definitions previously associated with this list.";
var item = new InkListItem(foundListDef.name, itemName);
var itemVal = foundListDef.ValueForItem(item);
this.Add(item, itemVal);
}
}
}, {
key: 'ContainsItemNamed',
value: function ContainsItemNamed(itemName) {
var contains = false;
this.forEach(function (itemWithValue) {
if (itemWithValue.Key.itemName == itemName) contains = true;
});
return contains;
}
}, {
key: 'ContainsKey',
value: function ContainsKey(key) {
return key in this._values;
}
}, {
key: 'Add',
value: function Add(key, value) {
this._keys[key] = key;
this._values[key] = value;
}
}, {
key: 'Remove',
value: function Remove(key) {
delete this._values[key];
delete this._keys[key];
}
}, {
key: 'SetInitialOriginName',
value: function SetInitialOriginName(initialOriginName) {
this._originNames = [initialOriginName];
}
}, {
key: 'SetInitialOriginNames',
value: function SetInitialOriginNames(initialOriginNames) {
if (initialOriginNames == null) this._originNames = null;else this._originNames = initialOriginNames.slice(); //store a copy
}
}, {
key: 'Union',
value: function Union(otherList) {
var union = new InkList(this);
otherList.forEach(function (kv) {
union.Add(kv.Key, kv.Value);
});
return union;
}
}, {
key: 'Intersect',
value: function Intersect(otherList) {
var intersection = new InkList();
this.forEach(function (kv) {
if (otherList.ContainsKey(kv.Key)) intersection.Add(kv.Key, kv.Value);
});
return intersection;
}
}, {
key: 'Without',
value: function Without(listToRemove) {
var result = new InkList(this);
listToRemove.forEach(function (kv) {
result.Remove(kv.Key);
});
return result;
}
}, {
key: 'Contains',
value: function Contains(otherList) {
var _this3 = this;
var contains = true;
otherList.forEach(function (kv) {
if (!_this3.ContainsKey(kv.Key)) contains = false;
});
return contains;
}
}, {
key: 'GreaterThan',
value: function GreaterThan(otherList) {
if (this.Count == 0) return false;
if (otherList.Count == 0) return true;
// All greater
return this.minItem.Value > otherList.maxItem.Value;
}
}, {
key: 'GreaterThanOrEquals',
value: function GreaterThanOrEquals(otherList) {
if (this.Count == 0) return false;
if (otherList.Count == 0) return true;
return this.minItem.Value >= otherList.minItem.Value && this.maxItem.Value >= otherList.maxItem.Value;
}
}, {
key: 'LessThan',
value: function LessThan(otherList) {
if (otherList.Count == 0) return false;
if (this.Count == 0) return true;
return this.maxItem.Value < otherList.minItem.Value;
}
}, {
key: 'LessThanOrEquals',
value: function LessThanOrEquals(otherList) {
if (otherList.Count == 0) return false;
if (this.Count == 0) return true;
return this.maxItem.Value <= otherList.maxItem.Value && this.minItem.Value <= otherList.minItem.Value;
}
}, {
key: 'MaxAsList',
value: function MaxAsList() {
if (this.Count > 0) return new InkList(this.maxItem);else return new InkList();
}
}, {
key: 'MinAsList',
value: function MinAsList() {
if (this.Count > 0) return new InkList(this.minItem);else return new InkList();
}
}, {
key: 'Equals',
value: function Equals(other) {
// var otherInkList = other as InkList;
var otherInkList = other;
if (otherInkList instanceof InkList === false) return false;
if (otherInkList.Count != this.Count) return false;
var equals = true;
this.forEach(function (kv) {
if (!otherInkList.ContainsKey(kv.Key)) equals = false;
});
return equals;
}
//GetHashCode not implemented
}, {
key: 'toString',
value: function toString() {
var ordered = [];
this.forEach(function (kv) {
ordered.push(kv);
});
ordered = ordered.sort(function (a, b) {
return a.Value === b.Value ? 0 : a.Value > b.Value ? 1 : -1;
});
var sb = new StringBuilder();
for (var i = 0; i < ordered.length; i++) {
if (i > 0) sb.Append(", ");
var item = ordered[i].Key;
sb.Append(item.itemName);
}
return sb.toString();
}
//casting a InkList to a Number, for somereason, actually gives a number. This messes up the type detection when creating a Value from a InkList. Returning NaN here prevents that.
}, {
key: 'valueOf',
value: function valueOf() {
return NaN;
}
}, {
key: 'Count',
get: function get$$1() {
return Object.keys(this._values).length;
}
}, {
key: 'originOfMaxItem',
get: function get$$1() {
if (this.origins == null) return null;
var maxOriginName = this.maxItem.Key.originName;
var result = null;
this.origins.every(function (origin) {
if (origin.name == maxOriginName) {
result = origin;
return false;
} else return true;
});
return result;
}
}, {
key: 'originNames',
get: function get$$1() {
var _this4 = this;
if (this.Count > 0) {
if (this._originNames == null && this.Count > 0) this._originNames = [];else this._originNames.length = 0;
this.forEach(function (itemAndValue) {
_this4._originNames.push(itemAndValue.Key.originName);
});
}
return this._originNames;
}
}, {
key: 'maxItem',
get: function get$$1() {
var max = {
Key: null,
Value: null
};
this.forEach(function (kv) {
if (max.Key === null || kv.Value > max.Value) max = kv;
});
return max;
}
}, {
key: 'minItem',
get: function get$$1() {
var min = {
Key: null,
Value: null
};
this.forEach(function (kv) {
if (min.Key === null || kv.Value < min.Value) min = kv;
});
return min;
}
}, {
key: 'inverse',
get: function get$$1() {
var _this5 = this;
var list = new InkList();
if (this.origins != null) {
this.origins.forEach(function (origin) {
origin.items.forEach(function (itemAndValue) {
if (!_this5.ContainsKey(itemAndValue.Key)) list.Add(itemAndValue.Key, itemAndValue.Value);
});
});
}
return list;
}
}, {
key: 'all',
get: function get$$1() {
var list = new InkList();
if (this.origins != null) {
this.origins.forEach(function (origin) {
origin.items.forEach(function (itemAndValue) {
list.Add(itemAndValue.Key, itemAndValue.Value);
});
});
}
return list;
}
}]);
return InkList;
}();
var StoryException = function (_Error) {
inherits(StoryException, _Error);
function StoryException(message) {
classCallCheck(this, StoryException);
var _this = possibleConstructorReturn(this, (StoryException.__proto__ || Object.getPrototypeOf(StoryException)).call(this, message));
_this.useEndLineNumber = false;
_this.message = message;
_this.name = 'StoryException';
return _this;
}
return StoryException;
}(Error);
var ValueType = {
// Used in coersion
Int: 0,
Float: 1,
List: 2,
String: 3,
// Not used for coersion described above
DivertTarget: 4,
VariablePointer: 5
};
var AbstractValue = function (_InkObject) {
inherits(AbstractValue, _InkObject);
function AbstractValue(val) {
classCallCheck(this, AbstractValue);
var _this = possibleConstructorReturn(this, (AbstractValue.__proto__ || Object.getPrototypeOf(AbstractValue)).call(this));
_this._valueType;
_this._isTruthy;
_this._valueObject;
return _this;
}
createClass(AbstractValue, [{
key: 'Cast',
value: function Cast(newType) {
throw "Trying to casting an AbstractValue";
}
}, {
key: 'Copy',
value: function Copy(val) {
return AbstractValue.Create(val);
}
}, {
key: 'BadCastException',
value: function BadCastException(targetType) {
return new StoryException("Can't cast " + this.valueObject + " from " + this.valueType + " to " + targetType);
}
}, {
key: 'valueType',
get: function get$$1() {
return this._valueType;
}
}, {
key: 'isTruthy',
get: function get$$1() {
return this._isTruthy;
}
}, {
key: 'valueObject',
get: function get$$1() {
return this._valueObject;
}
}], [{