@bikky/replication 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/Constants/Errors.d.ts +27 -0
  2. package/Constants/Errors.js +75 -0
  3. package/Constants/Logging.d.ts +17 -0
  4. package/Constants/Logging.js +97 -0
  5. package/Constants/ReplicableRegistry.d.ts +37 -0
  6. package/Constants/ReplicableRegistry.js +234 -0
  7. package/Constants/SerialisationTypes.d.ts +82 -0
  8. package/Constants/SerialisationTypes.js +160 -0
  9. package/Constants/SourceMaps.d.ts +10 -0
  10. package/Constants/SourceMaps.js +12 -0
  11. package/Constants/TraversalStep.d.ts +5 -0
  12. package/Constants/TraversalStep.js +2 -0
  13. package/Constants/Versions.d.ts +15 -0
  14. package/Constants/Versions.js +63 -0
  15. package/Expressions/Compiler/BuiltinGrammar.d.ts +234 -0
  16. package/Expressions/Compiler/BuiltinGrammar.js +446 -0
  17. package/Expressions/Compiler/ExpressionGrammar.d.ts +89 -0
  18. package/Expressions/Compiler/ExpressionGrammar.js +70 -0
  19. package/Expressions/Compiler/Parser.d.ts +56 -0
  20. package/Expressions/Compiler/Parser.js +314 -0
  21. package/Expressions/Compiler/Tokenizer.d.ts +52 -0
  22. package/Expressions/Compiler/Tokenizer.js +222 -0
  23. package/Expressions/Compiler/__tests__/Replicable.Expressions.Parser.test.d.ts +1 -0
  24. package/Expressions/Compiler/__tests__/Replicable.Expressions.Parser.test.js +516 -0
  25. package/Expressions/Compiler/__tests__/Replicable.Expressions.Tokenizer.test.d.ts +1 -0
  26. package/Expressions/Compiler/__tests__/Replicable.Expressions.Tokenizer.test.js +68 -0
  27. package/Expressions/CreateEvaluator.d.ts +4 -0
  28. package/Expressions/CreateEvaluator.js +85 -0
  29. package/Expressions/EvaluatorChain.d.ts +19 -0
  30. package/Expressions/EvaluatorChain.js +137 -0
  31. package/Expressions/EvaluatorSteps.d.ts +19 -0
  32. package/Expressions/EvaluatorSteps.js +12 -0
  33. package/Expressions/EvaluatorString.d.ts +21 -0
  34. package/Expressions/EvaluatorString.js +26 -0
  35. package/Expressions/Expression.d.ts +36 -0
  36. package/Expressions/Expression.js +147 -0
  37. package/Expressions/Traverser.d.ts +28 -0
  38. package/Expressions/Traverser.js +348 -0
  39. package/Expressions/TypeRegistry/Accessors.d.ts +26 -0
  40. package/Expressions/TypeRegistry/Accessors.js +58 -0
  41. package/Expressions/TypeRegistry/ChainCollections.d.ts +51 -0
  42. package/Expressions/TypeRegistry/ChainCollections.js +134 -0
  43. package/Expressions/TypeRegistry/ChainTypes.d.ts +23 -0
  44. package/Expressions/TypeRegistry/ChainTypes.js +46 -0
  45. package/Expressions/TypeRegistry/CustomAPI.d.ts +36 -0
  46. package/Expressions/TypeRegistry/CustomAPI.js +181 -0
  47. package/Expressions/TypeRegistry/Primitive.d.ts +19 -0
  48. package/Expressions/TypeRegistry/Primitive.js +47 -0
  49. package/Expressions/TypeRegistry/Registry.d.ts +27 -0
  50. package/Expressions/TypeRegistry/Registry.js +270 -0
  51. package/Expressions/TypeRegistry/ReplAPI.d.ts +41 -0
  52. package/Expressions/TypeRegistry/ReplAPI.js +220 -0
  53. package/Expressions/TypeRegistry/Scope.d.ts +24 -0
  54. package/Expressions/TypeRegistry/Scope.js +44 -0
  55. package/Expressions/TypeRegistry/Types.d.ts +23 -0
  56. package/Expressions/TypeRegistry/Types.js +1 -0
  57. package/Expressions/TypeRegistry/__tests__/Replicable.Expressions.Accessors.test.d.ts +1 -0
  58. package/Expressions/TypeRegistry/__tests__/Replicable.Expressions.Accessors.test.js +31 -0
  59. package/Expressions/__tests__/ExpressionExamples.d.ts +28 -0
  60. package/Expressions/__tests__/ExpressionExamples.js +50 -0
  61. package/Expressions/__tests__/Replicable.Expressions.Expressions.test.d.ts +1 -0
  62. package/Expressions/__tests__/Replicable.Expressions.Expressions.test.js +166 -0
  63. package/IDPool.d.ts +18 -0
  64. package/IDPool.data.d.ts +17 -0
  65. package/IDPool.js +139 -0
  66. package/License.txt +1 -0
  67. package/Main.d.ts +13 -0
  68. package/Main.js +13 -0
  69. package/Networking.d.ts +60 -0
  70. package/Networking.js +626 -0
  71. package/Replicatable.d.ts +66 -0
  72. package/Replicatable.js +123 -0
  73. package/Tracking/Buffable.d.ts +68 -0
  74. package/Tracking/Buffable.js +194 -0
  75. package/Tracking/Class.d.ts +97 -0
  76. package/Tracking/Class.js +221 -0
  77. package/Tracking/Functions.d.ts +14 -0
  78. package/Tracking/Functions.js +27 -0
  79. package/Tracking/GlobalGroup.d.ts +5 -0
  80. package/Tracking/GlobalGroup.js +39 -0
  81. package/Tracking/Property.d.ts +95 -0
  82. package/Tracking/Property.js +125 -0
  83. package/Tracking/Types.d.ts +33 -0
  84. package/Tracking/Types.js +1 -0
  85. package/Tracking/__tests__/Replicable.Tracking.Decorator.test.d.ts +1 -0
  86. package/Tracking/__tests__/Replicable.Tracking.Decorator.test.js +151 -0
  87. package/Tracking/__tests__/Replicable.Tracking.Deserialisation.test.d.ts +1 -0
  88. package/Tracking/__tests__/Replicable.Tracking.Deserialisation.test.js +253 -0
  89. package/Tracking/__tests__/Replicable.Tracking.MixinSchemaGeneration.test.d.ts +1 -0
  90. package/Tracking/__tests__/Replicable.Tracking.MixinSchemaGeneration.test.js +135 -0
  91. package/Tracking/__tests__/Replicable.Tracking.Struct.test.d.ts +1 -0
  92. package/Tracking/__tests__/Replicable.Tracking.Struct.test.js +66 -0
  93. package/Tracking/__tests__/Replicable.Tracking.Type.test.d.ts +1 -0
  94. package/Tracking/__tests__/Replicable.Tracking.Type.test.js +67 -0
  95. package/Transformers/Configurer.d.ts +39 -0
  96. package/Transformers/Configurer.js +415 -0
  97. package/Transformers/Constructor.d.ts +12 -0
  98. package/Transformers/Constructor.js +44 -0
  99. package/Transformers/Definitions.d.ts +102 -0
  100. package/Transformers/Definitions.js +626 -0
  101. package/Transformers/Loader.d.ts +45 -0
  102. package/Transformers/Loader.js +350 -0
  103. package/Transformers/Progress.d.ts +32 -0
  104. package/Transformers/Progress.js +429 -0
  105. package/Transformers/Reference.d.ts +37 -0
  106. package/Transformers/Reference.js +212 -0
  107. package/Transformers/SchemaGenerator.d.ts +102 -0
  108. package/Transformers/SchemaGenerator.js +564 -0
  109. package/Transformers/Serialiser.d.ts +31 -0
  110. package/Transformers/Serialiser.js +366 -0
  111. package/Transformers/Utils.d.ts +33 -0
  112. package/Transformers/Utils.js +287 -0
  113. package/Transformers/__tests__/Examples.d.ts +168 -0
  114. package/Transformers/__tests__/Examples.js +263 -0
  115. package/Transformers/__tests__/Replicable.Transformers.Definitions.test.d.ts +1 -0
  116. package/Transformers/__tests__/Replicable.Transformers.Definitions.test.js +457 -0
  117. package/Transformers/__tests__/Replicable.Transformers.Loader.test.d.ts +1 -0
  118. package/Transformers/__tests__/Replicable.Transformers.Loader.test.js +339 -0
  119. package/Transformers/__tests__/Replicable.Transformers.Progress.test.d.ts +1 -0
  120. package/Transformers/__tests__/Replicable.Transformers.Progress.test.js +256 -0
  121. package/Transformers/__tests__/Replicable.Transformers.Reference.test.d.ts +1 -0
  122. package/Transformers/__tests__/Replicable.Transformers.Reference.test.js +167 -0
  123. package/Transformers/__tests__/Replicable.Transformers.SchemaGenerator.test.d.ts +1 -0
  124. package/Transformers/__tests__/Replicable.Transformers.SchemaGenerator.test.js +400 -0
  125. package/Transformers/__tests__/Replicable.Transformers.SchemaGeneratorOutput.test.d.ts +1 -0
  126. package/Transformers/__tests__/Replicable.Transformers.SchemaGeneratorOutput.test.js +441 -0
  127. package/Transformers/__tests__/Replicable.Transformers.Serialiser.test.d.ts +1 -0
  128. package/Transformers/__tests__/Replicable.Transformers.Serialiser.test.js +320 -0
  129. package/Transformers/__tests__/Replicable.Transformers.Utils.test.d.ts +1 -0
  130. package/Transformers/__tests__/Replicable.Transformers.Utils.test.js +534 -0
  131. package/__tests__/Replicable.Expressions.test.d.ts +1 -0
  132. package/__tests__/Replicable.Expressions.test.js +166 -0
  133. package/__tests__/Replicable.IDPool.test.d.ts +1 -0
  134. package/__tests__/Replicable.IDPool.test.js +11 -0
  135. package/__tests__/Replicable.ReplicableRegistry.test.d.ts +1 -0
  136. package/__tests__/Replicable.ReplicableRegistry.test.js +154 -0
  137. package/__tests__/Replicable.Serialisation.test.d.ts +1 -0
  138. package/__tests__/Replicable.Serialisation.test.js +283 -0
  139. package/package.json +14 -0
  140. package/tsconfig.json +19 -0
