@amxts/core 0.2.3 → 0.3.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 (71) hide show
  1. package/README.md +5 -5
  2. package/README.ru.md +5 -5
  3. package/as/amxts.d.ts +13 -3
  4. package/as/entities.ts +571 -501
  5. package/as/events.ts +3323 -557
  6. package/as/facade.ts +3079 -718
  7. package/as/fetch.ts +2 -2
  8. package/as/fs.ts +352 -59
  9. package/as/hlds.ts +121 -120
  10. package/as/hooks.ts +10585 -5177
  11. package/as/lib/check.ts +3 -2
  12. package/as/natives.ts +856 -1272
  13. package/as/promise.ts +37 -27
  14. package/as/vector.ts +94 -14
  15. package/includes/order.txt +17 -19
  16. package/node_modules/assemblyscript/std/assembly/index.d.ts +1 -1
  17. package/package.json +9 -6
  18. package/runtime/deps/assemblyscript/dist/asc.js +136 -42
  19. package/runtime/deps/assemblyscript/dist/assemblyscript.js +141 -141
  20. package/runtime/licenses/README.md +9 -7
  21. package/runtime/licenses/ReGameDLL-LICENSE +21 -0
  22. package/runtime/licenses/ReHLDS-LICENSE +21 -0
  23. package/runtime/licenses/zlib-LICENSE +22 -0
  24. package/runtime/natives.txt +618 -523
  25. package/runtime/patches/README.md +87 -1
  26. package/runtime/patches/assemblyscript-0.28.20-amxts.patch +4838 -416
  27. package/runtime/patches/wamr-2.4.5-amxts.patch +417 -5
  28. package/scripts/auto-imports.ts +1 -1
  29. package/scripts/build-identity.ts +102 -65
  30. package/scripts/build-wasm.ts +17 -13
  31. package/scripts/check.ts +4 -1
  32. package/scripts/client-messages.ts +73 -1
  33. package/scripts/compile-cache.ts +11 -8
  34. package/scripts/compile-pool.ts +6 -3
  35. package/scripts/compile-worker.ts +23 -23
  36. package/scripts/compile.ts +142 -19
  37. package/scripts/docs/as/amxts.ts +10 -4
  38. package/scripts/docs/as/facade.ts +1779 -275
  39. package/scripts/docs/as/fetch.ts +2 -2
  40. package/scripts/docs/as/fs.ts +190 -6
  41. package/scripts/docs/as/vector.ts +81 -0
  42. package/scripts/docs/entities.ts +12 -0
  43. package/scripts/docs/events.ts +49 -13
  44. package/scripts/docs/game.ts +6 -0
  45. package/scripts/docs/messages.ts +10 -1
  46. package/scripts/hlds-events.ts +11 -11
  47. package/scripts/includes.ts +3 -4
  48. package/scripts/leaf-natives.ts +84 -0
  49. package/scripts/player-fields.ts +1 -1
  50. package/scripts/plugin-natives.ts +1 -1
  51. package/scripts/prebuilt.ts +42 -11
  52. package/scripts/project.ts +63 -4
  53. package/scripts/reapi-events.ts +9 -9
  54. package/scripts/server-env.ts +145 -0
  55. package/scripts/shared-modules.ts +23 -7
  56. package/scripts/system.ts +1 -1
  57. package/scripts/tracked-fs.ts +11 -2
  58. package/scripts/typed-commands.ts +153 -15
  59. package/scripts/upgrade-calls.ts +225 -0
  60. package/scripts/upgrade-names.ts +1 -4
  61. package/scripts/upgrade.ts +47 -34
  62. package/src/cli-api.mjs +3 -2
  63. package/src/system.mjs +21 -11
  64. package/src/testing/compile.ts +31 -8
  65. package/src/testing/coroutines.ts +0 -10
  66. package/src/testing/memory.ts +89 -2
  67. package/src/testing/natives.ts +67 -30
  68. package/src/testing/server.ts +1094 -155
  69. package/src/testing/tables.ts +23 -6
  70. package/src/typecheck.mjs +110 -0
  71. package/runtime/licenses/Bun-LICENSE.md +0 -84
package/README.md CHANGED
@@ -34,7 +34,7 @@ plugin.
34
34
  - **The editor knows the game.** Every native, ReAPI field and hookchain
35
35
  comes with its type and a tooltip in English or Russian; a typo is a red
36
36
  line, not a runtime error.
37
- - **No import lines.** `Player`, `server`, `print` and the modules' names are
37
+ - **No import lines.** `Player`, `server`, `game` and the modules' names are
38
38
  auto-imported: the build adds what a plugin uses, and nothing else.
39
39
  - **Save and play.** `amxts dev` rebuilds what you saved, deploys it and
40
40
  reloads the running server - no map change, nobody disconnected.
