@kuncat/avoidant 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.
Binary file
@@ -0,0 +1,86 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_channel_free: (a: number, b: number) => void;
5
+ export const __wbg_channelsender_free: (a: number, b: number) => void;
6
+ export const __wbg_gamestate_free: (a: number, b: number) => void;
7
+ export const __wbg_networknode_free: (a: number, b: number) => void;
8
+ export const __wbg_pulse_free: (a: number, b: number) => void;
9
+ export const __wbg_uistate_free: (a: number, b: number) => void;
10
+ export const channel_id: (a: number) => [number, number];
11
+ export const channel_neighbors: (a: number) => [number, number];
12
+ export const channel_receiver: (a: number) => any;
13
+ export const channel_sender: (a: number) => number;
14
+ export const channel_ticket: (a: number, b: any) => [number, number, number, number];
15
+ export const channelsender_broadcast: (a: number, b: number, c: number) => any;
16
+ export const channelsender_set_nickame: (a: number, b: number, c: number) => void;
17
+ export const gamestate_applyMapCells: (a: number, b: any) => [number, number, number];
18
+ export const gamestate_cellMetadata: (a: number) => any;
19
+ export const gamestate_cells: (a: number) => any;
20
+ export const gamestate_endpointId: (a: number) => [number, number];
21
+ export const gamestate_exploreCell: (a: number, b: number, c: number, d: number, e: number) => [number, number];
22
+ export const gamestate_hasNetworkNode: (a: number) => number;
23
+ export const gamestate_invite: (a: number, b: number, c: number) => any;
24
+ export const gamestate_joinAsPeer: (a: number, b: number, c: number, d: number, e: number) => any;
25
+ export const gamestate_lastInboundMutationMs: (a: number) => [number, number];
26
+ export const gamestate_lastOutboundMutationMs: (a: number) => [number, number];
27
+ export const gamestate_networkListenerStarted: (a: number) => number;
28
+ export const gamestate_networkPeers: (a: number) => [number, number];
29
+ export const gamestate_networkSnapshot: (a: number) => any;
30
+ export const gamestate_new: (a: any) => [number, number, number];
31
+ export const gamestate_optionsFromTicket: (a: number, b: number) => [number, number, number];
32
+ export const gamestate_queueExplorePulse: (a: number, b: number, c: number, d: number, e: number) => [number, number];
33
+ export const gamestate_score: (a: number) => any;
34
+ export const gamestate_topicId: (a: number) => [number, number];
35
+ export const gamestate_uiState: (a: number) => number;
36
+ export const generateMapData: (a: any) => [number, number, number];
37
+ export const networknode_create: (a: number, b: number, c: number) => any;
38
+ export const networknode_endpointId: (a: number) => [number, number];
39
+ export const networknode_join: (a: number, b: number, c: number, d: number, e: number) => any;
40
+ export const networknode_spawn: () => any;
41
+ export const pulse_durationMs: (a: number) => number;
42
+ export const pulse_id: (a: number) => number;
43
+ export const pulse_isRemote: (a: number) => number;
44
+ export const pulse_nullPulse: () => number;
45
+ export const pulse_originCell: (a: number) => number;
46
+ export const pulse_position: (a: number) => [number, number];
47
+ export const start: () => void;
48
+ export const uistate_pulses: (a: number) => any;
49
+ export const gamestate_elevationMax: (a: number) => number;
50
+ export const gamestate_elevationMin: (a: number) => number;
51
+ export const pulse_createdAtMs: (a: number) => number;
52
+ export const pulse_maxRadius: (a: number) => number;
53
+ export const __wbg_intounderlyingbytesource_free: (a: number, b: number) => void;
54
+ export const __wbg_intounderlyingsink_free: (a: number, b: number) => void;
55
+ export const __wbg_intounderlyingsource_free: (a: number, b: number) => void;
56
+ export const intounderlyingbytesource_autoAllocateChunkSize: (a: number) => number;
57
+ export const intounderlyingbytesource_cancel: (a: number) => void;
58
+ export const intounderlyingbytesource_pull: (a: number, b: any) => any;
59
+ export const intounderlyingbytesource_start: (a: number, b: any) => void;
60
+ export const intounderlyingbytesource_type: (a: number) => number;
61
+ export const intounderlyingsink_abort: (a: number, b: any) => any;
62
+ export const intounderlyingsink_close: (a: number) => any;
63
+ export const intounderlyingsink_write: (a: number, b: any) => any;
64
+ export const intounderlyingsource_cancel: (a: number) => void;
65
+ export const intounderlyingsource_pull: (a: number, b: any) => any;
66
+ export const ring_core_0_17_14__bn_mul_mont: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
67
+ export const wasm_bindgen__convert__closures_____invoke__h00c6858f5875acdf: (a: number, b: number, c: any) => [number, number];
68
+ export const wasm_bindgen__convert__closures_____invoke__h299fd98c162ada8d: (a: number, b: number, c: any, d: any) => void;
69
+ export const wasm_bindgen__convert__closures_____invoke__h1d3d8bbcf4bb9647: (a: number, b: number, c: any) => any;
70
+ export const wasm_bindgen__convert__closures_____invoke__h364282c46f736e9f: (a: number, b: number, c: any) => void;
71
+ export const wasm_bindgen__convert__closures_____invoke__h104a0d4c5facca10: (a: number, b: number, c: any) => void;
72
+ export const wasm_bindgen__convert__closures_____invoke__h3ed8ec9c74648bb3: (a: number, b: number, c: any) => void;
73
+ export const wasm_bindgen__convert__closures_____invoke__hac60de05c959eab5: (a: number, b: number) => void;
74
+ export const wasm_bindgen__convert__closures_____invoke__h863ae91844dca7d2: (a: number, b: number) => void;
75
+ export const wasm_bindgen__convert__closures_____invoke__h9480bdc51ff47b2e: (a: number, b: number) => void;
76
+ export const wasm_bindgen__convert__closures_____invoke__ha30834eb04ba8562: (a: number, b: number) => void;
77
+ export const __wbindgen_malloc: (a: number, b: number) => number;
78
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
79
+ export const __wbindgen_exn_store: (a: number) => void;
80
+ export const __externref_table_alloc: () => number;
81
+ export const __wbindgen_externrefs: WebAssembly.Table;
82
+ export const __externref_drop_slice: (a: number, b: number) => void;
83
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
84
+ export const __wbindgen_destroy_closure: (a: number, b: number) => void;
85
+ export const __externref_table_dealloc: (a: number) => void;
86
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "avoidant",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "Alvin Ali Khaled <aak@kuncat.com>"
6
+ ],
7
+ "description": "The game logic for Avoidant.",
8
+ "version": "0.1.0",
9
+ "license": "MIT OR Apache-2.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/kuncat/avoidant"
13
+ },
14
+ "files": [
15
+ "avoidant_wasm_bg.wasm",
16
+ "avoidant_wasm.js",
17
+ "avoidant_wasm.d.ts",
18
+ "LICENSE_MIT",
19
+ "LICENSE_APACHE"
20
+ ],
21
+ "main": "avoidant_wasm.js",
22
+ "types": "avoidant_wasm.d.ts",
23
+ "sideEffects": [
24
+ "./snippets/*"
25
+ ]
26
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Client-side helper that drives the dedicated mapgen Web Worker.
3
+ *
4
+ * A single worker is kept alive across calls so the wasm module is only initialized once. Each call gets a unique requestId so we can multiplex safely even though map generation is normally serial.
5
+ */
6
+ import type { GameOptions, MapData } from "../wasm/avoidant_wasm";
7
+ export declare function generateMap(options: GameOptions): Promise<MapData>;
@@ -0,0 +1,53 @@
1
+ import MapgenWorker from "./mapgen.worker?worker";
2
+ let workerInstance;
3
+ const pending = new Map();
4
+ let nextRequestId = 1;
5
+ function getWorker() {
6
+ if (workerInstance) {
7
+ return workerInstance;
8
+ }
9
+ const worker = new MapgenWorker();
10
+ worker.addEventListener("message", (event) => {
11
+ const data = event.data;
12
+ const entry = pending.get(data.requestId);
13
+ if (!entry) {
14
+ return;
15
+ }
16
+ pending.delete(data.requestId);
17
+ if (data.type === "result") {
18
+ entry.resolve({
19
+ cells: data.cells,
20
+ terrain: data.terrain,
21
+ });
22
+ }
23
+ else {
24
+ entry.reject(new Error(data.message));
25
+ }
26
+ });
27
+ const failAll = (error) => {
28
+ for (const [id, entry] of pending) {
29
+ pending.delete(id);
30
+ entry.reject(error);
31
+ }
32
+ // Drop the dead worker so the next call spawns a fresh one.
33
+ workerInstance = undefined;
34
+ };
35
+ worker.addEventListener("error", (event) => {
36
+ console.error("Mapgen worker error event", event);
37
+ failAll(event.error instanceof Error ? event.error : new Error("Mapgen worker error"));
38
+ });
39
+ worker.addEventListener("messageerror", (event) => {
40
+ console.error("Mapgen worker messageerror", event);
41
+ failAll(new Error("Mapgen worker messageerror (structured clone failed)"));
42
+ });
43
+ workerInstance = worker;
44
+ return worker;
45
+ }
46
+ export function generateMap(options) {
47
+ return new Promise((resolve, reject) => {
48
+ const worker = getWorker();
49
+ const requestId = nextRequestId++;
50
+ pending.set(requestId, { resolve, reject });
51
+ worker.postMessage({ type: "generate", requestId, options });
52
+ });
53
+ }
@@ -0,0 +1,18 @@
1
+ import { type GameOptions, type MapData } from "../wasm/avoidant_wasm";
2
+ export interface GenerateMessage {
3
+ type: "generate";
4
+ requestId: number;
5
+ options: GameOptions;
6
+ }
7
+ export interface ResultResponse {
8
+ type: "result";
9
+ requestId: number;
10
+ cells: MapData["cells"];
11
+ terrain: MapData["terrain"];
12
+ }
13
+ export interface ErrorResponse {
14
+ type: "error";
15
+ requestId: number;
16
+ message: string;
17
+ }
18
+ export type WorkerResponse = ResultResponse | ErrorResponse;
@@ -0,0 +1,41 @@
1
+ /// <reference lib="webworker" />
2
+ import init, { generateMapData } from "../wasm/avoidant_wasm";
3
+ const ctx = self;
4
+ let wasmReady;
5
+ function ensureWasm() {
6
+ if (!wasmReady) {
7
+ wasmReady = init();
8
+ }
9
+ return wasmReady;
10
+ }
11
+ ctx.addEventListener("message", (event) => {
12
+ const message = event.data;
13
+ if (!message || message.type !== "generate") {
14
+ return;
15
+ }
16
+ const respond = (response) => ctx.postMessage(response);
17
+ void (async () => {
18
+ try {
19
+ await ensureWasm();
20
+ const data = generateMapData(message.options);
21
+ const terrain = {
22
+ positions: data.terrain.positions,
23
+ normals: data.terrain.normals,
24
+ cellIndices: data.terrain.cellIndices,
25
+ };
26
+ respond({
27
+ type: "result",
28
+ requestId: message.requestId,
29
+ cells: data.cells,
30
+ terrain,
31
+ });
32
+ }
33
+ catch (error) {
34
+ respond({
35
+ type: "error",
36
+ requestId: message.requestId,
37
+ message: error instanceof Error ? `${error.name}: ${error.message}` : String(error),
38
+ });
39
+ }
40
+ })();
41
+ });
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "devDependencies": {
3
+ "@eslint/compat": "^2.0.4",
4
+ "@eslint/js": "^10.0.1",
5
+ "@inlang/paraglide-js": "^2.15.2",
6
+ "@sveltejs/adapter-static": "^3.0.10",
7
+ "@sveltejs/kit": "^2.57.0",
8
+ "@sveltejs/package": "^2.5.7",
9
+ "@sveltejs/vite-plugin-svelte": "^7.0.0",
10
+ "@tailwindcss/forms": "^0.5.11",
11
+ "@tailwindcss/typography": "^0.5.19",
12
+ "@tailwindcss/vite": "^4.2.2",
13
+ "@types/node": "^24",
14
+ "@vitest/browser-playwright": "^4.1.3",
15
+ "eslint": "^10.2.0",
16
+ "eslint-config-prettier": "^10.1.8",
17
+ "eslint-plugin-svelte": "^3.17.0",
18
+ "globals": "^17.4.0",
19
+ "playwright": "^1.59.1",
20
+ "prettier": "^3.8.1",
21
+ "prettier-plugin-glsl": "^0.3.0",
22
+ "prettier-plugin-svelte": "^3.5.1",
23
+ "prettier-plugin-tailwindcss": "^0.7.2",
24
+ "publint": "^0.3.21",
25
+ "svelte": "^5.55.2",
26
+ "svelte-check": "^4.4.6",
27
+ "tailwindcss": "^4.2.2",
28
+ "typescript": "^6.0.2",
29
+ "typescript-eslint": "^8.58.1",
30
+ "vite": "^8.0.7",
31
+ "vite-plugin-wasm": "^3.6.0",
32
+ "vitest": "^4.1.3",
33
+ "vitest-browser-svelte": "^2.1.0"
34
+ },
35
+ "dependencies": {
36
+ "@threlte/core": "^8.5.9",
37
+ "@threlte/extras": "^9.15.0"
38
+ },
39
+ "exports": {
40
+ ".": {
41
+ "types": "./dist/index.d.ts",
42
+ "import": "./dist/index.js",
43
+ "svelte": "./dist/index.js",
44
+ "default": "./dist/index.js"
45
+ },
46
+ "./styles.css": "./dist/styles/global.css"
47
+ },
48
+ "files": [
49
+ "dist",
50
+ "!dist/**/*.test.*",
51
+ "!dist/**/*.spec.*"
52
+ ],
53
+ "name": "@kuncat/avoidant",
54
+ "peerDependencies": {
55
+ "svelte": "^5.0.0",
56
+ "tailwindcss": "^4.0.0"
57
+ },
58
+ "peerDependenciesMeta": {
59
+ "tailwindcss": {
60
+ "optional": true
61
+ }
62
+ },
63
+ "repository": {
64
+ "type": "git",
65
+ "url": "https://github.com/kuncat/avoidant"
66
+ },
67
+ "scripts": {
68
+ "dev": "vite dev",
69
+ "build": "npm run build:wasm && vite build",
70
+ "build:wasm": "wasm-pack build crates/game --target web --out-dir ../../src/lib/wasm --out-name avoidant_wasm && rm -f src/lib/wasm/.gitignore",
71
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
72
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
73
+ "format": "prettier --write .",
74
+ "lint": "prettier --check . && eslint .",
75
+ "prepack": "npm run build:wasm && svelte-kit sync && svelte-package && rm -f dist/paraglide/.gitignore dist/paraglide/.prettierignore && publint",
76
+ "prepare": "svelte-kit sync || echo ''",
77
+ "preview": "vite preview",
78
+ "test:unit": "vitest",
79
+ "test": "npm run test:unit -- --run"
80
+ },
81
+ "sideEffects": [
82
+ "**/*.css"
83
+ ],
84
+ "type": "module",
85
+ "version": "0.1.0"
86
+ }