@@ -0,0 +1,123 @@
1
+ import { BikPath } from "@bikky/path";
2
+ import { ReplicableRegistry } from "./Constants/ReplicableRegistry.js";
3
+ import { getClassOfObject as GetClassOfObjectInternal, TypeSymbol, isPrimitiveType, describeObject } from "./Constants/SerialisationTypes.js";
4
+ import { Versions } from "./Constants/Versions.js";
5
+ import { Expression } from "./Expressions/Expression.js";
6
+ import { ReplicableClass } from "./Tracking/Class.js";
7
+ import { Loader } from "./Transformers/Loader.js";
8
+ import { ErrorStack } from "./Constants/Errors.js";
9
+ import { Definitions } from "./Transformers/Definitions.js";
10
+ import { Referencer } from "./Transformers/Reference.js";
11
+ import { Utils } from "./Transformers/Utils.js";
12
+ import { Serialiser } from "./Transformers/Serialiser.js";
13
+ import { Constructor } from "./Transformers/Constructor.js";
14
+ import { __ReplTypeHelperFunctions } from "./Expressions/TypeRegistry/ReplAPI.js";
15
+ import { Progress } from "./Transformers/Progress.js";
16
+ import { Configurer } from "./Transformers/Configurer.js";
17
+ export var Replicable;
18
+ (function (Replicable) {
19
+ Referencer.SetDataNameLookupFunction(ReplicableRegistry.__GetReplicableForDataName);
20
+ Referencer.SetAliasLookupFunction(ReplicableRegistry.__GetReplicablesFor);
21
+ __ReplTypeHelperFunctions.SetDataNameTypeLookupFunction(ReplicableRegistry.GetTypeForDataName);
22
+ __ReplTypeHelperFunctions.SetPrimOrClassLookupFunction(ReplicableRegistry.__GetReplOrPrimFor);
23
+ Progress.RegisterReplInitialisationFunction(Configurer.CacheClassProperties);
24
+ /**
25
+ * Can be used to create a new instance of a replicable class, even from serialised data.
26
+ * When restoring serialised data provide the serialised data as the "data" parameter of the options.
27
+ * @param Class the class to create an instance of.
28
+ * @param opts the options for creating the instance.
29
+ */
30
+ function Create(Class, opts) {
31
+ var _a, _b, _c;
32
+ if (!opts)
33
+ opts = {};
34
+ if (!opts.source) {
35
+ opts.source = {
36
+ SourceFile: BikPath.getCallerFilepath(),
37
+ Version: Versions.MAX
38
+ };
39
+ }
40
+ let stack = new ErrorStack(opts.source);
41
+ let types = (_a = ReplicableRegistry.__GetReplicablesFor(Class)) !== null && _a !== void 0 ? _a : [];
42
+ if (!Array.isArray(opts.data)) {
43
+ types = types.filter((e) => {
44
+ if (e === undefined)
45
+ return false;
46
+ return Definitions.IsLoadableDataForType(e, opts.data, opts.source.Version, stack);
47
+ });
48
+ if (types.length === 0) {
49
+ throw new Error(`Failed to find matching type for data ${(_b = opts.data.Class) !== null && _b !== void 0 ? _b : describeObject(opts.data)} in ${describeObject(Class)}\n` + stack.toString("REP_001"));
50
+ }
51
+ }
52
+ else {
53
+ let serialisedType = Replicable.GetTypeForDataName(opts.data[0]);
54
+ if (!types.some((e) => e === serialisedType || (e instanceof ReplicableClass ? e.isChildTypeOfThisType(serialisedType) : false))) {
55
+ throw new Error(`Failed to find matching type for data ${opts.data[0]} in ${describeObject(Class)}\n` + stack.toString("REP_002"));
56
+ }
57
+ types = [serialisedType];
58
+ }
59
+ if (isPrimitiveType(types[0])) {
60
+ return opts.data;
61
+ }
62
+ return Constructor.Construct(types[0], opts.source, opts.owner, (_c = opts.args) !== null && _c !== void 0 ? _c : opts.data);
63
+ }
64
+ Replicable.Create = Create;
65
+ function Initialise(object, data, expressionParams) {
66
+ let type = Replicable.GetClassOfObject(object);
67
+ let typeDef = type.prototype[TypeSymbol];
68
+ if (expressionParams) {
69
+ Expression.setCurrentScope(type, expressionParams);
70
+ }
71
+ if (Array.isArray(data.data) && data.data[0] !== typeDef.opts.dataTypeName) {
72
+ return Replicable.Deserialise(object, data.data);
73
+ }
74
+ else {
75
+ if (!("source" in data)) {
76
+ throw new Error(`Source not provided for initialisation of ${describeObject(object)}`);
77
+ }
78
+ return Replicable.Load(object, data.data, data.source, expressionParams);
79
+ }
80
+ }
81
+ Replicable.Initialise = Initialise;
82
+ function Load(object, data, source, expressionParams) {
83
+ let type = Replicable.GetClassOfObject(object);
84
+ let typeDef = type.prototype[TypeSymbol];
85
+ if (expressionParams) {
86
+ Expression.setCurrentScope(expressionParams.type, expressionParams.scope);
87
+ }
88
+ return Loader.InitFromData(typeDef, source, object, data);
89
+ }
90
+ Replicable.Load = Load;
91
+ function GetOriginalPropertyValue(object, property) {
92
+ let typeDef = object[TypeSymbol];
93
+ return typeDef.getOriginalPropertyValue(object, property);
94
+ }
95
+ Replicable.GetOriginalPropertyValue = GetOriginalPropertyValue;
96
+ function GetChildClassesNames(type) {
97
+ var _a;
98
+ let typeDef = (_a = ReplicableRegistry.__GetReplicablesFor(type)) === null || _a === void 0 ? void 0 : _a.filter((e) => !isPrimitiveType(e));
99
+ if (!typeDef)
100
+ return [];
101
+ return typeDef.flatMap((e) => e.getChildClassesNames());
102
+ }
103
+ Replicable.GetChildClassesNames = GetChildClassesNames;
104
+ Replicable.GetClassOfObject = GetClassOfObjectInternal;
105
+ Replicable.GetDataName = ReplicableRegistry.GetDataName;
106
+ Replicable.GetTypesForName = ReplicableRegistry.GetTypesForName;
107
+ Replicable.GetTypeForDataName = ReplicableRegistry.GetTypeForDataName;
108
+ Replicable.IsType = ReplicableRegistry.IsType;
109
+ Replicable.getDataNameOfObjectType = ReplicableRegistry.GetDataNameOfObjectType;
110
+ Replicable.InitialiseData = Definitions.PrePrepareData;
111
+ Replicable.CanReference = Referencer.CanReference;
112
+ Replicable.IsReference = Referencer.IsReference;
113
+ Replicable.Reference = Referencer.Reference;
114
+ Replicable.Dereference = Referencer.Dereference;
115
+ Replicable.CompareReferences = Utils.CompareUtils.CompareReferences;
116
+ Replicable.Serialise = Serialiser.Serialise;
117
+ Replicable.IsSerialisable = Serialiser.IsSerialisable;
118
+ Replicable.Deserialise = Serialiser.Deserialise;
119
+ Replicable.Compare = Utils.CompareUtils.Compare;
120
+ Replicable.OnReady = ReplicableRegistry.Initialise;
121
+ Replicable.RegisterTypeAlias = ReplicableRegistry.RegisterTypeAlias;
122
+ Replicable.ReplaceClass = ReplicableRegistry.ReplaceClass;
123
+ })(Replicable || (Replicable = {}));
@@ -0,0 +1,68 @@
1
+ import { Expression } from "../Expressions/Expression.js";
2
+ interface BuffableEvents {
3
+ onChange: (newVal: number, oldVal: number) => void;
4
+ }
5
+ /**
6
+ * Similar to Pointer.ts but instead allows values to be altered by "buffs". Replaces the value itself with a
7
+ * buffable object that has a .val, .raw, .buffs and other useful properties for values that are buffed.
8
+ * Numbers only would be buffable by default (worked into the replication API).
9
+ *
10
+ * NOTE: This is designed to handle only periodic updates. If you want to deal with streaming resources it's
11
+ * advised to treat the whole value as though it's a streaming value and handle it's application on-tick to the
12
+ * storage separately.
13
+ */
14
+ export declare class Buffable {
15
+ protected original: number | Expression;
16
+ protected computed: number;
17
+ protected eventListeners: {
18
+ onChange: any;
19
+ };
20
+ protected resolution: Buffable.MultiBuffResolution;
21
+ protected buffs: any;
22
+ get raw(): number;
23
+ set raw(val: number);
24
+ get val(): number;
25
+ set val(val: number);
26
+ constructor(original: number, resolution?: Buffable.MultiBuffResolution);
27
+ addEventListener<eventName extends keyof BuffableEvents>(event: eventName, callback: BuffableEvents[eventName]): void;
28
+ removeEventListener<eventName extends keyof BuffableEvents>(event: eventName, callback: BuffableEvents[eventName]): void;
29
+ addBuff(source: Buffable.BuffSource): void;
30
+ removeBuff(source: Buffable.BuffSource): void;
31
+ protected isResolvedAs(type: Buffable.MultiBuffResolution): boolean;
32
+ protected calculate(): void;
33
+ }
34
+ export declare namespace Buffable {
35
+ interface BuffSource {
36
+ op: Operator;
37
+ value: number;
38
+ addEventListener: <eventName extends keyof BuffableEvents>(event: eventName, callback: BuffableEvents[eventName]) => void;
39
+ removeEventListener: <eventName extends keyof BuffableEvents>(event: eventName, callback: BuffableEvents[eventName]) => void;
40
+ }
41
+ /**
42
+ * Note that only AddBuffs supports multiplication and division.
43
+ */
44
+ enum Operator {
45
+ Replace = 0,
46
+ Multiply = 1,
47
+ Divide = 2,
48
+ Add = 3,
49
+ Subtract = 4,
50
+ BuffMultiplier = 5,
51
+ BuffDivider = 6
52
+ }
53
+ /**
54
+ * Note that only AddBuffs supports multiplication and division, everything else only supports add and subtract.
55
+ */
56
+ enum MultiBuffResolution {
57
+ ApplyAllBuffs = 0,
58
+ UseAverageBuff = 1,
59
+ UseHighestBuff = 9,
60
+ UseLowestBuff = 17,
61
+ UseAverageDebuff = 64,
62
+ UseHighestDebuff = 576,
63
+ UseLowestDebuff = 1088,
64
+ Average = 65,
65
+ HighestBuffLowestDebuff = 8465
66
+ }
67
+ }
68
+ export {};
@@ -0,0 +1,194 @@
1
+ import { SmartArray } from "@bikky/smart-collections";
2
+ /**
3
+ * Similar to Pointer.ts but instead allows values to be altered by "buffs". Replaces the value itself with a
4
+ * buffable object that has a .val, .raw, .buffs and other useful properties for values that are buffed.
5
+ * Numbers only would be buffable by default (worked into the replication API).
6
+ *
7
+ * NOTE: This is designed to handle only periodic updates. If you want to deal with streaming resources it's
8
+ * advised to treat the whole value as though it's a streaming value and handle it's application on-tick to the
9
+ * storage separately.
10
+ */
11
+ export class Buffable {
12
+ get raw() {
13
+ return typeof this.original === "number" ? this.original : this.original.get();
14
+ }
15
+ set raw(val) {
16
+ this.original = val;
17
+ }
18
+ get val() {
19
+ return this.computed;
20
+ }
21
+ set val(val) {
22
+ throw new Error(`Cannot set the value of a buffable object, did you mean to set the raw instead?.`);
23
+ }
24
+ constructor(original, resolution = Buffable.MultiBuffResolution.ApplyAllBuffs) {
25
+ this.eventListeners = {
26
+ onChange: new SmartArray()
27
+ };
28
+ this.resolution = Buffable.MultiBuffResolution.ApplyAllBuffs;
29
+ this.buffs = new SmartArray();
30
+ this.original = original;
31
+ this.resolution = resolution;
32
+ this.computed = this.raw;
33
+ this.calculate = this.calculate.bind(this);
34
+ }
35
+ addEventListener(event, callback) {
36
+ this.eventListeners[event].push(callback);
37
+ }
38
+ removeEventListener(event, callback) {
39
+ this.eventListeners[event].remove(callback);
40
+ }
41
+ addBuff(source) {
42
+ this.buffs.push(source);
43
+ this.buffs = this.buffs.sort((a, b) => a.op - b.op);
44
+ source.addEventListener("onChange", this.calculate);
45
+ this.calculate();
46
+ }
47
+ removeBuff(source) {
48
+ this.buffs.remove(source);
49
+ source.removeEventListener("onChange", this.calculate);
50
+ this.calculate();
51
+ }
52
+ isResolvedAs(type) {
53
+ return (this.resolution & type) == type;
54
+ }
55
+ //Calculate the amount that a buff would currently apply
56
+ calculate() {
57
+ let newValue = this.raw;
58
+ if (this.isResolvedAs(Buffable.MultiBuffResolution.ApplyAllBuffs)) {
59
+ for (let buff of this.buffs) {
60
+ switch (buff.op) {
61
+ case Buffable.Operator.Replace: {
62
+ newValue = buff.value;
63
+ break;
64
+ }
65
+ case Buffable.Operator.Add: {
66
+ newValue += buff.value;
67
+ break;
68
+ }
69
+ case Buffable.Operator.Subtract: {
70
+ newValue -= buff.value;
71
+ break;
72
+ }
73
+ case Buffable.Operator.Multiply: {
74
+ newValue *= buff.value;
75
+ break;
76
+ }
77
+ case Buffable.Operator.Divide: {
78
+ newValue /= buff.value;
79
+ break;
80
+ }
81
+ case Buffable.Operator.BuffMultiplier: {
82
+ newValue *= buff.value;
83
+ break;
84
+ }
85
+ case Buffable.Operator.BuffDivider: {
86
+ newValue /= buff.value;
87
+ break;
88
+ }
89
+ }
90
+ }
91
+ }
92
+ if (this.isResolvedAs(Buffable.MultiBuffResolution.UseHighestBuff)) {
93
+ let val = 0;
94
+ for (let buff of this.buffs) {
95
+ if (buff.op != Buffable.Operator.Add)
96
+ continue;
97
+ if (buff.value > val)
98
+ val = buff.value;
99
+ }
100
+ newValue += val;
101
+ }
102
+ else if (this.isResolvedAs(Buffable.MultiBuffResolution.UseLowestBuff)) {
103
+ if (this.buffs.length > 0) {
104
+ let val = Number.POSITIVE_INFINITY;
105
+ for (let buff of this.buffs) {
106
+ if (buff.op != Buffable.Operator.Add)
107
+ continue;
108
+ if (buff.value < val)
109
+ val = buff.value;
110
+ }
111
+ newValue += val;
112
+ }
113
+ }
114
+ else if (this.isResolvedAs(Buffable.MultiBuffResolution.UseAverageBuff)) {
115
+ let total = 0;
116
+ for (let buff of this.buffs) {
117
+ if (buff.op != Buffable.Operator.Add)
118
+ continue;
119
+ total += buff.value;
120
+ }
121
+ newValue += total / this.buffs.length;
122
+ }
123
+ if (this.isResolvedAs(Buffable.MultiBuffResolution.UseHighestDebuff)) {
124
+ let val = 0;
125
+ for (let buff of this.buffs) {
126
+ if (buff.op != Buffable.Operator.Subtract)
127
+ continue;
128
+ if (buff.value > val)
129
+ val = buff.value;
130
+ }
131
+ newValue -= val;
132
+ }
133
+ else if (this.isResolvedAs(Buffable.MultiBuffResolution.UseLowestDebuff)) {
134
+ if (this.buffs.length > 0) {
135
+ let val = Number.POSITIVE_INFINITY;
136
+ for (let buff of this.buffs) {
137
+ if (buff.op != Buffable.Operator.Subtract)
138
+ continue;
139
+ if (buff.value < val)
140
+ val = buff.value;
141
+ }
142
+ newValue -= val;
143
+ }
144
+ }
145
+ else if (this.isResolvedAs(Buffable.MultiBuffResolution.UseAverageDebuff)) {
146
+ let total = 0;
147
+ for (let buff of this.buffs) {
148
+ if (buff.op != Buffable.Operator.Subtract)
149
+ continue;
150
+ total += buff.value;
151
+ }
152
+ newValue -= total / this.buffs.length;
153
+ }
154
+ if (newValue != this.computed) {
155
+ let old = this.computed;
156
+ this.computed = newValue;
157
+ this.eventListeners.onChange.callEach(old, newValue);
158
+ }
159
+ }
160
+ }
161
+ (function (Buffable) {
162
+ /**
163
+ * Note that only AddBuffs supports multiplication and division.
164
+ */
165
+ let Operator;
166
+ (function (Operator) {
167
+ Operator[Operator["Replace"] = 0] = "Replace";
168
+ Operator[Operator["Multiply"] = 1] = "Multiply";
169
+ Operator[Operator["Divide"] = 2] = "Divide";
170
+ Operator[Operator["Add"] = 3] = "Add";
171
+ Operator[Operator["Subtract"] = 4] = "Subtract";
172
+ //This one is a bit special, because is read instead of set and it alters the value of every property in the buff.
173
+ Operator[Operator["BuffMultiplier"] = 5] = "BuffMultiplier";
174
+ Operator[Operator["BuffDivider"] = 6] = "BuffDivider";
175
+ })(Operator = Buffable.Operator || (Buffable.Operator = {}));
176
+ /**
177
+ * Note that only AddBuffs supports multiplication and division, everything else only supports add and subtract.
178
+ */
179
+ let MultiBuffResolution;
180
+ (function (MultiBuffResolution) {
181
+ //Just add each buff together.
182
+ MultiBuffResolution[MultiBuffResolution["ApplyAllBuffs"] = 0] = "ApplyAllBuffs";
183
+ MultiBuffResolution[MultiBuffResolution["UseAverageBuff"] = 1] = "UseAverageBuff";
184
+ MultiBuffResolution[MultiBuffResolution["UseHighestBuff"] = 9] = "UseHighestBuff";
185
+ MultiBuffResolution[MultiBuffResolution["UseLowestBuff"] = 17] = "UseLowestBuff";
186
+ MultiBuffResolution[MultiBuffResolution["UseAverageDebuff"] = 64] = "UseAverageDebuff";
187
+ MultiBuffResolution[MultiBuffResolution["UseHighestDebuff"] = 576] = "UseHighestDebuff";
188
+ MultiBuffResolution[MultiBuffResolution["UseLowestDebuff"] = 1088] = "UseLowestDebuff";
189
+ //Average buff + average debuff.
190
+ MultiBuffResolution[MultiBuffResolution["Average"] = 65] = "Average";
191
+ //Highest buff + lowest debuff.
192
+ MultiBuffResolution[MultiBuffResolution["HighestBuffLowestDebuff"] = 8465] = "HighestBuffLowestDebuff";
193
+ })(MultiBuffResolution = Buffable.MultiBuffResolution || (Buffable.MultiBuffResolution = {}));
194
+ })(Buffable || (Buffable = {}));
@@ -0,0 +1,97 @@
1
+ import { ClassCategory, Primitive } from "../Constants/SerialisationTypes.js";
2
+ import { Versions } from "../Constants/Versions.js";
3
+ import type { FunctionOptions } from "./Functions.js";
4
+ import { ComplexPropertyType, PropertyConfiguration, PropertyOptions } from "./Property.js";
5
+ import type { CustomClass, ReplicableClassConstructor, StructClass, TypeClass } from "./Types.js";
6
+ import type { TraversalScope } from "../Expressions/TypeRegistry/Types.js";
7
+ import { ReplAPI } from "../Expressions/TypeRegistry/ReplAPI.js";
8
+ import { ChainType } from "../Expressions/TypeRegistry/ChainTypes.js";
9
+ export interface ReplicableTypeOptions {
10
+ version: Versions;
11
+ file?: string;
12
+ name?: string;
13
+ dataTypeName?: string;
14
+ typescriptTypeName?: string;
15
+ abstract?: boolean;
16
+ }
17
+ export interface RatifiedPropertyOptions extends PropertyOptions {
18
+ type: ComplexPropertyType[];
19
+ customDataType?: ComplexPropertyType[];
20
+ }
21
+ export interface PropertyDefinition extends RatifiedPropertyOptions {
22
+ version: Versions | string;
23
+ property: string;
24
+ dataName: string;
25
+ }
26
+ export interface FunctionConfiguration {
27
+ version: Versions | string;
28
+ funcName: string;
29
+ dataName: string;
30
+ outputType: ComplexPropertyType[];
31
+ parameters: ComplexPropertyType[][];
32
+ options: FunctionOptions;
33
+ }
34
+ export interface PropertyRemoved {
35
+ version: Versions | string;
36
+ property: string;
37
+ removed: true;
38
+ dataName: string;
39
+ expressionMigration?: (scope: TraversalScope) => any;
40
+ dataMigration?: (value: any) => [key: string, value: any];
41
+ type: any[];
42
+ customDataType?: any[];
43
+ }
44
+ export interface PropertyDoesntExist {
45
+ version: Versions | string;
46
+ property: string;
47
+ doesntExist: true;
48
+ }
49
+ export declare class ReplicableClass {
50
+ category: ClassCategory;
51
+ classConstructor: ReplicableClassConstructor;
52
+ properties: any;
53
+ functions: any;
54
+ finalised_properties: Map<string, {
55
+ [name: string]: PropertyConfiguration | PropertyRemoved | PropertyDoesntExist;
56
+ }>;
57
+ finalised_functions: Map<string, {
58
+ [name: string]: PropertyRemoved | PropertyDoesntExist | FunctionConfiguration;
59
+ }>;
60
+ finalised_propertyNames: string[];
61
+ finalised_functionNames: string[];
62
+ finalised_ownPropertyNames: string[];
63
+ finalised_ownFunctionNames: string[];
64
+ opts: Required<Omit<ReplicableTypeOptions, "name">>;
65
+ liveIDs: string[];
66
+ dataIDs: string[];
67
+ parents: ReplicableClass[];
68
+ children: any;
69
+ rule: ReplAPI;
70
+ constructor(category: ClassCategory, typeClass: ReplicableClassConstructor, opts: ReplicableTypeOptions);
71
+ getIDAsString(val: any, data?: boolean): string;
72
+ protected getAppropriateEnclosingRule(): ChainType | undefined;
73
+ protected removeParentsParentsFromArray(parents: ReplicableClass[]): ReplicableClass[];
74
+ isObjectOfThisType(object: any): boolean;
75
+ isChildTypeOfThisType(specificType: any): boolean;
76
+ getPropDefinition(version: Versions | string, property: string): PropertyConfiguration | PropertyDoesntExist | PropertyRemoved;
77
+ getPropHistoryDefinition(property: string): {
78
+ "1.0.0": PropertyConfiguration | PropertyRemoved | PropertyDoesntExist;
79
+ };
80
+ addProperty(version: Versions | string, property: string, data: RatifiedPropertyOptions): void;
81
+ removeProperty(version: Versions | string, property: string, opts: Pick<PropertyRemoved, "type" | "expressionMigration" | "dataMigration" | "customDataType">): void;
82
+ addFunction(version: Versions | string, funcName: string, outputType: ComplexPropertyType[], parameters: ComplexPropertyType[][], options: FunctionOptions): void;
83
+ static typesToString(allTypes: (ReplicableClass | Primitive | string)[]): string[];
84
+ getOriginalPropertyValue(object: any, property: string): any;
85
+ /**
86
+ * Used for some fancy Arkhaven type checking.
87
+ */
88
+ getChildClassesNames(): any;
89
+ }
90
+ export declare function Type(version: Versions, opts?: Omit<ReplicableTypeOptions, "version" | "file">): (classConstructor: TypeClass) => void;
91
+ export declare function Struct(version: Versions, opts?: Omit<ReplicableTypeOptions, "version" | "file">): (classConstructor: StructClass) => void;
92
+ export declare function CustomReplicableType(version: Versions, _class: CustomClass & {
93
+ [name: string | symbol]: any;
94
+ }, opts?: Omit<ReplicableTypeOptions, "version" | "file">): CustomClass & {
95
+ [name: string]: any;
96
+ [name: symbol]: any;
97
+ };