@@ -90,11 +90,11 @@ plugin({ name: "Hello", version: "1.0.0", author: "you", description: "An exampl
90
90
 
91
91
  server.addCommand("/hp", ({ player }) => sayHp(player));
92
92
  server.addEventListener("putInServer", (event) => {
93
- print(0, `${event.player.name} joined`);
93
+ server.print(`${event.player.name} joined`);
94
94
  });
95
95
 
96
96
  function sayHp(player: Player) {
97
- print(player, `${player.name}, your HP: ${player.health}`);
97
+ player.print(`${player.name}, your HP: ${player.health}`);
98
98
 
99
99
  if (player.health < 50) player.health = 100;
100
100
  }
@@ -153,6 +153,6 @@ send a change.
153
153
 
154
154
  ## License
155
155
 
156
- [MIT](LICENSE). The server module built from this code, with the host plugin
157
- it carries, uses AMX Mod X's SDK, so it is distributed under GPL-3.0-or-later. Third-party
156
+ [MIT](LICENSE). The server module built from this code, with the natives'
157
+ image it carries, uses AMX Mod X's SDK, so it is distributed under GPL-3.0-or-later. Third-party
158
158
  licenses: [`runtime/licenses`](runtime/licenses/README.md).
package/README.ru.md CHANGED
@@ -34,7 +34,7 @@ Mod X рядом с Pawn-плагинами. Они вызывают друг д
34
34
  - **Редактор знает игру.** Каждый натив, поле ReAPI и хукчейн — с типом и
35
35
  подсказкой на русском или английском; опечатка — красная строка, а не
36
36
  ошибка на сервере.
37
- - **Без строк импорта.** `Player`, `server`, `print` и имена модулей
37
+ - **Без строк импорта.** `Player`, `server`, `game` и имена модулей
38
38
  импортируются сами: сборка добавляет то, чем плагин пользуется, и ничего
39
39
  больше.
40
40
  - **Сохранил — играешь.** `amxts dev` пересобирает сохранённое, выкладывает и
@@ -91,11 +91,11 @@ plugin({ name: "Hello", version: "1.0.0", author: "you", description: "An exampl
91
91
 
92
92
  server.addCommand("/hp", ({ player }) => sayHp(player));
93
93
  server.addEventListener("putInServer", (event) => {
94
- print(0, `${event.player.name} joined`);
94
+ server.print(`${event.player.name} joined`);
95
95
  });
96
96
 
97
97
  function sayHp(player: Player) {
98
- print(player, `${player.name}, your HP: ${player.health}`);
98
+ player.print(`${player.name}, your HP: ${player.health}`);
99
99
 
100
100
  if (player.health < 50) player.health = 100;
101
101
  }
@@ -154,7 +154,7 @@ bun run test
154
154
 
155
155
  ## Лицензия
156
156
 
157
- [MIT](LICENSE). Модуль сервера, собранный из этого кода, вместе с
158
- плагином-хостом, который он несёт в себе, использует SDK AMX Mod X, поэтому
157
+ [MIT](LICENSE). Модуль сервера, собранный из этого кода, вместе с образом
158
+ нативов, который он несёт в себе, использует SDK AMX Mod X, поэтому
159
159
  распространяется под GPL-3.0-or-later.
160
160
  Лицензии сторонних проектов: [`runtime/licenses`](runtime/licenses/README.md).
package/as/amxts.d.ts CHANGED
@@ -143,6 +143,13 @@ type UsageArgs<U extends string> = string extends U ? Record<string, string | un
143
143
  /** A command's arguments: the type argument's, or else the usage's, as text. */
144
144
  type CommandArgsOf<T, U extends string> = [T] extends [never] ? UsageArgs<U> : T;
145
145
 
146
+ /**
147
+ * What a command's handler takes: its arguments and `player` - `({ player,
148
+ * target }) =>`; for a command without arguments, the player himself too -
149
+ * `(player) =>`, which the compiler hands `player` (`Context & Player`).
150
+ */
151
+ type CommandHandlerArgs<T, U extends string> = CommandArgsOf<T, U> & { player: Player } & ([T] extends [never] ? ([RequiredNames<U> | OptionalNames<U>] extends [never] ? Player : unknown) : unknown);
152
+
146
153
  declare module "./facade" {
147
154
  interface PlayerChangeEvent<F extends string = string> {
148
155
  /** The field's value after the change; with `{ field }`, of the field's type. */
@@ -176,11 +183,14 @@ declare module "./facade" {
176
183
  * server.addCommand<KickArgs>("/kick <target> [reason]", ({ player, target, reason }) => {
177
184
  * target.kick(reason ?? `Kicked by ${player.name}`);
178
185
  * }, { access: "kick" });
179
- * server.addCommand("/hp", ({ player }) => print(player, `${player.health} HP`));
186
+ * server.addCommand("/hp", ({ player }) => player.print(`${player.health} HP`));
187
+ * server.addCommand(["/cp", "cp"], checkpoint); // several names; a handler of the player
180
188
  * ```
181
189
  *
182
190
  * A name with `/` is a chat command, one without a console command, and
183
- * `"say <phrase>"` a phrase written in chat. A `number` argument is
191
+ * `"say <phrase>"` a phrase written in chat. Several names - the usage
192
+ * first, then other names - are one command. A command without
193
+ * arguments takes a handler of the player, `(player) => ...`. A `number` argument is
184
194
  * parsed, a `Player` found by `#userid`, the whole name or a part of it,
185
195
  * a `string` taken as it is - the last one takes the rest of the line. A
186
196
  * word that is not what the command takes answers the player with the
@@ -189,7 +199,7 @@ declare module "./facade" {
189
199
  * Pawn: `register_clcmd`
190
200
  */
191
201
  // oxlint-disable-next-line typescript/method-signature-style -- the editor's signature of the class's method, which the build writes per call
192
- addCommand<T extends object = never, const U extends string = string>(usage: U, handler: (args: CommandArgsOf<T, U> & { player: Player }) => void, options?: CommandOptions): void;
202
+ addCommand<T extends object = never, const U extends string = string>(usage: U | readonly [U, ...string[]], handler: (args: CommandHandlerArgs<T, U>) => void, options?: CommandOptions): void;
193
203
  /**
194
204
  * Adds a command of the server console - typed there, sent over rcon or
195
205
  * run by another plugin - by its usage, its arguments read as a player's