mlogjs 0.4.10 → 0.5.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 (114) hide show
  1. package/README.md +15 -11
  2. package/dist/Compiler.d.ts +40 -38
  3. package/dist/CompilerError.d.ts +33 -33
  4. package/dist/Scope.d.ts +31 -30
  5. package/dist/bin.cjs +99 -58
  6. package/dist/bin.d.ts +1 -1
  7. package/dist/handlers/BlockStatement.d.ts +2 -2
  8. package/dist/handlers/CallExpression.d.ts +4 -4
  9. package/dist/handlers/File.d.ts +2 -2
  10. package/dist/handlers/ForStatement.d.ts +2 -2
  11. package/dist/handlers/Function.d.ts +5 -5
  12. package/dist/handlers/Identifier.d.ts +2 -2
  13. package/dist/handlers/IfStatement.d.ts +2 -2
  14. package/dist/handlers/Literal.d.ts +5 -5
  15. package/dist/handlers/Object.d.ts +8 -7
  16. package/dist/handlers/OperationExpressions.d.ts +9 -9
  17. package/dist/handlers/Program.d.ts +2 -2
  18. package/dist/handlers/Statements.d.ts +7 -7
  19. package/dist/handlers/SwitchStatement.d.ts +2 -2
  20. package/dist/handlers/TemplateExpression.d.ts +2 -2
  21. package/dist/handlers/Typescript.d.ts +8 -7
  22. package/dist/handlers/VariableDeclaration.d.ts +3 -3
  23. package/dist/handlers/WhileStatement.d.ts +3 -3
  24. package/dist/handlers/index.d.ts +17 -17
  25. package/dist/index.cjs +4213 -3261
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.mjs +4209 -3257
  28. package/dist/initScope.d.ts +5 -5
  29. package/dist/instructions/AddressResolver.d.ts +12 -12
  30. package/dist/instructions/ControlInstructions.d.ts +10 -10
  31. package/dist/instructions/EndInstruction.d.ts +6 -4
  32. package/dist/instructions/InstructionBase.d.ts +15 -15
  33. package/dist/instructions/JumpInstruction.d.ts +22 -16
  34. package/dist/instructions/OperationInstruction.d.ts +5 -5
  35. package/dist/instructions/SetCounterInstruction.d.ts +5 -5
  36. package/dist/instructions/SetInstruction.d.ts +8 -8
  37. package/dist/instructions/ZeroSpaceInstruction.d.ts +4 -4
  38. package/dist/instructions/index.d.ts +9 -9
  39. package/dist/macros/Asm.d.ts +4 -4
  40. package/dist/macros/DynamicArray.d.ts +33 -23
  41. package/dist/macros/Function.d.ts +16 -12
  42. package/dist/macros/GetGlobal.d.ts +5 -5
  43. package/dist/macros/Math.d.ts +4 -4
  44. package/dist/macros/Memory.d.ts +4 -4
  45. package/dist/macros/Namespace.d.ts +15 -12
  46. package/dist/macros/Other.d.ts +4 -4
  47. package/dist/macros/Unchecked.d.ts +7 -7
  48. package/dist/macros/commands/ApplyStatus.d.ts +4 -4
  49. package/dist/macros/commands/Control.d.ts +4 -4
  50. package/dist/macros/commands/Cutscene.d.ts +4 -4
  51. package/dist/macros/commands/Draw.d.ts +4 -4
  52. package/dist/macros/commands/DrawFlush.d.ts +4 -4
  53. package/dist/macros/commands/End.d.ts +4 -4
  54. package/dist/macros/commands/Explosion.d.ts +4 -4
  55. package/dist/macros/commands/Fetch.d.ts +4 -4
  56. package/dist/macros/commands/FlushMessage.d.ts +4 -4
  57. package/dist/macros/commands/GetBlock.d.ts +4 -4
  58. package/dist/macros/commands/GetFlag.d.ts +4 -4
  59. package/dist/macros/commands/GetLink.d.ts +4 -4
  60. package/dist/macros/commands/Lookup.d.ts +4 -4
  61. package/dist/macros/commands/PackColor.d.ts +4 -4
  62. package/dist/macros/commands/Print.d.ts +4 -4
  63. package/dist/macros/commands/PrintFlush.d.ts +4 -4
  64. package/dist/macros/commands/Radar.d.ts +6 -6
  65. package/dist/macros/commands/Sensor.d.ts +4 -4
  66. package/dist/macros/commands/SetBlock.d.ts +4 -4
  67. package/dist/macros/commands/SetFlag.d.ts +4 -4
  68. package/dist/macros/commands/SetRate.d.ts +4 -4
  69. package/dist/macros/commands/SetRule.d.ts +4 -4
  70. package/dist/macros/commands/SpawnUnit.d.ts +4 -4
  71. package/dist/macros/commands/SpawnWave.d.ts +4 -4
  72. package/dist/macros/commands/Stop.d.ts +4 -4
  73. package/dist/macros/commands/UnitBind.d.ts +4 -4
  74. package/dist/macros/commands/UnitControl.d.ts +4 -4
  75. package/dist/macros/commands/UnitLocate.d.ts +4 -4
  76. package/dist/macros/commands/UnitRadar.d.ts +4 -4
  77. package/dist/macros/commands/Wait.d.ts +4 -4
  78. package/dist/macros/commands/index.d.ts +30 -30
  79. package/dist/macros/index.d.ts +8 -6
  80. package/dist/macros/util.d.ts +17 -17
  81. package/dist/operators.d.ts +46 -26
  82. package/dist/types.d.ts +264 -237
  83. package/dist/utils/constants.d.ts +8 -6
  84. package/dist/utils/general.d.ts +26 -26
  85. package/dist/utils/index.d.ts +4 -4
  86. package/dist/utils/instruction.d.ts +9 -5
  87. package/dist/utils/value.d.ts +41 -36
  88. package/dist/values/AssignmentValue.d.ts +11 -0
  89. package/dist/values/BaseValue.d.ts +10 -10
  90. package/dist/values/DestructuringValue.d.ts +32 -30
  91. package/dist/values/FunctionValue.d.ts +57 -50
  92. package/dist/values/JumpOutValue.d.ts +36 -0
  93. package/dist/values/LazyValue.d.ts +11 -9
  94. package/dist/values/LiteralValue.d.ts +18 -14
  95. package/dist/values/ObjectValue.d.ts +23 -20
  96. package/dist/values/SenseableValue.d.ts +24 -24
  97. package/dist/values/StoreValue.d.ts +22 -21
  98. package/dist/values/VoidValue.d.ts +17 -13
  99. package/dist/values/index.d.ts +9 -8
  100. package/lib/commands.d.ts +59 -32
  101. package/lib/eslib/lib.es5.d.ts +36 -0
  102. package/lib/globals.d.ts +5 -5
  103. package/lib/helpers.d.ts +18 -2
  104. package/lib/index.d.ts +1 -1
  105. package/lib/macros.d.ts +150 -0
  106. package/lib/traits.d.ts +5 -5
  107. package/package.json +31 -27
  108. package/dist/assertions.d.ts +0 -28
  109. package/dist/bin.cjs.map +0 -1
  110. package/dist/discardedName.d.ts +0 -5
  111. package/dist/index.cjs.map +0 -1
  112. package/dist/index.mjs.map +0 -1
  113. package/dist/utils.d.ts +0 -45
  114. package/lib/memory.d.ts +0 -17
