@al8b/vm 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.
@@ -0,0 +1,196 @@
1
+ /**
2
+ * VM related type definitions
3
+ */
4
+ /**
5
+ * Player API exposed to game code - controls player UX
6
+ */
7
+ interface PlayerAPI {
8
+ /** Pause the game loop */
9
+ pause: () => void;
10
+ /** Resume the game loop */
11
+ resume: () => void;
12
+ /** Send a custom message to the host application */
13
+ postMessage: (message: any) => void;
14
+ /** Set target update rate (FPS) */
15
+ setFps: (fps: number) => void;
16
+ /** Current FPS (read-only) */
17
+ readonly fps: number;
18
+ /** Target update rate in Hz (read/write) */
19
+ update_rate: number;
20
+ }
21
+ /**
22
+ * System API exposed to game code - system info and utilities
23
+ */
24
+ interface SystemAPI {
25
+ time: number;
26
+ fps: number;
27
+ cpu_load: number;
28
+ update_rate: number;
29
+ language: string;
30
+ inputs: {
31
+ keyboard: number;
32
+ mouse: number;
33
+ touch: number;
34
+ gamepad: number;
35
+ };
36
+ loading?: number;
37
+ prompt: (text: string, callback: (result: string) => void) => void;
38
+ say: (text: string) => void;
39
+ file: {
40
+ dropped: number;
41
+ };
42
+ javascript: any;
43
+ disable_autofullscreen?: number;
44
+ preemptive?: number;
45
+ threads?: any[];
46
+ }
47
+ /**
48
+ * Storage interface exposed to game code
49
+ */
50
+ interface StorageInterface {
51
+ set: (name: string, value: unknown) => void;
52
+ get: (name: string) => unknown;
53
+ }
54
+ /**
55
+ * Scene interface exposed to game code
56
+ */
57
+ interface SceneInterface {
58
+ register: (name: string, def: Record<string, unknown>) => void;
59
+ route: (path: string, sceneName: string) => void;
60
+ goto: (name: string, params?: Record<string, string>) => void;
61
+ current: () => string | null;
62
+ }
63
+ /**
64
+ * Router interface exposed to game code
65
+ */
66
+ interface RouterInterface {
67
+ navigate: (path: string) => void;
68
+ back: () => void;
69
+ readonly path: string;
70
+ }
71
+ /**
72
+ * Global API exposed to game code
73
+ *
74
+ * Core service fields (screen, audio, keyboard, etc.) use Record<string, any>
75
+ * because they are dynamically populated from different core packages with varying shapes.
76
+ * Helper interfaces above document the expected shape of stable APIs.
77
+ */
78
+ interface GlobalAPI {
79
+ screen: Record<string, any>;
80
+ audio: Record<string, any>;
81
+ keyboard: Record<string, any>;
82
+ mouse: Record<string, any>;
83
+ touch: Record<string, any>;
84
+ gamepad: Record<string, any>;
85
+ sprites: Record<string, any>;
86
+ maps: Record<string, any>;
87
+ sounds: Record<string, any>;
88
+ music: Record<string, any>;
89
+ assets: Record<string, any>;
90
+ storage: Record<string, any>;
91
+ scene: Record<string, any>;
92
+ route: Record<string, any>;
93
+ router: Record<string, any>;
94
+ player: Record<string, any>;
95
+ system: SystemAPI;
96
+ fonts?: Record<string, any>;
97
+ Sound?: any;
98
+ Image?: any;
99
+ Sprite?: any;
100
+ TileMap?: any;
101
+ Palette?: any;
102
+ Random?: any;
103
+ }
104
+ /**
105
+ * Meta functions (built-in functions)
106
+ */
107
+ interface MetaFunctions {
108
+ print: (text: any) => void;
109
+ round: (x: number) => number;
110
+ floor: (x: number) => number;
111
+ ceil: (x: number) => number;
112
+ abs: (x: number) => number;
113
+ min: (x: number, y: number) => number;
114
+ max: (x: number, y: number) => number;
115
+ sqrt: (x: number) => number;
116
+ pow: (x: number, y: number) => number;
117
+ sin: (x: number) => number;
118
+ cos: (x: number) => number;
119
+ tan: (x: number) => number;
120
+ asin: (x: number) => number;
121
+ acos: (x: number) => number;
122
+ atan: (x: number) => number;
123
+ atan2: (y: number, x: number) => number;
124
+ sind: (x: number) => number;
125
+ cosd: (x: number) => number;
126
+ tand: (x: number) => number;
127
+ asind: (x: number) => number;
128
+ acosd: (x: number) => number;
129
+ atand: (x: number) => number;
130
+ atan2d: (y: number, x: number) => number;
131
+ log: (x: number) => number;
132
+ exp: (x: number) => number;
133
+ random: any;
134
+ PI: number;
135
+ true: number;
136
+ false: number;
137
+ }
138
+ /**
139
+ * Warning info for a specific code location
140
+ */
141
+ interface WarningInfo {
142
+ file: string;
143
+ line: number;
144
+ column: number;
145
+ expression?: string;
146
+ identifier?: string;
147
+ reported?: boolean;
148
+ }
149
+ /**
150
+ * Accumulated warnings structure
151
+ */
152
+ interface VMWarnings {
153
+ using_undefined_variable: Record<string, WarningInfo>;
154
+ assigning_field_to_undefined: Record<string, WarningInfo>;
155
+ invoking_non_function: Record<string, WarningInfo>;
156
+ assigning_api_variable: Record<string, WarningInfo>;
157
+ assignment_as_condition: Record<string, WarningInfo>;
158
+ }
159
+ /**
160
+ * VM Context
161
+ */
162
+ interface VMContext {
163
+ meta: MetaFunctions;
164
+ global: GlobalAPI;
165
+ local: any;
166
+ object: any;
167
+ breakable: number;
168
+ continuable: number;
169
+ returnable: number;
170
+ stack_size: number;
171
+ timeout: number;
172
+ warnings: VMWarnings;
173
+ }
174
+ /**
175
+ * Call frame for stack trace
176
+ */
177
+ interface CallFrame {
178
+ functionName: string;
179
+ file: string;
180
+ line: number;
181
+ column: number;
182
+ }
183
+ /**
184
+ * Error information returned by VM
185
+ */
186
+ interface ErrorInfo {
187
+ error: string;
188
+ type?: string;
189
+ line?: number;
190
+ column?: number;
191
+ file?: string;
192
+ stack?: string;
193
+ stackTrace?: CallFrame[];
194
+ }
195
+
196
+ export type { CallFrame, ErrorInfo, GlobalAPI, MetaFunctions, PlayerAPI, RouterInterface, SceneInterface, StorageInterface, SystemAPI, VMContext, VMWarnings, WarningInfo };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/types/index.ts
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["/**\n * VM related type definitions\n */\n\n/**\n * Player API exposed to game code - controls player UX\n */\nexport interface PlayerAPI {\n\t/** Pause the game loop */\n\tpause: () => void;\n\t/** Resume the game loop */\n\tresume: () => void;\n\t/** Send a custom message to the host application */\n\tpostMessage: (message: any) => void;\n\t/** Set target update rate (FPS) */\n\tsetFps: (fps: number) => void;\n\t/** Current FPS (read-only) */\n\treadonly fps: number;\n\t/** Target update rate in Hz (read/write) */\n\tupdate_rate: number;\n}\n\n/**\n * System API exposed to game code - system info and utilities\n */\nexport interface SystemAPI {\n\ttime: number;\n\tfps: number;\n\tcpu_load: number;\n\tupdate_rate: number;\n\tlanguage: string;\n\tinputs: {\n\t\tkeyboard: number;\n\t\tmouse: number;\n\t\ttouch: number;\n\t\tgamepad: number;\n\t};\n\tloading?: number;\n\tprompt: (text: string, callback: (result: string) => void) => void;\n\tsay: (text: string) => void;\n\tfile: {\n\t\tdropped: number;\n\t};\n\tjavascript: any;\n\tdisable_autofullscreen?: number;\n\tpreemptive?: number;\n\tthreads?: any[];\n}\n\n/**\n * Storage interface exposed to game code\n */\nexport interface StorageInterface {\n\tset: (name: string, value: unknown) => void;\n\tget: (name: string) => unknown;\n}\n\n/**\n * Scene interface exposed to game code\n */\nexport interface SceneInterface {\n\tregister: (name: string, def: Record<string, unknown>) => void;\n\troute: (path: string, sceneName: string) => void;\n\tgoto: (name: string, params?: Record<string, string>) => void;\n\tcurrent: () => string | null;\n}\n\n/**\n * Router interface exposed to game code\n */\nexport interface RouterInterface {\n\tnavigate: (path: string) => void;\n\tback: () => void;\n\treadonly path: string;\n}\n\n/**\n * Global API exposed to game code\n *\n * Core service fields (screen, audio, keyboard, etc.) use Record<string, any>\n * because they are dynamically populated from different core packages with varying shapes.\n * Helper interfaces above document the expected shape of stable APIs.\n */\nexport interface GlobalAPI {\n\tscreen: Record<string, any>;\n\taudio: Record<string, any>;\n\tkeyboard: Record<string, any>;\n\tmouse: Record<string, any>;\n\ttouch: Record<string, any>;\n\tgamepad: Record<string, any>;\n\tsprites: Record<string, any>;\n\tmaps: Record<string, any>;\n\tsounds: Record<string, any>;\n\tmusic: Record<string, any>;\n\tassets: Record<string, any>;\n\tstorage: Record<string, any>;\n\tscene: Record<string, any>;\n\troute: Record<string, any>;\n\trouter: Record<string, any>;\n\tplayer: Record<string, any>;\n\tsystem: SystemAPI;\n\tfonts?: Record<string, any>;\n\tSound?: any;\n\tImage?: any;\n\tSprite?: any;\n\tTileMap?: any;\n\tPalette?: any;\n\tRandom?: any;\n}\n\n/**\n * Meta functions (built-in functions)\n */\nexport interface MetaFunctions {\n\tprint: (text: any) => void;\n\tround: (x: number) => number;\n\tfloor: (x: number) => number;\n\tceil: (x: number) => number;\n\tabs: (x: number) => number;\n\tmin: (x: number, y: number) => number;\n\tmax: (x: number, y: number) => number;\n\tsqrt: (x: number) => number;\n\tpow: (x: number, y: number) => number;\n\tsin: (x: number) => number;\n\tcos: (x: number) => number;\n\ttan: (x: number) => number;\n\tasin: (x: number) => number;\n\tacos: (x: number) => number;\n\tatan: (x: number) => number;\n\tatan2: (y: number, x: number) => number;\n\tsind: (x: number) => number;\n\tcosd: (x: number) => number;\n\ttand: (x: number) => number;\n\tasind: (x: number) => number;\n\tacosd: (x: number) => number;\n\tatand: (x: number) => number;\n\tatan2d: (y: number, x: number) => number;\n\tlog: (x: number) => number;\n\texp: (x: number) => number;\n\trandom: any;\n\tPI: number;\n\ttrue: number;\n\tfalse: number;\n}\n\n/**\n * Warning info for a specific code location\n */\nexport interface WarningInfo {\n\tfile: string;\n\tline: number;\n\tcolumn: number;\n\texpression?: string;\n\tidentifier?: string;\n\treported?: boolean;\n}\n\n/**\n * Accumulated warnings structure\n */\nexport interface VMWarnings {\n\tusing_undefined_variable: Record<string, WarningInfo>;\n\tassigning_field_to_undefined: Record<string, WarningInfo>;\n\tinvoking_non_function: Record<string, WarningInfo>;\n\tassigning_api_variable: Record<string, WarningInfo>;\n\tassignment_as_condition: Record<string, WarningInfo>;\n}\n\n/**\n * VM Context\n */\nexport interface VMContext {\n\tmeta: MetaFunctions;\n\tglobal: GlobalAPI;\n\tlocal: any;\n\tobject: any;\n\tbreakable: number;\n\tcontinuable: number;\n\treturnable: number;\n\tstack_size: number;\n\ttimeout: number;\n\twarnings: VMWarnings;\n}\n\n/**\n * Call frame for stack trace\n */\nexport interface CallFrame {\n\tfunctionName: string;\n\tfile: string;\n\tline: number;\n\tcolumn: number;\n}\n\n/**\n * Error information returned by VM\n */\nexport interface ErrorInfo {\n\terror: string;\n\ttype?: string;\n\tline?: number;\n\tcolumn?: number;\n\tfile?: string;\n\tstack?: string;\n\tstackTrace?: CallFrame[];\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@al8b/vm",
3
+ "version": "0.1.0",
4
+ "sideEffects": false,
5
+ "files": [
6
+ "dist/**/*",
7
+ "README.md",
8
+ "package.json"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsup",
12
+ "clean": "bun --bun ../../../scripts/clean-package.mjs dist",
13
+ "test": "vitest run --passWithNoTests"
14
+ },
15
+ "main": "./dist/index.js",
16
+ "module": "./dist/index.mjs",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.mjs",
22
+ "require": "./dist/index.js"
23
+ }
24
+ },
25
+ "dependencies": {
26
+ "@al8b/lootiscript": "workspace:*",
27
+ "@al8b/io": "workspace:*",
28
+ "@al8b/framework-shared": "workspace:*"
29
+ },
30
+ "keywords": [
31
+ "vm",
32
+ "runtime",
33
+ "lootiscript"
34
+ ],
35
+ "publishConfig": {
36
+ "access": "public"
37
+ }
38
+ }