@amxts/core 0.1.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.
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/README.ru.md +162 -0
- package/amxmodx/base/include/amxconst.inc +594 -0
- package/amxmodx/base/include/amxmisc.inc +902 -0
- package/amxmodx/base/include/amxmodx.inc +3447 -0
- package/amxmodx/base/include/amxmodx_version.inc +20 -0
- package/amxmodx/base/include/cellarray.inc +525 -0
- package/amxmodx/base/include/cellstack.inc +166 -0
- package/amxmodx/base/include/celltrie.inc +412 -0
- package/amxmodx/base/include/core.inc +202 -0
- package/amxmodx/base/include/csstats.inc +298 -0
- package/amxmodx/base/include/csstats_const.inc +29 -0
- package/amxmodx/base/include/cstrike.inc +1287 -0
- package/amxmodx/base/include/cstrike_const.inc +521 -0
- package/amxmodx/base/include/csx.inc +259 -0
- package/amxmodx/base/include/cvars.inc +547 -0
- package/amxmodx/base/include/datapack.inc +161 -0
- package/amxmodx/base/include/dbi.inc +154 -0
- package/amxmodx/base/include/dodconst.inc +152 -0
- package/amxmodx/base/include/dodfun.inc +152 -0
- package/amxmodx/base/include/dodstats.inc +69 -0
- package/amxmodx/base/include/dodx.inc +161 -0
- package/amxmodx/base/include/engine.inc +1343 -0
- package/amxmodx/base/include/engine_const.inc +310 -0
- package/amxmodx/base/include/engine_stocks.inc +248 -0
- package/amxmodx/base/include/esf.inc +70 -0
- package/amxmodx/base/include/esf_const.inc +74 -0
- package/amxmodx/base/include/fakemeta.inc +1127 -0
- package/amxmodx/base/include/fakemeta_const.inc +793 -0
- package/amxmodx/base/include/fakemeta_stocks.inc +395 -0
- package/amxmodx/base/include/fakemeta_util.inc +882 -0
- package/amxmodx/base/include/file.inc +666 -0
- package/amxmodx/base/include/float.inc +422 -0
- package/amxmodx/base/include/fun.inc +333 -0
- package/amxmodx/base/include/gameconfig.inc +93 -0
- package/amxmodx/base/include/geoip.inc +264 -0
- package/amxmodx/base/include/ham_const.inc +4352 -0
- package/amxmodx/base/include/hamsandwich.inc +439 -0
- package/amxmodx/base/include/hlsdk_const.inc +808 -0
- package/amxmodx/base/include/json.inc +777 -0
- package/amxmodx/base/include/lang.inc +119 -0
- package/amxmodx/base/include/message_const.inc +1130 -0
- package/amxmodx/base/include/message_stocks.inc +161 -0
- package/amxmodx/base/include/messages.inc +604 -0
- package/amxmodx/base/include/newmenus.inc +387 -0
- package/amxmodx/base/include/ns.inc +754 -0
- package/amxmodx/base/include/ns_const.inc +196 -0
- package/amxmodx/base/include/nvault.inc +154 -0
- package/amxmodx/base/include/regex.inc +348 -0
- package/amxmodx/base/include/sockets.inc +183 -0
- package/amxmodx/base/include/sorting.inc +107 -0
- package/amxmodx/base/include/sqlx.inc +582 -0
- package/amxmodx/base/include/string.inc +786 -0
- package/amxmodx/base/include/string_const.inc +156 -0
- package/amxmodx/base/include/string_stocks.inc +325 -0
- package/amxmodx/base/include/textparse_ini.inc +214 -0
- package/amxmodx/base/include/textparse_smc.inc +261 -0
- package/amxmodx/base/include/tfcconst.inc +84 -0
- package/amxmodx/base/include/tfcstats.inc +62 -0
- package/amxmodx/base/include/tfcx.inc +148 -0
- package/amxmodx/base/include/time.inc +118 -0
- package/amxmodx/base/include/tsconst.inc +154 -0
- package/amxmodx/base/include/tsfun.inc +198 -0
- package/amxmodx/base/include/tsstats.inc +65 -0
- package/amxmodx/base/include/tsx.inc +88 -0
- package/amxmodx/base/include/vault.inc +60 -0
- package/amxmodx/base/include/vector.inc +131 -0
- package/amxmodx/base/include/xs.inc +1570 -0
- package/as/amxts.d.ts +153 -0
- package/as/constants.ts +4730 -0
- package/as/effects.ts +1449 -0
- package/as/entities.ts +5482 -0
- package/as/events.ts +3054 -0
- package/as/facade.ts +4639 -0
- package/as/flags.ts +299 -0
- package/as/fs.ts +287 -0
- package/as/hooks.ts +18536 -0
- package/as/kit.ts +25 -0
- package/as/lib/check.ts +86 -0
- package/as/modules/http.ts +184 -0
- package/as/natives.ts +11845 -0
- package/as/os.ts +30 -0
- package/as/promise.ts +1392 -0
- package/as/promise.types.d.ts +82 -0
- package/as/remote.ts +288 -0
- package/as/tsconfig.json +22 -0
- package/as/vector.ts +65 -0
- package/bin/amxts.mjs +10 -0
- package/includes/menu_core.inc +355 -0
- package/includes/order.txt +54 -0
- package/includes/sources.json +27 -0
- package/includes/universal_config.inc +355 -0
- package/lint/oxlint-plugin.mjs +77 -0
- package/node_modules/assemblyscript/LICENSE +201 -0
- package/node_modules/assemblyscript/NOTICE +93 -0
- package/node_modules/assemblyscript/package.json +63 -0
- package/node_modules/assemblyscript/std/README.md +6 -0
- package/node_modules/assemblyscript/std/assembly/array.ts +526 -0
- package/node_modules/assemblyscript/std/assembly/arraybuffer.ts +77 -0
- package/node_modules/assemblyscript/std/assembly/atomics.ts +127 -0
- package/node_modules/assemblyscript/std/assembly/bindings/asyncify.ts +16 -0
- package/node_modules/assemblyscript/std/assembly/bindings/dom.ts +291 -0
- package/node_modules/assemblyscript/std/assembly/bindings/node.ts +6 -0
- package/node_modules/assemblyscript/std/assembly/builtins.ts +2631 -0
- package/node_modules/assemblyscript/std/assembly/compat.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/console.ts +42 -0
- package/node_modules/assemblyscript/std/assembly/crypto.ts +9 -0
- package/node_modules/assemblyscript/std/assembly/dataview.ts +181 -0
- package/node_modules/assemblyscript/std/assembly/date.ts +373 -0
- package/node_modules/assemblyscript/std/assembly/diagnostics.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/error.ts +44 -0
- package/node_modules/assemblyscript/std/assembly/function.ts +38 -0
- package/node_modules/assemblyscript/std/assembly/index.d.ts +2822 -0
- package/node_modules/assemblyscript/std/assembly/iterator.ts +35 -0
- package/node_modules/assemblyscript/std/assembly/map.ts +260 -0
- package/node_modules/assemblyscript/std/assembly/math.ts +3289 -0
- package/node_modules/assemblyscript/std/assembly/memory.ts +123 -0
- package/node_modules/assemblyscript/std/assembly/number.ts +388 -0
- package/node_modules/assemblyscript/std/assembly/object.ts +36 -0
- package/node_modules/assemblyscript/std/assembly/performance.ts +9 -0
- package/node_modules/assemblyscript/std/assembly/polyfills.ts +27 -0
- package/node_modules/assemblyscript/std/assembly/process.ts +50 -0
- package/node_modules/assemblyscript/std/assembly/reference.ts +48 -0
- package/node_modules/assemblyscript/std/assembly/regexp.ts +12 -0
- package/node_modules/assemblyscript/std/assembly/rt/README.md +83 -0
- package/node_modules/assemblyscript/std/assembly/rt/common.ts +81 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-incremental.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-minimal.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-stub.ts +1 -0
- package/node_modules/assemblyscript/std/assembly/rt/index.d.ts +37 -0
- package/node_modules/assemblyscript/std/assembly/rt/itcms.ts +419 -0
- package/node_modules/assemblyscript/std/assembly/rt/rtrace.ts +15 -0
- package/node_modules/assemblyscript/std/assembly/rt/stub.ts +133 -0
- package/node_modules/assemblyscript/std/assembly/rt/tcms.ts +254 -0
- package/node_modules/assemblyscript/std/assembly/rt/tlsf.ts +592 -0
- package/node_modules/assemblyscript/std/assembly/rt.ts +87 -0
- package/node_modules/assemblyscript/std/assembly/set.ts +220 -0
- package/node_modules/assemblyscript/std/assembly/shared/feature.ts +65 -0
- package/node_modules/assemblyscript/std/assembly/shared/runtime.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/target.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/tsconfig.json +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/typeinfo.ts +72 -0
- package/node_modules/assemblyscript/std/assembly/staticarray.ts +401 -0
- package/node_modules/assemblyscript/std/assembly/string.ts +847 -0
- package/node_modules/assemblyscript/std/assembly/symbol.ts +114 -0
- package/node_modules/assemblyscript/std/assembly/table.ts +16 -0
- package/node_modules/assemblyscript/std/assembly/tsconfig.json +6 -0
- package/node_modules/assemblyscript/std/assembly/typedarray.ts +1945 -0
- package/node_modules/assemblyscript/std/assembly/uri.ts +17 -0
- package/node_modules/assemblyscript/std/assembly/util/bytes.ts +107 -0
- package/node_modules/assemblyscript/std/assembly/util/casemap.ts +497 -0
- package/node_modules/assemblyscript/std/assembly/util/error.ts +54 -0
- package/node_modules/assemblyscript/std/assembly/util/hash.ts +117 -0
- package/node_modules/assemblyscript/std/assembly/util/math.ts +1922 -0
- package/node_modules/assemblyscript/std/assembly/util/memory.ts +290 -0
- package/node_modules/assemblyscript/std/assembly/util/number.ts +873 -0
- package/node_modules/assemblyscript/std/assembly/util/sort.ts +313 -0
- package/node_modules/assemblyscript/std/assembly/util/string.ts +1202 -0
- package/node_modules/assemblyscript/std/assembly/util/uri.ts +275 -0
- package/node_modules/assemblyscript/std/assembly/vector.ts +4 -0
- package/node_modules/assemblyscript/std/assembly.json +16 -0
- package/node_modules/assemblyscript/std/portable/index.d.ts +462 -0
- package/node_modules/assemblyscript/std/portable/index.js +416 -0
- package/node_modules/assemblyscript/std/portable.json +11 -0
- package/node_modules/assemblyscript/std/types/assembly/index.d.ts +1 -0
- package/node_modules/assemblyscript/std/types/assembly/package.json +3 -0
- package/node_modules/assemblyscript/std/types/portable/index.d.ts +1 -0
- package/node_modules/assemblyscript/std/types/portable/package.json +3 -0
- package/node_modules/assemblyscript/tsconfig-base.json +13 -0
- package/package.json +112 -0
- package/runtime/deps/assemblyscript/LICENSE +201 -0
- package/runtime/deps/assemblyscript/NOTICE +93 -0
- package/runtime/deps/assemblyscript/bin/asc.js +35 -0
- package/runtime/deps/assemblyscript/dist/asc.js +25035 -0
- package/runtime/deps/assemblyscript/dist/assemblyscript.js +337 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/LICENSE +201 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/index.js +28905 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/package.json +50 -0
- package/runtime/deps/assemblyscript/node_modules/long/LICENSE +202 -0
- package/runtime/deps/assemblyscript/node_modules/long/index.js +1581 -0
- package/runtime/deps/assemblyscript/node_modules/long/package.json +58 -0
- package/runtime/deps/assemblyscript/package.json +114 -0
- package/runtime/host/amxts.inc +85 -0
- package/runtime/licenses/AMXX-LICENSE.txt +34 -0
- package/runtime/licenses/AssemblyScript-LICENSE +201 -0
- package/runtime/licenses/AssemblyScript-NOTICE +93 -0
- package/runtime/licenses/Binaryen-LICENSE +201 -0
- package/runtime/licenses/Bun-LICENSE.md +84 -0
- package/runtime/licenses/GPL-3.0.txt +674 -0
- package/runtime/licenses/LLVM-LICENSE.TXT +279 -0
- package/runtime/licenses/README.md +25 -0
- package/runtime/licenses/WAMR-LICENSE +219 -0
- package/runtime/natives.txt +1095 -0
- package/runtime/patches/README.md +59 -0
- package/runtime/patches/assemblyscript-0.28.20-amxts.patch +14174 -0
- package/runtime/patches/wamr-2.4.5-amxts.patch +364 -0
- package/scripts/apply-docs.ts +508 -0
- package/scripts/asc.ts +27 -0
- package/scripts/auto-imports.ts +258 -0
- package/scripts/build-wasm.ts +595 -0
- package/scripts/check.ts +93 -0
- package/scripts/compile-cache.ts +179 -0
- package/scripts/compile.ts +401 -0
- package/scripts/docker-server.ts +73 -0
- package/scripts/docs/as/amxts.ts +210 -0
- package/scripts/docs/as/effects.ts +1684 -0
- package/scripts/docs/as/facade.ts +3302 -0
- package/scripts/docs/as/fs.ts +173 -0
- package/scripts/docs/as/lib/check.ts +68 -0
- package/scripts/docs/as/modules/http.ts +66 -0
- package/scripts/docs/as/os.ts +16 -0
- package/scripts/docs/as/promise.ts +132 -0
- package/scripts/docs/as/promise.types.ts +63 -0
- package/scripts/docs/as/vector.ts +48 -0
- package/scripts/docs/entities.ts +2338 -0
- package/scripts/docs/events.ts +245 -0
- package/scripts/docs/game.ts +497 -0
- package/scripts/docs/messages.ts +148 -0
- package/scripts/file-contents.ts +74 -0
- package/scripts/includes.ts +134 -0
- package/scripts/player-fields.ts +866 -0
- package/scripts/plugin-cache.ts +92 -0
- package/scripts/plugin-natives.ts +1157 -0
- package/scripts/prebuilt.ts +268 -0
- package/scripts/prepare.ts +134 -0
- package/scripts/project.ts +973 -0
- package/scripts/run.ts +28 -0
- package/scripts/shared-modules.ts +906 -0
- package/scripts/system.ts +33 -0
- package/scripts/tracked-fs.ts +115 -0
- package/scripts/typed-configs.ts +788 -0
- package/scripts/ui.ts +77 -0
- package/src/cli-api.mjs +175 -0
- package/src/parser/include-parser.ts +506 -0
- package/src/system.mjs +155 -0
- package/src/testing/compile-cache.ts +31 -0
- package/src/testing/compile.ts +222 -0
- package/src/testing/coroutines.ts +191 -0
- package/src/testing/index.ts +39 -0
- package/src/testing/kits.ts +55 -0
- package/src/testing/memory.ts +125 -0
- package/src/testing/natives.ts +925 -0
- package/src/testing/server.ts +1874 -0
- package/src/testing/setup.ts +63 -0
- package/src/testing/tables.ts +139 -0
- package/src/types.ts +51 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// A project on the fake server, as `amxts build` would lay it out on a real
|
|
2
|
+
// one:
|
|
3
|
+
//
|
|
4
|
+
// const server = await setup(); // the project the tests run from
|
|
5
|
+
// const server = await setup({ rootDir: "playground" }); // a module's playground
|
|
6
|
+
//
|
|
7
|
+
// The modules the project's plugins use load first, each after what it
|
|
8
|
+
// requires, with their test kits; then the project's plugins; then the map
|
|
9
|
+
// starts. A module no plugin uses is left out, as the build leaves it out.
|
|
10
|
+
import type { ServerOptions } from './server';
|
|
11
|
+
import { basename, resolve } from 'node:path';
|
|
12
|
+
import { loadProject, modulesInUse, projectPlugins, setProjectDir, sourcesFor } from '../../scripts/project';
|
|
13
|
+
import { installKit } from './kits';
|
|
14
|
+
import { FakeServer } from './server';
|
|
15
|
+
import { PLUGINS_ROOT } from './tables';
|
|
16
|
+
|
|
17
|
+
export interface SetupOptions extends ServerOptions {
|
|
18
|
+
/**
|
|
19
|
+
* The project: the folder with its amxts.config.ts, whose modules and
|
|
20
|
+
* plugins are loaded. The folder the tests run from when left out. It
|
|
21
|
+
* stays the project for the rest of the run: `server.load("@you/greeter")`
|
|
22
|
+
* afterwards finds the module there.
|
|
23
|
+
*/
|
|
24
|
+
rootDir?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Which of the project's plugins load, by file name - `["welcome.ts"]`,
|
|
27
|
+
* `["welcome"]` - in this order; all of them when left out, none for `[]`.
|
|
28
|
+
*/
|
|
29
|
+
plugins?: string[];
|
|
30
|
+
/** Starts the map - plugin_init, then plugin_cfg - once everything is loaded. True when left out. */
|
|
31
|
+
start?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A new fake server with the project on it: the modules its plugins use, in
|
|
36
|
+
* load order, each with its test kit, then its plugins, then the map started.
|
|
37
|
+
*/
|
|
38
|
+
export async function setup(options: SetupOptions = {}): Promise<FakeServer> {
|
|
39
|
+
const { rootDir = process.cwd(), plugins, start = true, ...serverOptions } = options;
|
|
40
|
+
setProjectDir(rootDir);
|
|
41
|
+
const project = loadProject(resolve(rootDir));
|
|
42
|
+
if (project.problems.length) throw new Error(project.problems.join('\n'));
|
|
43
|
+
|
|
44
|
+
const server = new FakeServer(serverOptions);
|
|
45
|
+
const found = projectPlugins(project);
|
|
46
|
+
const modules = modulesInUse(sourcesFor(PLUGINS_ROOT), found);
|
|
47
|
+
for (const pkg of modules) await installKit(server, pkg);
|
|
48
|
+
for (const pkg of modules) await server.load(pkg.name);
|
|
49
|
+
for (const plugin of chosen(found, plugins)) await server.load(plugin);
|
|
50
|
+
if (start) server.start();
|
|
51
|
+
return server;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The plugins asked for, in the order asked; every one when none is named. */
|
|
55
|
+
function chosen(found: string[], names: string[] | undefined): string[] {
|
|
56
|
+
if (!names) return found;
|
|
57
|
+
return names.map((name) => {
|
|
58
|
+
const file = name.endsWith('.ts') ? name : `${name}.ts`;
|
|
59
|
+
const match = found.find(path => basename(path) === file);
|
|
60
|
+
if (!match) throw new Error(`setup: no plugin ${file} in the project's plugins (${found.map(path => basename(path)).join(', ') || 'it has none'})`);
|
|
61
|
+
return match;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// What the fake server needs to know about the generated layer, read out of
|
|
2
|
+
// the generated files themselves rather than copied: a constant, a dispatcher
|
|
3
|
+
// id or a hookchain number that moves when `bun run generate` runs moves here
|
|
4
|
+
// too, and a test never disagrees with the plugin it loads.
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
|
|
9
|
+
/** The plugins folder - what `~/` means - and where the generated files live. */
|
|
10
|
+
export const PLUGINS_ROOT = fileURLToPath(new URL('../../as/', import.meta.url));
|
|
11
|
+
|
|
12
|
+
function generated(file: string): string {
|
|
13
|
+
try {
|
|
14
|
+
return readFileSync(join(PLUGINS_ROOT, file), 'utf-8');
|
|
15
|
+
} catch {
|
|
16
|
+
throw new Error(`as/${file} is missing - run \`bun run generate\` before testing plugins`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A hookchain as the fake fires it: which arguments are floats or text, and what it answers. */
|
|
21
|
+
export interface HookShape {
|
|
22
|
+
/** reapi's short name: "take_damage". */
|
|
23
|
+
kind: string;
|
|
24
|
+
/** Zero-based arguments the event reads as floats. */
|
|
25
|
+
floats: Set<number>;
|
|
26
|
+
/** Zero-based arguments the event reads as text. */
|
|
27
|
+
texts: Set<number>;
|
|
28
|
+
/** The ATYPE_* the chain answers with, or -1 for a chain that answers nothing. */
|
|
29
|
+
answer: number;
|
|
30
|
+
/** The Ham_* function a Ham Sandwich hook of the event is on, when it has one. */
|
|
31
|
+
ham?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface Tables {
|
|
35
|
+
/** Every `export const X: i32 = N` in as/constants.ts. */
|
|
36
|
+
constants: Map<string, number>;
|
|
37
|
+
/** The dispatcher's native ids (`NATIVE_x`) to names. */
|
|
38
|
+
dispatched: Map<number, string>;
|
|
39
|
+
/** A hookchain's number (hookIdOf) to its short name. */
|
|
40
|
+
hookNames: Map<number, string>;
|
|
41
|
+
/** A hookchain by its short name, or by its event name ("takeDamage"). */
|
|
42
|
+
hooks: Map<string, HookShape>;
|
|
43
|
+
/** Entvars and members read as floats, by constant value. */
|
|
44
|
+
floatFields: Set<number>;
|
|
45
|
+
/** Entvars and members that hold three floats. */
|
|
46
|
+
vectorFields: Set<number>;
|
|
47
|
+
/** Entvars and members that hold text: var_classname, m_szTeamName. */
|
|
48
|
+
stringFields: Set<number>;
|
|
49
|
+
/** Members read with an element index: m_rgpPlayerItems. */
|
|
50
|
+
arrayFields: Set<number>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let cached: Tables | null = null;
|
|
54
|
+
|
|
55
|
+
export function tables(): Tables {
|
|
56
|
+
if (cached) return cached;
|
|
57
|
+
|
|
58
|
+
const constantsSource = generated('constants.ts');
|
|
59
|
+
const constants = new Map<string, number>();
|
|
60
|
+
for (const [, name, value] of constantsSource.matchAll(/^export const (\w+): i32 = (-?(?:0x[0-9a-fA-F]+|\d+));/gm)) {
|
|
61
|
+
constants.set(name, Number(value));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const dispatched = new Map<number, string>();
|
|
65
|
+
for (const [, name, id] of generated('natives.ts').matchAll(/^export const NATIVE_(\w+): i32 = (\d+);/gm)) {
|
|
66
|
+
dispatched.set(Number(id), name);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const hookNames = new Map<number, string>();
|
|
70
|
+
const switchBody = constantsSource.slice(constantsSource.indexOf('export function hookIdOf'));
|
|
71
|
+
for (const [, name, id] of switchBody.slice(0, switchBody.indexOf('\n}\n')).matchAll(/case "(\w+)": return (-?\d+);/g)) {
|
|
72
|
+
hookNames.set(Number(id), name);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const hooksSource = generated('hooks.ts');
|
|
76
|
+
const hooks = new Map<string, HookShape>();
|
|
77
|
+
const byClass = new Map<string, HookShape>();
|
|
78
|
+
|
|
79
|
+
for (const [, className, body] of hooksSource.matchAll(/^export class (\w+) extends HookEvent \{\n([\s\S]*?)\n\}\n/gm)) {
|
|
80
|
+
const kind = body.match(/private readonly kind: string = "(\w+)";/)?.[1];
|
|
81
|
+
if (!kind) continue;
|
|
82
|
+
|
|
83
|
+
// The answer's ATYPE_*: a cell's, or text or a vector, which only Ham Sandwich answers.
|
|
84
|
+
const result = body.match(/get result\(\)[^{]*\{[^}]*this\.__result(?:Cell\((ATYPE_\w+)\)|(Text|Vector)\(\))/);
|
|
85
|
+
const answer = !result ? '' : result[1] ?? (result[2] === 'Text' ? 'ATYPE_STRING' : 'ATYPE_VECTOR');
|
|
86
|
+
const ham = body.match(/private static readonly ham: i32 = (Ham_\w+);/)?.[1];
|
|
87
|
+
const shape: HookShape = {
|
|
88
|
+
kind,
|
|
89
|
+
floats: new Set([...body.matchAll(/cellFloat\(this\.__cell\((\d+)\)\)/g)].map(m => Number(m[1]))),
|
|
90
|
+
texts: new Set([...body.matchAll(/this\.__text\((\d+)\)/g)].map(m => Number(m[1]))),
|
|
91
|
+
answer: answer ? constants.get(answer) ?? -1 : -1,
|
|
92
|
+
...(ham ? { ham: constants.get(ham) } : {}),
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
hooks.set(kind, shape);
|
|
96
|
+
byClass.set(className, shape);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const eventMap = hooksSource.slice(hooksSource.indexOf('export interface GameEventMap'));
|
|
100
|
+
for (const [, event, className] of eventMap.slice(0, eventMap.indexOf('\n}\n')).matchAll(/^\t(\w+): (\w+);/gm)) {
|
|
101
|
+
const shape = byClass.get(className);
|
|
102
|
+
if (shape) hooks.set(event, shape);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// A field's kind is what the field natives' tables in as/natives.ts say
|
|
106
|
+
// (__get_entvar_kind, __get_member_kind): 1 a Float, 2 a vector, 3 text,
|
|
107
|
+
// 4 more for an array member. Entvars and members only - a game rule's
|
|
108
|
+
// number is its own.
|
|
109
|
+
const kinds = new Map<number, number>();
|
|
110
|
+
for (const [, body] of generated('natives.ts').matchAll(/^export function __get_(?:entvar|member)_kind\(field: i32\): i32 \{\n([\s\S]*?)\n\}\n/gm)) {
|
|
111
|
+
for (const [, cases, kind] of body.matchAll(/((?:\t\tcase \w+:\n)+)\t\t\treturn (\d+);/g)) {
|
|
112
|
+
for (const [, name] of cases.matchAll(/case (\w+):/g)) {
|
|
113
|
+
const value = constants.get(name);
|
|
114
|
+
if (value !== undefined) kinds.set(value, Number(kind));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const fieldsOf = (test: (kind: number) => boolean) => new Set([...kinds].filter(([, kind]) => test(kind)).map(([field]) => field));
|
|
119
|
+
|
|
120
|
+
cached = {
|
|
121
|
+
constants,
|
|
122
|
+
dispatched,
|
|
123
|
+
hookNames,
|
|
124
|
+
hooks,
|
|
125
|
+
floatFields: fieldsOf(kind => (kind & 3) === 1),
|
|
126
|
+
vectorFields: fieldsOf(kind => (kind & 3) === 2),
|
|
127
|
+
stringFields: fieldsOf(kind => (kind & 3) === 3),
|
|
128
|
+
arrayFields: fieldsOf(kind => (kind & 4) !== 0),
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return cached;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** A constant's value by name, or an error naming it. */
|
|
135
|
+
export function constant(name: string): number {
|
|
136
|
+
const value = tables().constants.get(name);
|
|
137
|
+
if (value === undefined) throw new Error(`no constant named ${name} in as/constants.ts`);
|
|
138
|
+
return value;
|
|
139
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface ParsedInclude {
|
|
2
|
+
natives: NativeFunction[];
|
|
3
|
+
forwards: ForwardDeclaration[];
|
|
4
|
+
constants: Constant[];
|
|
5
|
+
enums: EnumDeclaration[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface NativeFunction {
|
|
9
|
+
name: string;
|
|
10
|
+
params: Parameter[];
|
|
11
|
+
returnType: string;
|
|
12
|
+
docs?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ForwardDeclaration {
|
|
16
|
+
name: string;
|
|
17
|
+
params: Parameter[];
|
|
18
|
+
returnType: string;
|
|
19
|
+
docs?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface Parameter {
|
|
23
|
+
name: string;
|
|
24
|
+
type: string;
|
|
25
|
+
isArray?: boolean;
|
|
26
|
+
isRef?: boolean;
|
|
27
|
+
isConst?: boolean;
|
|
28
|
+
isRest?: boolean;
|
|
29
|
+
defaultValue?: string;
|
|
30
|
+
arraySize?: string;
|
|
31
|
+
/** How many bracket pairs the declaration had — `array[][]` is 2, everything else is 1. */
|
|
32
|
+
dimensions?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface Constant {
|
|
36
|
+
name: string;
|
|
37
|
+
value: string;
|
|
38
|
+
docs?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface EnumDeclaration {
|
|
42
|
+
name?: string;
|
|
43
|
+
members: EnumMember[];
|
|
44
|
+
docs?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface EnumMember {
|
|
48
|
+
name: string;
|
|
49
|
+
value?: string;
|
|
50
|
+
docs?: string;
|
|
51
|
+
}
|