package/lib/commands.d.ts CHANGED
@@ -45,6 +45,18 @@ declare global {
45
45
  */
46
46
  function color(r: number, g: number, b: number, a?: number): void;
47
47
 
48
+ /**
49
+ * Sets the color for the next drawing operations.
50
+ *
51
+ * Uses compressed rgba data from `packColor`.
52
+ *
53
+ * ```js
54
+ * draw.col(packColor(1, 1, 1, 1));
55
+ * ```
56
+ *
57
+ */
58
+ function col(rgbaData: number): void;
59
+
48
60
  /**
49
61
  * Sets the width of the next lines to be drawn.
50
62
  *
@@ -256,7 +268,7 @@ declare global {
256
268
  * Example:
257
269
  * ```js
258
270
  * if(index < Vars.links) {
259
- * let myBlock = getLink(index)
271
+ * const myBlock = getLink(index)
260
272
  * // ...
261
273
  * }
262
274
  * ```
@@ -344,20 +356,13 @@ declare global {
344
356
  /**
345
357
  * Sets the color of an illuminator.
346
358
  *
347
- * The RGB values must be within the range: [0, 255].
348
- *
349
359
  * ```js
350
360
  * const illuminator = getBuilding("illuminator1");
351
361
  *
352
- * control.color(illuminator, 10, 150, 210);
362
+ * control.color(illuminator, packColor(0.2, 0.65, 1, 1));
353
363
  * ```
354
364
  */
355
- function color(
356
- building: BasicBuilding,
357
- r: number,
358
- g: number,
359
- b: number
360
- ): void;
365
+ function color(building: BasicBuilding, rgbaData: number): void;
361
366
  }
