mlogjs 0.2.0 → 0.3.0-beta.0

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 (264) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +68 -18
  3. package/build/Compiler.js +32 -47
  4. package/build/Compiler.js.map +1 -1
  5. package/build/CompilerError.js +11 -0
  6. package/build/CompilerError.js.map +1 -0
  7. package/build/Scope.js +17 -7
  8. package/build/Scope.js.map +1 -1
  9. package/build/bin.js +45 -12
  10. package/build/bin.js.map +1 -1
  11. package/build/handlers/BlockStatement.js.map +1 -1
  12. package/build/handlers/CallExpression.js.map +1 -1
  13. package/build/handlers/File.js +9 -0
  14. package/build/handlers/File.js.map +1 -0
  15. package/build/handlers/ForStatement.js.map +1 -1
  16. package/build/handlers/Function.js +20 -9
  17. package/build/handlers/Function.js.map +1 -1
  18. package/build/handlers/IfStatement.js.map +1 -1
  19. package/build/handlers/Literal.js +11 -14
  20. package/build/handlers/Literal.js.map +1 -1
  21. package/build/handlers/Object.js +16 -5
  22. package/build/handlers/Object.js.map +1 -1
  23. package/build/handlers/OperationExpressions.js +6 -1
  24. package/build/handlers/OperationExpressions.js.map +1 -1
  25. package/build/handlers/Program.js +1 -1
  26. package/build/handlers/Program.js.map +1 -1
  27. package/build/handlers/Statements.js.map +1 -1
  28. package/build/handlers/TemplateExpression.js.map +1 -1
  29. package/build/handlers/VariableDeclaration.js +25 -9
  30. package/build/handlers/VariableDeclaration.js.map +1 -1
  31. package/build/handlers/WhileStatement.js.map +1 -1
  32. package/build/handlers/index.js +1 -0
  33. package/build/handlers/index.js.map +1 -1
  34. package/build/index.js +5 -5
  35. package/build/index.js.map +1 -1
  36. package/build/initScope.js +40 -0
  37. package/build/initScope.js.map +1 -0
  38. package/build/instructions/InstructionBase.js +1 -1
  39. package/build/instructions/InstructionBase.js.map +1 -1
  40. package/build/instructions/JumpInstruction.js +1 -1
  41. package/build/instructions/JumpInstruction.js.map +1 -1
  42. package/build/instructions/OperationInstruction.js.map +1 -1
  43. package/build/macros/Building.js +16 -8
  44. package/build/macros/Building.js.map +1 -1
  45. package/build/macros/Function.js +1 -1
  46. package/build/macros/Function.js.map +1 -1
  47. package/build/macros/Math.js +13 -8
  48. package/build/macros/Math.js.map +1 -1
  49. package/build/macros/Memory.js +7 -5
  50. package/build/macros/Memory.js.map +1 -1
  51. package/build/macros/Namespace.js +24 -11
  52. package/build/macros/Namespace.js.map +1 -1
  53. package/build/macros/Other.js +2 -1
  54. package/build/macros/Other.js.map +1 -1
  55. package/build/macros/RawValue.js +2 -1
  56. package/build/macros/RawValue.js.map +1 -1
  57. package/build/macros/commands/{control.js → Control.js} +4 -3
  58. package/build/macros/commands/Control.js.map +1 -0
  59. package/build/macros/commands/Draw.js +4 -3
  60. package/build/macros/commands/Draw.js.map +1 -1
  61. package/build/macros/commands/DrawFlush.js +2 -1
  62. package/build/macros/commands/DrawFlush.js.map +1 -1
  63. package/build/macros/commands/GetLink.js +8 -4
  64. package/build/macros/commands/GetLink.js.map +1 -1
  65. package/build/macros/commands/Lookup.js +5 -4
  66. package/build/macros/commands/Lookup.js.map +1 -1
  67. package/build/macros/commands/Print.js +5 -1
  68. package/build/macros/commands/Print.js.map +1 -1
  69. package/build/macros/commands/PrintFlush.js +2 -1
  70. package/build/macros/commands/PrintFlush.js.map +1 -1
  71. package/build/macros/commands/Radar.js +16 -12
  72. package/build/macros/commands/Radar.js.map +1 -1
  73. package/build/macros/commands/Sensor.js +4 -3
  74. package/build/macros/commands/Sensor.js.map +1 -1
  75. package/build/macros/commands/UnitBind.js +2 -1
  76. package/build/macros/commands/UnitBind.js.map +1 -1
  77. package/build/macros/commands/UnitControl.js +13 -8
  78. package/build/macros/commands/UnitControl.js.map +1 -1
  79. package/build/macros/commands/UnitLocate.js +29 -8
  80. package/build/macros/commands/UnitLocate.js.map +1 -1
  81. package/build/macros/commands/UnitRadar.js +17 -10
  82. package/build/macros/commands/UnitRadar.js.map +1 -1
  83. package/build/macros/commands/Wait.js +2 -1
  84. package/build/macros/commands/Wait.js.map +1 -1
  85. package/build/operators.js.map +1 -1
  86. package/build/types.js +1 -1
  87. package/build/types.js.map +1 -1
  88. package/build/utils.js +7 -2
  89. package/build/utils.js.map +1 -1
  90. package/build/values/BaseValue.js +5 -5
  91. package/build/values/BaseValue.js.map +1 -1
  92. package/build/values/FunctionValue.js +25 -13
  93. package/build/values/FunctionValue.js.map +1 -1
  94. package/build/values/LiteralValue.js +5 -4
  95. package/build/values/LiteralValue.js.map +1 -1
  96. package/build/values/ObjectValue.js +11 -6
  97. package/build/values/ObjectValue.js.map +1 -1
  98. package/build/values/StoreValue.js +3 -2
  99. package/build/values/StoreValue.js.map +1 -1
  100. package/build/values/TempValue.js +18 -7
  101. package/build/values/TempValue.js.map +1 -1
  102. package/build/values/VoidValue.js +8 -7
  103. package/build/values/VoidValue.js.map +1 -1
  104. package/dist/bin.cjs +82 -0
  105. package/dist/bin.cjs.map +1 -0
  106. package/dist/index.cjs +2187 -0
  107. package/dist/index.cjs.map +1 -0
  108. package/dist/index.mjs +2162 -0
  109. package/dist/index.mjs.map +1 -0
  110. package/dist/types/Compiler.d.ts +26 -0
  111. package/dist/types/CompilerError.d.ts +9 -0
  112. package/dist/types/Scope.d.ts +24 -0
  113. package/dist/types/bin.d.ts +1 -0
  114. package/dist/types/handlers/BlockStatement.d.ts +2 -0
  115. package/dist/types/handlers/CallExpression.d.ts +3 -0
  116. package/dist/types/handlers/File.d.ts +2 -0
  117. package/dist/types/handlers/ForStatement.d.ts +2 -0
  118. package/{build → dist/types}/handlers/Function.d.ts +1 -0
  119. package/{build → dist/types}/handlers/Identifier.d.ts +0 -0
  120. package/dist/types/handlers/IfStatement.d.ts +2 -0
  121. package/dist/types/handlers/Literal.d.ts +5 -0
  122. package/{build → dist/types}/handlers/Object.d.ts +2 -0
  123. package/{build → dist/types}/handlers/OperationExpressions.d.ts +1 -0
  124. package/dist/types/handlers/Program.d.ts +2 -0
  125. package/dist/types/handlers/Statements.d.ts +5 -0
  126. package/dist/types/handlers/TemplateExpression.d.ts +2 -0
  127. package/dist/types/handlers/Typescript.d.ts +7 -0
  128. package/dist/types/handlers/VariableDeclaration.d.ts +3 -0
  129. package/dist/types/handlers/WhileStatement.d.ts +3 -0
  130. package/{build → dist/types}/handlers/index.d.ts +2 -0
  131. package/dist/types/index.d.ts +2 -0
  132. package/dist/types/initScope.d.ts +5 -0
  133. package/{build → dist/types}/instructions/AddressResolver.d.ts +1 -1
  134. package/{build → dist/types}/instructions/ControlInstructions.d.ts +0 -3
  135. package/{build → dist/types}/instructions/EndInstruction.d.ts +0 -0
  136. package/{build → dist/types}/instructions/InstructionBase.d.ts +4 -4
  137. package/{build → dist/types}/instructions/JumpInstruction.d.ts +1 -1
  138. package/{build → dist/types}/instructions/OperationInstruction.d.ts +1 -1
  139. package/{build → dist/types}/instructions/SetCounterInstruction.d.ts +0 -0
  140. package/{build → dist/types}/instructions/SetInstruction.d.ts +1 -0
  141. package/{build → dist/types}/instructions/ZeroSpaceInstruction.d.ts +0 -0
  142. package/{build → dist/types}/instructions/index.d.ts +0 -0
  143. package/{build → dist/types}/macros/Building.d.ts +1 -2
  144. package/dist/types/macros/Entities.d.ts +11 -0
  145. package/dist/types/macros/Function.d.ts +13 -0
  146. package/{build/macros/Draw.d.ts → dist/types/macros/GetGlobal.d.ts} +1 -1
  147. package/{build → dist/types}/macros/Math.d.ts +0 -0
  148. package/{build → dist/types}/macros/Memory.d.ts +0 -0
  149. package/{build → dist/types}/macros/Namespace.d.ts +0 -5
  150. package/{build → dist/types}/macros/Other.d.ts +0 -0
  151. package/{build → dist/types}/macros/RawValue.d.ts +0 -0
  152. package/{build/macros/commands/Asm.d.ts → dist/types/macros/commands/Control.d.ts} +1 -1
  153. package/{build/macros/helpers/GetVar.d.ts → dist/types/macros/commands/Draw.d.ts} +1 -1
  154. package/{build → dist/types}/macros/commands/DrawFlush.d.ts +1 -1
  155. package/{build/macros/commands/Draw.d.ts → dist/types/macros/commands/End.d.ts} +1 -1
  156. package/{build → dist/types}/macros/commands/GetLink.d.ts +0 -0
  157. package/{build → dist/types}/macros/commands/Lookup.d.ts +0 -0
  158. package/{build → dist/types}/macros/commands/Print.d.ts +1 -1
  159. package/{build → dist/types}/macros/commands/PrintFlush.d.ts +1 -1
  160. package/{build → dist/types}/macros/commands/Radar.d.ts +0 -0
  161. package/{build → dist/types}/macros/commands/Sensor.d.ts +0 -0
  162. package/{build → dist/types}/macros/commands/UnitBind.d.ts +1 -1
  163. package/dist/types/macros/commands/UnitControl.d.ts +5 -0
  164. package/{build → dist/types}/macros/commands/UnitLocate.d.ts +0 -0
  165. package/{build → dist/types}/macros/commands/UnitRadar.d.ts +0 -0
  166. package/{build → dist/types}/macros/commands/Wait.d.ts +1 -1
  167. package/{build → dist/types}/macros/commands/index.d.ts +1 -0
  168. package/{build → dist/types}/macros/index.d.ts +0 -1
  169. package/{build → dist/types}/operators.d.ts +1 -1
  170. package/dist/types/types.d.ts +209 -0
  171. package/dist/types/utils.d.ts +24 -0
  172. package/dist/types/values/BaseValue.d.ts +7 -0
  173. package/dist/types/values/DestructuringValue.d.ts +17 -0
  174. package/{build → dist/types}/values/FunctionValue.d.ts +21 -8
  175. package/{build → dist/types}/values/LiteralValue.d.ts +2 -1
  176. package/dist/types/values/ObjectValue.d.ts +23 -0
  177. package/dist/types/values/SenseableValue.d.ts +23 -0
  178. package/dist/types/values/StackValue.d.ts +16 -0
  179. package/{build → dist/types}/values/StoreValue.d.ts +7 -3
  180. package/{build → dist/types}/values/TempValue.d.ts +9 -2
  181. package/dist/types/values/ValueOwner.d.ts +27 -0
  182. package/dist/types/values/VoidValue.d.ts +16 -0
  183. package/{build → dist/types}/values/index.d.ts +2 -1
  184. package/lib/commands.d.ts +532 -326
  185. package/lib/eslib/index.d.ts +3 -3
  186. package/lib/eslib/lib.d.ts +9 -9
  187. package/lib/eslib/lib.es2015.collection.d.ts +89 -89
  188. package/lib/eslib/lib.es2015.core.d.ts +16 -16
  189. package/lib/eslib/lib.es2015.d.ts +30 -30
  190. package/lib/eslib/lib.es2015.generator.d.ts +79 -79
  191. package/lib/eslib/lib.es2015.iterable.d.ts +70 -70
  192. package/lib/eslib/lib.es5.d.ts +295 -295
  193. package/lib/eslib/lib.es6.d.ts +18 -18
  194. package/lib/globals.d.ts +341 -328
  195. package/lib/helpers.d.ts +23 -23
  196. package/lib/index.d.ts +7 -7
  197. package/lib/kinds.d.ts +36 -36
  198. package/lib/memory.d.ts +17 -17
  199. package/lib/traits.d.ts +141 -121
  200. package/lib/util.d.ts +32 -32
  201. package/package.json +68 -48
  202. package/build/Compiler.d.ts +0 -18
  203. package/build/Scope.d.ts +0 -26
  204. package/build/bin.d.ts +0 -2
  205. package/build/handlers/BlockStatement.d.ts +0 -2
  206. package/build/handlers/CallExpression.d.ts +0 -3
  207. package/build/handlers/ForStatement.d.ts +0 -2
  208. package/build/handlers/IfStatement.d.ts +0 -2
  209. package/build/handlers/Literal.d.ts +0 -2
  210. package/build/handlers/Program.d.ts +0 -2
  211. package/build/handlers/Statements.d.ts +0 -5
  212. package/build/handlers/TemplateExpression.d.ts +0 -2
  213. package/build/handlers/VariableDeclaration.d.ts +0 -3
  214. package/build/handlers/WhileStatement.d.ts +0 -2
  215. package/build/index.d.ts +0 -1
  216. package/build/macros/Blocks.d.ts +0 -5
  217. package/build/macros/Blocks.js +0 -143
  218. package/build/macros/Blocks.js.map +0 -1
  219. package/build/macros/Draw.js +0 -39
  220. package/build/macros/Draw.js.map +0 -1
  221. package/build/macros/Function.d.ts +0 -12
  222. package/build/macros/Items.d.ts +0 -5
  223. package/build/macros/Items.js +0 -20
  224. package/build/macros/Items.js.map +0 -1
  225. package/build/macros/Liquids.d.ts +0 -5
  226. package/build/macros/Liquids.js +0 -18
  227. package/build/macros/Liquids.js.map +0 -1
  228. package/build/macros/Symbol.d.ts +0 -0
  229. package/build/macros/Symbol.js +0 -1
  230. package/build/macros/Symbol.js.map +0 -1
  231. package/build/macros/SymbolNamespace.d.ts +0 -0
  232. package/build/macros/SymbolNamespace.js +0 -1
  233. package/build/macros/SymbolNamespace.js.map +0 -1
  234. package/build/macros/TypeFactory.d.ts +0 -8
  235. package/build/macros/TypeFactory.js +0 -22
  236. package/build/macros/TypeFactory.js.map +0 -1
  237. package/build/macros/Units.d.ts +0 -5
  238. package/build/macros/Units.js +0 -18
  239. package/build/macros/Units.js.map +0 -1
  240. package/build/macros/Vars.d.ts +0 -5
  241. package/build/macros/Vars.js +0 -18
  242. package/build/macros/Vars.js.map +0 -1
  243. package/build/macros/commands/Asm.js +0 -21
  244. package/build/macros/commands/Asm.js.map +0 -1
  245. package/build/macros/commands/UnitControl.d.ts +0 -5
  246. package/build/macros/commands/control.d.ts +0 -5
  247. package/build/macros/commands/control.js.map +0 -1
  248. package/build/macros/commands/io.d.ts +0 -8
  249. package/build/macros/commands/io.js +0 -47
  250. package/build/macros/commands/io.js.map +0 -1
  251. package/build/macros/helpers/GetBuilding.d.ts +0 -5
  252. package/build/macros/helpers/GetBuilding.js +0 -16
  253. package/build/macros/helpers/GetBuilding.js.map +0 -1
  254. package/build/macros/helpers/GetVar.js +0 -16
  255. package/build/macros/helpers/GetVar.js.map +0 -1
  256. package/build/macros/helpers/index.d.ts +0 -2
  257. package/build/macros/helpers/index.js +0 -15
  258. package/build/macros/helpers/index.js.map +0 -1
  259. package/build/types.d.ts +0 -49
  260. package/build/utils.d.ts +0 -3
  261. package/build/values/BaseValue.d.ts +0 -5
  262. package/build/values/ObjectValue.d.ts +0 -17
  263. package/build/values/VoidValue.d.ts +0 -11
  264. package/dist/bundle.js +0 -1