362
367
 
363
368
  /**
@@ -400,12 +405,12 @@ declare global {
400
405
  *
401
406
  * Example:
402
407
  * ```ts
403
- * let myBuilding = getBuilding("container1");
408
+ * const myBuilding = getBuilding("container1");
404
409
  *
405
410
  * // typescript annotation, you can use jsdoc comments on
406
411
  * // regular javascript
407
- * let myCustomSymbol = getVar<symbol>("@custom-symbol"); // problably defined by a mod
408
- * let result = sensor(myCustomSymbol, myBuilding);
412
+ * const myCustomSymbol = getVar<symbol>("@custom-symbol"); // problably defined by a mod
413
+ * const result = sensor(myCustomSymbol, myBuilding);
409
414
  * ```
410
415
  */
411
416
  function sensor<T>(property: symbol, target: BasicBuilding | BasicUnit): T;
@@ -432,7 +437,7 @@ declare global {
432
437
  * Example:
433
438
  * ```js
434
439
  * if(index < Vars.blockCount) {
435
- * let blockKind = lookup.block(index);
440
+ * const blockKind = lookup.block(index);
436
441
  * }
437
442
  * ```
438
443
  */
@@ -446,11 +451,11 @@ declare global {
446
451
  * Example:
447
452
  * ```js
448
453
  * if(index < Vars.unitCount) {
449
- * let unitKind = lookup.unit(index);
454
+ * const unitKind = lookup.unit(index);
450
455
  * }
451
456
  * ```
452
457
  */
453
- function unit(index: number): UnitSymbol | null;
458
+ function unit(index: number): UnitSymbol | undefined;
454
459
 
455
460
  /**
456
461
  * Looks up an item symbol by it's index on the content registry.
@@ -460,11 +465,11 @@ declare global {
460
465
  * Example:
461
466
  * ```js
462
467
  * if(index < Vars.itemCount) {
463
- * let itemKind = lookup.item(index);
468
+ * const itemKind = lookup.item(index);
464
469
  * }
465
470
  * ```
466
471
  */
467
- function item(index: number): ItemSymbol | null;
472
+ function item(index: number): ItemSymbol | undefined;
468
473
 
469
474
  /**
470
475
  * Looks up a liquid symbol by it's index on the content registry.
@@ -474,11 +479,11 @@ declare global {
474
479
  * Example:
475
480
  * ```js
476
481
  * if(index < Vars.liquidCount) {
477
- * let liquidKind = lookup.liquid(index);
482
+ * const liquidKind = lookup.liquid(index);
478
483
  * }
479
484
  * ```
480
485
  */
481
- function liquid(index: number): LiquidSymbol | null;
486
+ function liquid(index: number): LiquidSymbol | undefined;
482
487
  }
483
488
 
484
489
  /**
@@ -491,7 +496,12 @@ declare global {
491
496
  * const colorData = packColor(0.1, 0.6, 0.8, 0.1);
492
497
  *
493
498
  * // world processor only
499
+ * // sets the color of the ambient light
494
500
  * setRule.ambientLight(colorData);
501
+ *
502
+ * // set color of illuminator
503
+ * const illuminator = getBuilding("illuminator1");
504
+ * control.color(illuminator, packColor(0.2, 0.65, 1, 1));
495
505
  * ```
496
506
  */
497
507
  function packColor(r: number, g: number, b: number, a: number): number;
@@ -499,6 +509,11 @@ declare global {
499
509
  /**
500
510
  * Binds an unit to the this processor. The unit is accessible at `Vars.unit`.
501
511
  *
512
+ * If an unit symbol is received, the processor will pick an
513
+ * unit of the given type.
514
+ *
515
+ * If an unit object is received, the processor will bind to the unit.
516
+ *
502
517
  * ```js
503
518
  * unitBind(Units.flare);
504
519
  *
@@ -508,7 +523,7 @@ declare global {
508
523
  * printFlush();
509
524
  * ```
510
525
  */
511
- function unitBind(type: UnitSymbol): void;
526
+ function unitBind(unit: UnitSymbol | BasicUnit): void;
512
527
 
513
528
  namespace unitControl {
514
529
  /**
@@ -694,12 +709,24 @@ declare global {
694
709
  function getBlock<T extends BasicBuilding = AnyBuilding>(
695
710
  x: number,
696
711
  y: number
697
- ): [type: BlockSymbol | null, building: T | null];
712
+ ): [
713
+ type: BlockSymbol | undefined,
714
+ building: T | undefined,
715
+ floor: EnvBlockSymbol | OreSymbol | undefined
716
+ ];
698
717
 
699
718
  /**
700
719
  * Checks if the unit bound to this processor is within a radius of a given position.
701
720
  */
702
721
  function within(options: { x: number; y: number; radius: number }): boolean;
722
+
723
+ /**
724
+ * Resets the AI of the unit.
725
+ *
726
+ * Calling `unbind` does not actually unbind the unit from the processor,
727
+ * it just makes the unit resume its natural behavior.
728
+ */
729
+ function unbind(): void;
703
730
  }
704
731
 
705
732
  /**
@@ -869,11 +896,11 @@ declare global {
869
896
  /** Gets the block type on the give location. `Blocks.air` if there is no block. */
870
897
  function block(x: number, y: number): BlockSymbol;
871
898
 
872
- /** Gets the building on the given location. `null` if there is no building. */
899
+ /** Gets the building on the given location. `undefined` if there is no building. */
873
900
  function building<T extends BasicBuilding = AnyBuilding>(
874
901
  x: number,
875
902
  y: number
876
- ): T | null;
903
+ ): T | undefined;
877
904
  }
878
905
 
879
906
  /** Sets block data on a given location. World processor ONLY. */
@@ -1104,7 +1131,7 @@ declare global {
1104
1131
  * The index starts at 0.
1105
1132
  *
1106
1133
  * ```js
1107
- * const count = fetch.unitCount();
1134
+ * const count = fetch.unitCount(Teams.sharded);
1108
1135
  * for(let i = 0; i < count; i++) {
1109
1136
  * const unit = fetch.unit(Teams.sharded, i);
1110
1137
  * print`x: ${unit.x}, y: ${unit.y}\n`;
@@ -1120,7 +1147,7 @@ declare global {
1120
1147
  * Gets the amount of units existing on a given team.
1121
1148
  *
1122
1149
  * ```js
1123
- * const count = fetch.unitCount();
1150
+ * const count = fetch.unitCount(Teams.sharded);
1124
1151
  * for(let i = 0; i < count; i++) {
1125
1152
  * const unit = fetch.unit(Teams.sharded, i);
1126
1153
  * print`x: ${unit.x}, y: ${unit.y}\n`;
@@ -1135,7 +1162,7 @@ declare global {
1135
1162
  * The index starts at 0.
1136
1163
  *
1137
1164
  * ```js
1138
- * const count = fetch.playerCount();
1165
+ * const count = fetch.playerCount(Teams.sharded);
1139
1166
  * for(let i = 0; i < count; i++) {
1140
1167
  * const player = fetch.player(Teams.sharded, i);
1141
1168
  * print`x: ${player.x}, y: ${player.y}\n`;
@@ -1151,7 +1178,7 @@ declare global {
1151
1178
  * Gets the amount of players existing on a given team.
1152
1179
  *
1153
1180
  * ```js
1154
- * const count = fetch.playerCount();
1181
+ * const count = fetch.playerCount(Teams.sharded);
1155
1182
  * for(let i = 0; i < count; i++) {
1156
1183
  * const player = fetch.player(Teams.sharded, i);
1157
1184
  * print`x: ${player.x}, y: ${player.y}\n`;
@@ -1166,7 +1193,7 @@ declare global {
1166
1193
  * The index of the starts at 0.
1167
1194
  *
1168
1195
  * ```js
1169
- * const count = fetch.coreCount();
1196
+ * const count = fetch.coreCount(Teams.sharded);
1170
1197
  * for(let i = 0; i < count; i++) {
1171
1198
  * const core = fetch.core(Teams.sharded, i);
1172
1199
  * print`x: ${core.x}, y: ${core.y}\n`;
@@ -1178,7 +1205,7 @@ declare global {
1178
1205
  /**
1179
1206
  * Gets the amount of cores existing on a given team.
1180
1207
  * ```js
1181
- * const count = fetch.coreCount();
1208
+ * const count = fetch.coreCount(Teams.sharded);
1182
1209
  * for(let i = 0; i < count; i++) {
1183
1210
  * const core = fetch.core(Teams.sharded, i);
1184
1211
  * print`x: ${core.x}, y: ${core.y}\n`;
@@ -1193,7 +1220,7 @@ declare global {
1193
1220
  * The index starts at 0.
1194
1221
  *
1195
1222
  * ```js
1196
- * const count = fetch.buildCount();
1223
+ * const count = fetch.buildCount(Teams.sharded, Blocks.router);
1197
1224
  * for(let i = 0; i < count; i++) {
1198
1225
  * const router = fetch.build(Teams.sharded, i, Blocks.router);
1199
1226
  * print`x: ${router.x}, y: ${router.y}\n`;
@@ -1210,7 +1237,7 @@ declare global {
1210
1237
  * Gets the amount of buildings existing on a given team.
1211
1238
  *
1212
1239
  * ```js
1213
- * const count = fetch.buildCount();
1240
+ * const count = fetch.buildCount(Teams.sharded, Blocks.router);
1214
1241
  * for(let i = 0; i < count; i++) {
1215
1242
  * const router = fetch.build(Teams.sharded, i, Blocks.router)
1216
1243
  * print`x: ${router.x}, y: ${router.y}\n`
@@ -135,11 +135,22 @@ interface Math {
135
135
  */
136
136
  log10(x: number): number;
137
137
 
138
+ /** Returns the sine of an angle in degrees.*/
138
139
  sin(x: number): number;
140
+
141
+ /** Returns the cosine of an angle in degrees */
139
142
  cos(x: number): number;
143
+
144
+ /** Returns the tangent of an angle in degrees */
140
145
  tan(x: number): number;
146
+
147
+ /**Returns the greatest integer less than or equal to `x` */
141
148
  floor(x: number): number;
149
+
150
+ /**Returns the smallest integer greater than or equal to `x` */
142
151
  ceil(x: number): number;
152
+
153
+ /** Returns the positive square root of a number */
143
154
  sqrt(x: number): number;
144
155
 
145
156
  /**
@@ -147,6 +158,31 @@ interface Math {
147
158
  * @param range
148
159
  */
149
160
  rand(range: number): number;
161
+
162
+ /** Returns the arc sine of a number, in degrees */
163
+ asin(x: number): number;
164
+
165
+ /** Returns the arc cosine of a number, in degrees */
166
+ acos(x: number): number;
167
+
168
+ /** Returns the arc tangent of a number, in degrees */
169
+ atan(x: number): number;
170
+
171
+ /**
172
+ * Returns the integer result of the division: `x / y`.
173
+ *
174
+ * @param x
175
+ * @param y
176
+ */
177
+ idiv(x: number, y: number): number;
178
+
179
+ /**
180
+ * Returns the value of a base expression taken to a specified power.
181
+ *
182
+ * @param x The base value of the expression.
183
+ * @param y The exponent value of the expression.
184
+ */
185
+ pow(x: number, y: number): number;
150
186
  }
151
187
  declare const Math: Math;
152
188
 
package/lib/globals.d.ts CHANGED
@@ -70,7 +70,7 @@ declare const Vars: Vars;
70
70
  /** Contains the base game teams. */
71
71
  declare namespace Teams {
72
72
  /** The gray team. */
73
- const delerict: unique symbol;
73
+ const derelict: unique symbol;
74
74
  /** The yellow team. */
75
75
  const sharded: unique symbol;
76
76
  /** The red team. */
@@ -91,7 +91,7 @@ declare namespace Teams {
91
91
  const blue: unique symbol;
92
92
  }
93
93
 
94
- type TeamSymbol = typeof Teams[keyof typeof Teams];
94
+ type TeamSymbol = (typeof Teams)[keyof typeof Teams];
95
95
 
96
96
  declare namespace Items {
97
97
  const copper: unique symbol;
@@ -118,7 +118,7 @@ declare namespace Items {
118
118
  const dormantCyst: unique symbol;
119
119
  }
120
120
 
121
- type ItemSymbol = typeof Items[keyof typeof Items];
121
+ type ItemSymbol = (typeof Items)[keyof typeof Items];
122
122
 
123
123
  declare namespace Liquids {
124
124
  const water: unique symbol;
@@ -134,7 +134,7 @@ declare namespace Liquids {
134
134
  const cyanogen: unique symbol;
135
135
  }
136
136
 
137
- type LiquidSymbol = typeof Liquids[keyof typeof Liquids];
137
+ type LiquidSymbol = (typeof Liquids)[keyof typeof Liquids];
138
138
 
139
139
  declare namespace Units {
140
140
  const dagger: unique symbol;
@@ -200,7 +200,7 @@ declare namespace Units {
200
200
  const assemblyDrone: unique symbol;
201
201
  }
202
202
 
203
- type UnitSymbol = typeof Units[keyof typeof Units];
203
+ type UnitSymbol = (typeof Units)[keyof typeof Units];
204
204
 
205
205
  declare namespace LAccess {
206
206
  const totalItems: unique symbol;
package/lib/helpers.d.ts CHANGED
@@ -20,8 +20,24 @@ declare function getBuilding<T extends BasicBuilding = AnyBuilding>(
20
20
  name: string
21
21
  ): T;
22
22
 
23
- /** Concatenates a list of constant strings */
24
- declare function concat(...strings: string[]): string;
23
+ type ConcatLiteral = string | number | boolean | undefined;
24
+
25
+ /**
26
+ * Concatenates a list of constant literal values.
27
+ *
28
+ * ```js
29
+ * const name = "example";
30
+ *
31
+ * // works with normal arguments
32
+ * const before = concat("before_", name);
33
+ *
34
+ * // works with tagged template strings
35
+ * const after = concat`after_${name}`;
36
+ * ```
37
+ */
38
+ declare function concat(
39
+ ...args: ConcatLiteral[] | [TemplateStringsArray, ...ConcatLiteral[]]
40
+ ): string;
25
41
 
26
42
  /**
27
43
  * Inlines raw mlog code. Variables and expressions can be placed inside.
package/lib/index.d.ts CHANGED
@@ -3,5 +3,5 @@
3
3
  /// <reference path="./globals.d.ts" />
4
4
  /// <reference path="./helpers.d.ts" />
5
5
  /// <reference path="./kinds.d.ts" />
6
- /// <reference path="./memory.d.ts" />
6
+ /// <reference path="./macros.d.ts" />
7
7
  /// <reference path="./traits.d.ts" />
@@ -0,0 +1,150 @@
1
+ /// <reference path="./kinds.d.ts" />
2
+
3
+ type MemoryCapacity = 64 | 128 | 512;
4
+ /**
5
+ * Allows you to view and modify the data of memory cells and memory banks.
6
+ */
7
+ declare class Memory<S extends MemoryCapacity = 64> {
8
+ constructor(cell: BasicBuilding, size?: S);
9
+
10
+ [Symbol.iterator](): IterableIterator<number>;
11
+ [index: number]: number;
12
+
13
+ /**
14
+ * The practical length of the memory view.
15
+ */
16
+ readonly length: S;
17
+ }
18
+
19
+ /**
20
+ * Creates a mutable, dynamic access array, the length is constant.
21
+ *
22
+ * The instructions for dynamic accesses
23
+ */
24
+ declare class MutableArray<T> {
25
+ /**
26
+ * Creates an array with fixed size that supports dynamic index accesses.
27
+ *
28
+ * The array can contain any value assignable to a store.
29
+ */
30
+ constructor(init: readonly T[]);
31
+ constructor(length: number);
32
+
33
+ [index: number]: T;
34
+
35
+ /** Fills the array with a given value */
36
+ fill(value: T): void;
37
+
38
+ /**
39
+ * Returns the item at the given index. Negative indexes are relative to `this.size`.
40
+ *
41
+ * ```js
42
+ * print(array.at(-1)); // equal to array[array.size - 1]
43
+ * ```
44
+ */
45
+ at(index: number): T;
46
+
47
+ /** The number of items preallocated for this array */
48
+ readonly size: number;
49
+
50
+ [Symbol.iterator](): IterableIterator<T>;
51
+ }
52
+
53
+ declare class DynamicArray<T> extends MutableArray<T> {
54
+ /**
55
+ * Creates an array with a predefined capacity that supports dynamic index accesses.
56
+ *
57
+ * The array can contain any value assignable to a store.
58
+ */
59
+ constructor(init: readonly T[]);
60
+ constructor(length: number);
61
+
62
+ /**
63
+ * Sets the last item of the array to `undefined` and decreases its length by 1.
64
+ *
65
+ * This method only generates the instructions for getting the value when needed.
66
+ *
67
+ * You can use `unchecked` to skip the bound check.
68
+ *
69
+ * ```js
70
+ * array.pop(); // doesn't generate getter instructions
71
+ * print(array.pop()); // generates getter instructions
72
+ * unchecked(array.pop()); // doesn't check the array length
73
+ * ```
74
+ */
75
+ pop(): T;
76
+ /**
77
+ * Adds the given item to the end of the array.
78
+ *
79
+ * If the array is full, the proccess is skipped.
80
+ *
81
+ * You can use `unchecked` to skip the length check.
82
+ *
83
+ * ```js
84
+ * // only do this if you know the array isn't full
85
+ * unchecked(array.push(Items.copper));
86
+ *
87
+ * array.push(Items.beryllium);
88
+ * ```
89
+ */
90
+ push(item: T): void;
91
+
92
+ /**
93
+ * Removes the item at the given index.
94
+ *
95
+ * This method only generates the instructions for getting the value when needed.
96
+ *
97
+ * The index must be within the range: [`0`, `this.length - 1`]
98
+ *
99
+ * You can use `unchecked` to skip the bound check.
100
+ *
101
+ * ```js
102
+ *
103
+ * let a = array.removeAt(i); // generates getter instructions
104
+ * array.removeAt(i); // doesn't generate getter instructions
105
+ *
106
+ * // only do this if you know the index is valid
107
+ * unchecked(array.removeAt(i));
108
+ * ```
109
+ */
110
+ removeAt(index: number): T;
111
+
112
+ /**
113
+ * Returns the item at the given index. Negative indexes are relative to `this.length`.
114
+ *
115
+ * ```js
116
+ * print(array.at(-1)); // equal to array[array.length - 1]
117
+ * ```
118
+ */
119
+ at(index: number): T;
120
+
121
+ /** The current length of the array, it can't be directly modified by the user. */
122
+ get length(): number;
123
+ }
124
+
125
+ /**
126
+ * A function that tells the compiler not to add
127
+ * bound checking in the array accesses in the given expression.
128
+ *
129
+ * Only access that are computed inside the call are unchecked:
130
+ *
131
+ * ```js
132
+ * // checked
133
+ * const a = array[i]
134
+ * // unckecked
135
+ * const b = unchecked(array[i])
136
+ *
137
+ * // the array accesses inside `doSomething`
138
+ * // are NOT unchecked
139
+ * unchecked(doSomething(i))
140
+ *
141
+ * // only `array[i * 2]` is unchecked
142
+ * const c = unchecked(doSomething(i) * array[i * 2])
143
+ *
144
+ * function doSomething(i) {
145
+ * // will always be checked
146
+ * return (array[i - 1] + array[i + 1]) / 2
147
+ * }
148
+ * ```
149
+ */
150
+ declare function unchecked<T>(expression: T): T;
package/lib/traits.d.ts CHANGED
@@ -23,7 +23,7 @@ declare global {
23
23
  readonly [I in keyof typeof Items]: number;
24
24
  } & {
25
25
  readonly totalItems: number;
26
- readonly firstItem: ItemSymbol | null;
26
+ readonly firstItem?: ItemSymbol;
27
27
  readonly itemCapacity: number;
28
28
  }
29
29
  > {}
@@ -93,7 +93,7 @@ declare global {
93
93
 
94
94
  interface Boosted
95
95
  extends WithSymbols<{
96
- readonly boosting: number;
96
+ readonly boosting: boolean;
97
97
  }> {}
98
98
 
99
99
  interface Mining
@@ -120,13 +120,13 @@ declare global {
120
120
 
121
121
  interface Nameable
122
122
  extends WithSymbols<{
123
- readonly name: string | null;
123
+ readonly name?: string;
124
124
  }> {}
125
125
 
126
126
  interface PayloadHolder
127
127
  extends WithSymbols<{
128
128
  readonly payloadCount: number;
129
- readonly payloadType: symbol | null;
129
+ readonly payloadType?: symbol;
130
130
  }> {}
131
131
 
132
132
  interface WithEnable
@@ -134,7 +134,7 @@ declare global {
134
134
  enabled: boolean;
135
135
  }> {}
136
136
  interface WithConfig<
137
- T extends symbol | number | null = symbol | null
137
+ T extends symbol | number | undefined = symbol | undefined
138
138
  > extends WithSymbols<{
139
139
  readonly config: T;
140
140
  }> {}
package/package.json CHANGED
@@ -1,11 +1,22 @@
1
1
  {
2
2
  "name": "mlogjs",
3
- "version": "0.4.10",
3
+ "version": "0.5.1",
4
4
  "description": "Compiler that compiles Javascript to Mindustry Logic Code.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
7
7
  "bin": "./dist/bin.cjs",
8
8
  "types": "./dist/index.d.ts",
9
+ "scripts": {
10
+ "clean": "rm -rf ../docs dist build",
11
+ "build": "rollup -c",
12
+ "build:dev": "rollup -c --environment DEV",
13
+ "dev": "ts-node src/bin",
14
+ "test": "jest",
15
+ "lint": "eslint src/**/*.ts",
16
+ "coverage": "jest --coverage",
17
+ "start": "pnpm run build && pnpm i -g . && mlogjs",
18
+ "prepublishOnly": "pnpm run build"
19
+ },
9
20
  "repository": {
10
21
  "type": "git",
11
22
  "url": "git+https://github.com/weisrc/mlogjs.git"
@@ -17,28 +28,31 @@
17
28
  "url": "https://github.com/weisrc/mlogjs/issues"
18
29
  },
19
30
  "homepage": "https://github.com/weisrc/mlogjs#readme",
31
+ "engines": {
32
+ "node": ">=16"
33
+ },
20
34
  "dependencies": {
21
- "@babel/parser": "^7.20.0",
22
- "@babel/types": "^7.20.0",
35
+ "@babel/parser": "^7.20.7",
36
+ "@babel/types": "^7.20.7",
23
37
  "chalk": "^4.1.2",
24
38
  "cli-highlight": "^2.1.11",
25
- "yargs": "^17.0.1"
39
+ "yargs": "^17.6.2"
26
40
  },
27
41
  "devDependencies": {
28
42
  "@rollup/plugin-alias": "^4.0.2",
29
- "@rollup/plugin-typescript": "^9.0.2",
30
- "@types/jest": "^29.0.3",
31
- "@types/node": "^15.14.9",
32
- "@types/yargs": "^17.0.13",
33
- "@typescript-eslint/eslint-plugin": "^5.38.0",
34
- "@typescript-eslint/parser": "^5.38.0",
35
- "eslint": "^8.24.0",
36
- "jest": "^29.0.3",
43
+ "@rollup/plugin-typescript": "^11.0.0",
44
+ "@types/jest": "^29.2.5",
45
+ "@types/node": "^16.18.10",
46
+ "@types/yargs": "^17.0.19",
47
+ "@typescript-eslint/eslint-plugin": "^5.48.2",
48
+ "@typescript-eslint/parser": "^5.48.2",
49
+ "eslint": "^8.32.0",
50
+ "jest": "^29.3.1",
37
51
  "npm-run-all": "^4.1.5",
38
- "rollup": "^3.2.3",
39
- "ts-jest": "^29.0.2",
52
+ "rollup": "^3.10.0",
53
+ "ts-jest": "^29.0.5",
40
54
  "ts-node": "^10.9.1",
41
- "tslib": "^2.3.1",
55
+ "tslib": "^2.4.1",
42
56
  "typescript": "*"
43
57
  },
44
58
  "files": [
@@ -47,15 +61,5 @@
47
61
  "lib",
48
62
  "LICENSE",
49
63
  "README.md"
50
- ],
51
- "scripts": {
52
- "clean": "rm -rf ../docs dist build",
53
- "build": "rollup -c",
54
- "build:dev": "rollup -c --environment DEV",
55
- "dev": "ts-node src/bin",
56
- "test": "jest",
57
- "lint": "eslint src/**/*.ts",
58
- "coverage": "jest --coverage",
59
- "start": "pnpm run build && pnpm i -g . && mlogjs"
60
- }
61
- }
64
+ ]
65
+ }