package/lib/helpers.d.ts CHANGED
@@ -1,23 +1,23 @@
1
- /// <reference path="./kinds.d.ts" />
2
-
3
- /**
4
- * Allows getting unlisted processor variables or symbols.
5
- *
6
- * Using this method is discouraged because most values are
7
- * already accessible under the namespaces `Units`, `Blocks`,
8
- * `Items`, `Liquids`, `ControlKind`, `Vars` and `UnitCommands`.
9
- *
10
- * @param key The identifier of the value
11
- */
12
- declare function getVar<T>(key: string): T;
13
-
14
- /**
15
- * Gets a building linked to the processor by its name.
16
- *
17
- * @param name
18
- */
19
- declare function getBuilding<T extends BasicBuilding = AnyBuilding>(
20
- name: string
21
- ): T;
22
-
23
- declare function concat(...strings: string[]): string;
1
+ /// <reference path="./kinds.d.ts" />
2
+
3
+ /**
4
+ * Allows getting unlisted processor variables or symbols.
5
+ *
6
+ * Using this method is discouraged because most values are
7
+ * already accessible under the namespaces `Units`, `Blocks`,
8
+ * `Items`, `Liquids`, `ControlKind`, `Vars` and `UnitCommands`.
9
+ *
10
+ * @param name The identifier of the value
11
+ */
12
+ declare function getVar<T>(name: string): T;
13
+
14
+ /**
15
+ * Gets a building linked to the processor by its name.
16
+ *
17
+ * @param name
18
+ */
19
+ declare function getBuilding<T extends BasicBuilding = AnyBuilding>(
20
+ name: string
21
+ ): T;
22
+
23
+ declare function concat(...strings: string[]): string;
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- /// <reference path="./eslib/index.d.ts" />
2
- /// <reference path="./commands.d.ts" />
3
- /// <reference path="./globals.d.ts" />
4
- /// <reference path="./helpers.d.ts" />
5
- /// <reference path="./kinds.d.ts" />
6
- /// <reference path="./memory.d.ts" />
7
- /// <reference path="./traits.d.ts" />
1
+ /// <reference path="./eslib/index.d.ts" />
2
+ /// <reference path="./commands.d.ts" />
3
+ /// <reference path="./globals.d.ts" />
4
+ /// <reference path="./helpers.d.ts" />
5
+ /// <reference path="./kinds.d.ts" />
6
+ /// <reference path="./memory.d.ts" />
7
+ /// <reference path="./traits.d.ts" />
package/lib/kinds.d.ts CHANGED
@@ -1,36 +1,36 @@
1
- /// <reference path="./traits.d.ts" />
2
-
3
- interface BasicUnit
4
- extends ItemHolder,
5
- Shooting,
6
- WithHealth,
7
- Rotatable,
8
- Spaced,
9
- Ranged,
10
- Typed<UnitSymbol>,
11
- Flagged,
12
- Controllable,
13
- Nameable {}
14
-
15
- interface AnyUnit extends BasicUnit, Boosted {}
16
-
17
- interface BasicBuilding
18
- extends LiquidHolder,
19
- ItemHolder,
20
- PowerHolder,
21
- WithHealth,
22
- WithEffiency,
23
- WithTimescale,
24
- Rotatable,
25
- Spaced,
26
- Ranged,
27
- Typed<BlockSymbol>,
28
- WithEnable,
29
- WithConfig {}
30
-
31
- interface BasicTurret extends BasicBuilding, Shooting, WithProgress {}
32
-
33
- // just to make this future proof
34
- interface AnyTurret extends BasicTurret {}
35
-
36
- interface AnyBuilding extends AnyTurret, Heatable {}
1
+ /// <reference path="./traits.d.ts" />
2
+
3
+ interface BasicUnit
4
+ extends ItemHolder,
5
+ Shooting,
6
+ WithHealth,
7
+ Rotatable,
8
+ Spaced,
9
+ Ranged,
10
+ Typed<UnitSymbol>,
11
+ Flagged,
12
+ Controllable,
13
+ Nameable {}
14
+
15
+ interface AnyUnit extends BasicUnit, Boosted {}
16
+
17
+ interface BasicBuilding
18
+ extends LiquidHolder,
19
+ ItemHolder,
20
+ PowerHolder,
21
+ WithHealth,
22
+ WithEffiency,
23
+ WithTimescale,
24
+ Rotatable,
25
+ Spaced,
26
+ Ranged,
27
+ Typed<BlockSymbol>,
28
+ WithEnable,
29
+ WithConfig {}
30
+
31
+ interface BasicTurret extends BasicBuilding, Shooting, WithProgress {}
32
+
33
+ // just to make this future proof
34
+ interface AnyTurret extends BasicTurret {}
35
+
36
+ interface AnyBuilding extends AnyTurret, Heatable {}
package/lib/memory.d.ts CHANGED
@@ -1,17 +1,17 @@
1
- /// <reference path="./kinds.d.ts" />
2
-
3
- type MemoryCapacity = 64 | 512;
4
- /**
5
- * A wrapper around memory cells/banks that is compatible with custom types.
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
- }
1
+ /// <reference path="./kinds.d.ts" />
2
+
3
+ type MemoryCapacity = 64 | 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
+ }
package/lib/traits.d.ts CHANGED
@@ -1,121 +1,141 @@
1
- import "./globals";
2
- import "./custom-lib";
3
-
4
- type LogicSymbols = typeof Items & typeof Liquids & typeof LAccess;
5
-
6
- type WithSymbols<T extends Record<string, unknown>> = T & {
7
- readonly [K in keyof (LogicSymbols | T) as LogicSymbols[K]]: T[K];
8
- };
9
-
10
- declare global {
11
- type LiquidHolder = WithSymbols<
12
- {
13
- readonly [L in keyof typeof Liquids]: number;
14
- } & {
15
- readonly totalLiquids: number;
16
- readonly liquidCapacity: number;
17
- }
18
- >;
19
-
20
- type ItemHolder = WithSymbols<
21
- {
22
- readonly [I in keyof typeof Items]: number;
23
- } & {
24
- readonly totalItems: number;
25
- readonly firstItem: ItemSymbol | null;
26
- readonly itemCapacity: number;
27
- }
28
- >;
29
-
30
- type PowerHolder = WithSymbols<{
31
- readonly totalPower: number;
32
- readonly powerCapacity: number;
33
- readonly powerNetStored: number;
34
- readonly powerNetCapacity: number;
35
- readonly powerNetIn: number;
36
- readonly powerNetOut: number;
37
- }>;
38
-
39
- type Shooting = WithSymbols<{
40
- readonly shootX: number;
41
- readonly shootY: number;
42
- readonly ammo: number;
43
- readonly ammoCapacity: number;
44
- }>;
45
-
46
- type WithHealth = WithSymbols<{
47
- readonly health: number;
48
- readonly maxHealth: number;
49
- readonly dead: boolean;
50
- }>;
51
-
52
- type Heatable = WithSymbols<{
53
- readonly heat: number;
54
- }>;
55
-
56
- type WithEffiency = WithSymbols<{
57
- readonly efficiency: number;
58
- }>;
59
-
60
- type WithProgress = WithSymbols<{
61
- readonly progress: number;
62
- }>;
63
-
64
- type WithTimescale = WithSymbols<{
65
- readonly timescale: number;
66
- }>;
67
-
68
- type Rotatable = WithSymbols<{
69
- readonly rotation: number;
70
- }>;
71
-
72
- type Spaced = WithSymbols<{
73
- readonly x: number;
74
- readonly y: number;
75
- readonly size: number;
76
- }>;
77
-
78
- type Ranged = WithSymbols<{
79
- readonly range: number;
80
- }>;
81
-
82
- type Boosted = WithSymbols<{
83
- readonly boosting: number;
84
- }>;
85
-
86
- type Mining = WithSymbols<{
87
- readonly mineX: number;
88
- readonly mineY: number;
89
- readonly mining: number;
90
- }>;
91
-
92
- type Typed<T extends symbol = symbol> = WithSymbols<{
93
- readonly type: T;
94
- }>;
95
- type Flagged = WithSymbols<{
96
- readonly flag: number;
97
- }>;
98
-
99
- type Controllable = WithSymbols<{
100
- readonly controlled: 0 | ControlKind;
101
- readonly controller: AnyUnit | BasicBuilding;
102
- }>;
103
-
104
- type Nameable = WithSymbols<{
105
- readonly name: string | null;
106
- }>;
107
-
108
- type PayloadHolder = WithSymbols<{
109
- readonly payloadCount: number;
110
- readonly payloadType: symbol | null;
111
- }>;
112
-
113
- type WithEnable = WithSymbols<{
114
- enabled: boolean;
115
- }>;
116
-
117
- type WithConfig<T extends symbol | number | null = symbol | null> =
118
- WithSymbols<{
119
- readonly config: T;
120
- }>;
121
- }
1
+ import "./globals";
2
+
3
+ type LogicSymbols = typeof Items & typeof Liquids & typeof LAccess;
4
+
5
+ type WithSymbols<T extends Record<string, unknown>> = T & {
6
+ readonly [K in keyof (LogicSymbols | T) as LogicSymbols[K]]: T[K];
7
+ };
8
+
9
+ declare global {
10
+ interface LiquidHolder
11
+ extends WithSymbols<
12
+ {
13
+ readonly [L in keyof typeof Liquids]: number;
14
+ } & {
15
+ readonly totalLiquids: number;
16
+ readonly liquidCapacity: number;
17
+ }
18
+ > {}
19
+
20
+ interface ItemHolder
21
+ extends WithSymbols<
22
+ {
23
+ readonly [I in keyof typeof Items]: number;
24
+ } & {
25
+ readonly totalItems: number;
26
+ readonly firstItem: ItemSymbol | null;
27
+ readonly itemCapacity: number;
28
+ }
29
+ > {}
30
+
31
+ interface PowerHolder
32
+ extends WithSymbols<{
33
+ readonly totalPower: number;
34
+ readonly powerCapacity: number;
35
+ readonly powerNetStored: number;
36
+ readonly powerNetCapacity: number;
37
+ readonly powerNetIn: number;
38
+ readonly powerNetOut: number;
39
+ }> {}
40
+
41
+ interface Shooting
42
+ extends WithSymbols<{
43
+ readonly shootX: number;
44
+ readonly shootY: number;
45
+ readonly ammo: number;
46
+ readonly ammoCapacity: number;
47
+ }> {}
48
+
49
+ interface WithHealth
50
+ extends WithSymbols<{
51
+ readonly health: number;
52
+ readonly maxHealth: number;
53
+ readonly dead: boolean;
54
+ }> {}
55
+
56
+ interface Heatable
57
+ extends WithSymbols<{
58
+ readonly heat: number;
59
+ }> {}
60
+
61
+ interface WithEffiency
62
+ extends WithSymbols<{
63
+ readonly efficiency: number;
64
+ }> {}
65
+
66
+ interface WithProgress
67
+ extends WithSymbols<{
68
+ readonly progress: number;
69
+ }> {}
70
+
71
+ interface WithTimescale
72
+ extends WithSymbols<{
73
+ readonly timescale: number;
74
+ }> {}
75
+
76
+ interface Rotatable
77
+ extends WithSymbols<{
78
+ readonly rotation: number;
79
+ }> {}
80
+
81
+ interface Spaced
82
+ extends WithSymbols<{
83
+ readonly x: number;
84
+ readonly y: number;
85
+ readonly size: number;
86
+ }> {}
87
+
88
+ interface Ranged
89
+ extends WithSymbols<{
90
+ readonly range: number;
91
+ }> {}
92
+
93
+ interface Boosted
94
+ extends WithSymbols<{
95
+ readonly boosting: number;
96
+ }> {}
97
+
98
+ interface Mining
99
+ extends WithSymbols<{
100
+ readonly mineX: number;
101
+ readonly mineY: number;
102
+ readonly mining: number;
103
+ }> {}
104
+
105
+ interface Typed<T extends symbol = symbol>
106
+ extends WithSymbols<{
107
+ readonly type: T;
108
+ }> {}
109
+ interface Flagged
110
+ extends WithSymbols<{
111
+ readonly flag: number;
112
+ }> {}
113
+
114
+ interface Controllable
115
+ extends WithSymbols<{
116
+ readonly controlled: 0 | ControlKind;
117
+ readonly controller: AnyUnit | BasicBuilding;
118
+ }> {}
119
+
120
+ interface Nameable
121
+ extends WithSymbols<{
122
+ readonly name: string | null;
123
+ }> {}
124
+
125
+ interface PayloadHolder
126
+ extends WithSymbols<{
127
+ readonly payloadCount: number;
128
+ readonly payloadType: symbol | null;
129
+ }> {}
130
+
131
+ interface WithEnable
132
+ extends WithSymbols<{
133
+ enabled: boolean;
134
+ }> {}
135
+
136
+ interface WithConfig<
137
+ T extends symbol | number | null = symbol | null
138
+ > extends WithSymbols<{
139
+ readonly config: T;
140
+ }> {}
141
+ }
package/lib/util.d.ts CHANGED
@@ -1,32 +1,32 @@
1
- export type TRadarFilter =
2
- | "any"
3
- | "enemy"
4
- | "ally"
5
- | "player"
6
- | "attacker"
7
- | "flying"
8
- | "boss"
9
- | "ground";
10
-
11
- export type TRadarFilterArray =
12
- | [TRadarFilter]
13
- | [TRadarFilter, TRadarFilter]
14
- | [TRadarFilter, TRadarFilter, TRadarFilter];
15
-
16
- export type TRadarSort =
17
- | "distance"
18
- | "health"
19
- | "shield"
20
- | "armor"
21
- | "maxHealth";
22
-
23
- export type TUnitLocateBuildingGroup =
24
- | "core"
25
- | "storage"
26
- | "generator"
27
- | "turret"
28
- | "factory"
29
- | "repair"
30
- | "rally"
31
- | "battery"
32
- | "reactor";
1
+ export type TRadarFilter =
2
+ | "any"
3
+ | "enemy"
4
+ | "ally"
5
+ | "player"
6
+ | "attacker"
7
+ | "flying"
8
+ | "boss"
9
+ | "ground";
10
+
11
+ export type TRadarFilterArray =
12
+ | [TRadarFilter]
13
+ | [TRadarFilter, TRadarFilter]
14
+ | [TRadarFilter, TRadarFilter, TRadarFilter];
15
+
16
+ export type TRadarSort =
17
+ | "distance"
18
+ | "health"
19
+ | "shield"
20
+ | "armor"
21
+ | "maxHealth";
22
+
23
+ export type TUnitLocateBuildingGroup =
24
+ | "core"
25
+ | "storage"
26
+ | "generator"
27
+ | "turret"
28
+ | "factory"
29
+ | "repair"
30
+ | "rally"
31
+ | "battery"
32
+ | "reactor";
package/package.json CHANGED
@@ -1,48 +1,68 @@
1
- {
2
- "name": "mlogjs",
3
- "version": "0.2.0",
4
- "description": "Compiler that compiles Javascript to Mindustry Logic Code.",
5
- "main": "build/index.js",
6
- "bin": "./build/bin.js",
7
- "scripts": {
8
- "build": "tsc && webpack",
9
- "start": "npm run build && npm i -g . && mlogjs",
10
- "prepublishOnly": "npm run build"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/weisrc/mlogjs.git"
15
- },
16
- "packageManager": "yarn@3.2.0",
17
- "keywords": [],
18
- "author": "str1z",
19
- "license": "MIT",
20
- "bugs": {
21
- "url": "https://github.com/weisrc/mlogjs/issues"
22
- },
23
- "homepage": "https://github.com/weisrc/mlogjs#readme",
24
- "dependencies": {
25
- "esprima": "^4.0.1",
26
- "yargs": "^17.0.1"
27
- },
28
- "devDependencies": {
29
- "@types/esprima": "^4.0.2",
30
- "@types/jest": "^27.4.1",
31
- "@types/node": "^15.3.0",
32
- "@types/yargs": "^16.0.1",
33
- "jest": "^27.5.1",
34
- "prettier": "^2.5.1",
35
- "ts-jest": "^27.1.3",
36
- "ts-loader": "^9.1.2",
37
- "typescript": "^4.6.2",
38
- "webpack": "^5.37.0",
39
- "webpack-cli": "^4.7.0"
40
- },
41
- "files": [
42
- "build",
43
- "dist",
44
- "lib",
45
- "LICENSE",
46
- "README.md"
47
- ]
48
- }
1
+ {
2
+ "name": "mlogjs",
3
+ "version": "0.3.0-beta.0",
4
+ "description": "Compiler that compiles Javascript to Mindustry Logic Code.",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "bin": "./dist/bin.cjs",
8
+ "types": "./dist/types",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/weisrc/mlogjs.git"
12
+ },
13
+ "keywords": [],
14
+ "author": "str1z",
15
+ "license": "MIT",
16
+ "bugs": {
17
+ "url": "https://github.com/weisrc/mlogjs/issues"
18
+ },
19
+ "homepage": "https://github.com/weisrc/mlogjs#readme",
20
+ "dependencies": {
21
+ "@babel/parser": "^7.17.7",
22
+ "chalk": "^4.1.2",
23
+ "cli-highlight": "^2.1.11",
24
+ "yargs": "^17.0.1"
25
+ },
26
+ "devDependencies": {
27
+ "@babel/types": "^7.17.0",
28
+ "@rollup/plugin-alias": "^3.1.9",
29
+ "@rollup/plugin-replace": "^4.0.0",
30
+ "@rollup/plugin-typescript": "^8.3.1",
31
+ "@types/estree": "^0.0.51",
32
+ "@types/jest": "^27.4.1",
33
+ "@types/node": "^15.3.0",
34
+ "@types/yargs": "^16.0.1",
35
+ "@typescript-eslint/eslint-plugin": "^5.15.0",
36
+ "@typescript-eslint/parser": "^5.15.0",
37
+ "eslint": "^8.11.0",
38
+ "jest": "^27.5.1",
39
+ "npm-run-all": "^4.1.5",
40
+ "rollup": "^2.70.1",
41
+ "ts-jest": "^27.1.3",
42
+ "ts-node": "^10.6.0",
43
+ "tslib": "^2.3.1",
44
+ "typedoc": "^0.22.12",
45
+ "typescript": "*"
46
+ },
47
+ "files": [
48
+ "build",
49
+ "dist",
50
+ "lib",
51
+ "LICENSE",
52
+ "README.md"
53
+ ],
54
+ "scripts": {
55
+ "clean": "rm -rf ../docs dist build",
56
+ "build": "rollup -c",
57
+ "build:dev": "rollup -c --environment DEV",
58
+ "dev": "ts-node src/bin",
59
+ "test": "jest",
60
+ "lint": "eslint src/**/*.ts",
61
+ "coverage": "jest --coverage",
62
+ "docs:doc": "mkdir -p ../docs && cp -r doc/. ../docs",
63
+ "docs:lib": "typedoc --out ../docs/lib lib/*",
64
+ "docs:src": "typedoc --out ../docs/src src/index.ts",
65
+ "docs": "run-p docs:lib docs:src docs:doc",
66
+ "start": "npm run build && npm i -g . && mlogjs"
67
+ }
68
+ }
@@ -1,18 +0,0 @@
1
- import { es, IScope, THandler, TValueInstructions } from "./types";
2
- declare type THandlerMap = {
3
- [k in es.Node["type"]]?: THandler;
4
- };
5
- export declare class Compiler {
6
- protected stackName?: string;
7
- protected usingStack: boolean;
8
- protected handlers: THandlerMap;
9
- constructor(stackName?: string);
10
- compile(script: string): string;
11
- protected resolve(valueInst: TValueInstructions): void;
12
- protected serialize(resLines: TValueInstructions): string;
13
- protected parse(script: string): import("esprima").Program;
14
- handle(scope: IScope, node: es.Node): TValueInstructions;
15
- handleEval(scope: IScope, node: es.Node): TValueInstructions;
16
- handleMany(scope: IScope, nodes: es.Node[], handler?: typeof Compiler.prototype.handle): TValueInstructions;
17
- }
18
- export {};
package/build/Scope.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import { AddressResolver } from "./instructions";
2
- import { IFunctionValue, IInstruction, IScope, IValue } from "./types";
3
- export declare class Scope implements IScope {
4
- parent: IScope;
5
- name: string;
6
- data: {
7
- [k: string]: IValue;
8
- };
9
- stacked: boolean;
10
- ntemp: number;
11
- inst: IInstruction[];
12
- break: AddressResolver;
13
- continue: AddressResolver;
14
- function: IFunctionValue;
15
- constructor(values: {
16
- [k: string]: IValue;
17
- }, parent?: IScope, stacked?: boolean, ntemp?: number, name?: string, inst?: any[]);
18
- copy(): IScope;
19
- createScope(): IScope;
20
- createFunction(name: string, stacked?: boolean): IScope;
21
- has(name: string): boolean;
22
- get(name: string): IValue;
23
- set(name: string, value: IValue): IValue;
24
- hardSet(name: string, value: IValue): IValue;
25
- make(name: string, storeName: string): IValue;
26
- }