@whatever-engine/api 0.2.0 → 0.2.2

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/README.md CHANGED
@@ -25,10 +25,14 @@ No install step needed — Bun resolves the package automatically for any script
25
25
  - `Engine.on(event, handler)` — subscribe to an engine event (`init`, `exit`, `tick`, `mod_message`)
26
26
  - `Engine.log(level, message)` — log through the engine logger (`"info"`, `"warn"`, `"error"`)
27
27
  - `Engine.setTickRate(ticks_per_second)` — override the game tick rate at runtime
28
+ - `Engine.setFpsCap(fps | null)` — set FPS cap; `null` = uncapped
29
+ - `Engine.setVsync(enabled)` — enable or disable vertical sync
28
30
 
29
31
  ### `Window`
30
32
 
31
33
  - `Window.setTitle(title)` — change the window title
34
+ - `Window.setSize(width, height)` — request a new inner size in physical pixels (no-op in fullscreen modes)
35
+ - `Window.setMode(mode)` — set display mode: `"windowed"`, `"borderless"`, or `"fullscreen"`
32
36
 
33
37
  ### `File`
34
38
 
@@ -69,7 +73,7 @@ Built-in component types: `core:transform`, `core:sprite_renderer`. `getComponen
69
73
 
70
74
  Methods (all setters chainable, return `this`):
71
75
 
72
- - `getX/Y/Z()`, `setX/Y/Z(v)` — individual position components
76
+ - `getX/Y/Z()`, `setX/Y/Z(v)`, `addX/Y/Z(v)` — individual position components
73
77
  - `getPosition()` → `[x, y, z]`, `setPosition(x, y, z)` — full position
74
78
  - `getScaleX/Y/Z()`, `setScaleX/Y/Z(v)` — individual scale components
75
79
  - `getScale()` → `[x, y, z]`, `setScale(x, y, z)`, `setScaleUniform(s)` — full scale
package/dist/index.d.ts CHANGED
@@ -80,11 +80,26 @@ export declare const Engine: {
80
80
  log(level: "info" | "warn" | "error", message: string): void;
81
81
  /** Override the game tick rate. Takes effect immediately. */
82
82
  setTickRate(ticks_per_second: number): void;
83
+ /** Set the FPS cap. Pass `null` to remove the cap (uncapped). */
84
+ setFpsCap(fps: number | null): void;
85
+ /** Enable or disable vertical sync. Takes effect immediately. */
86
+ setVsync(enabled: boolean): void;
83
87
  };
88
+ export type WindowMode = "windowed" | "borderless" | "fullscreen";
84
89
  /** Window management. */
85
90
  export declare const Window: {
86
91
  /** Set the title of the active window. */
87
92
  setTitle(title: string): void;
93
+ /** Request a new inner window size in physical pixels. Has no effect in fullscreen modes. */
94
+ setSize(width: number, height: number): void;
95
+ /**
96
+ * Set the window display mode.
97
+ * - `"windowed"` — normal window
98
+ * - `"borderless"` — borderless fullscreen (windowed fullscreen)
99
+ * - `"fullscreen"` — exclusive fullscreen using the monitor's preferred video mode;
100
+ * falls back to borderless if no exclusive mode is available
101
+ */
102
+ setMode(mode: WindowMode): void;
88
103
  };
89
104
  /** Sandboxed per-mod file I/O. Paths must not contain `..`. */
90
105
  declare const File$1: {
@@ -353,6 +368,10 @@ export type ArgSpec = {
353
368
  type: ArgType;
354
369
  required?: boolean;
355
370
  description?: string;
371
+ /** Called to provide autocomplete suggestions for this argument.
372
+ * Receives the current raw text the user has typed (empty string if nothing yet).
373
+ * Return a list of candidate strings. */
374
+ suggest?: (current: string) => string[] | Promise<string[]>;
356
375
  };
357
376
  /** A command or subcommand specification. */
358
377
  export type CommandSpec = {
package/dist/index.js CHANGED
@@ -28,14 +28,21 @@ var _EVENT_SUBSCRIBE = {
28
28
  // src/components/console.ts
29
29
  var _cmdHandlers = new Map;
30
30
  var _cmdArgSpecs = new Map;
31
+ var _argSuggesters = new Map;
31
32
  function _specToInternal(spec, pathPrefix) {
32
33
  const path = pathPrefix ? `${pathPrefix}.${spec.name}` : spec.name;
33
- const mappedArgs = (spec.args ?? []).map((a) => ({
34
- name: a.name,
35
- type: a.type,
36
- required: a.required ?? false,
37
- description: a.description ?? ""
38
- }));
34
+ const mappedArgs = (spec.args ?? []).map((a, i) => {
35
+ if (a.suggest) {
36
+ _argSuggesters.set(`${path}:${i}`, a.suggest);
37
+ }
38
+ return {
39
+ name: a.name,
40
+ type: a.type,
41
+ required: a.required ?? false,
42
+ description: a.description ?? "",
43
+ has_suggest: !!a.suggest
44
+ };
45
+ });
39
46
  if (spec.handler) {
40
47
  _cmdHandlers.set(path, spec.handler);
41
48
  _cmdArgSpecs.set(path, mappedArgs);
@@ -71,6 +78,19 @@ async function _handleCommandInvoke(msg) {
71
78
  _send({ type: "CommandResponse", request_id: msg.request_id, output: [], error: message });
72
79
  }
73
80
  }
81
+ async function _handleArgSuggestRequest(msg) {
82
+ const key = `${msg.command_path.join(".")}:${msg.arg_index}`;
83
+ const suggester = _argSuggesters.get(key);
84
+ let suggestions = [];
85
+ if (suggester) {
86
+ try {
87
+ suggestions = await suggester(msg.current);
88
+ } catch {
89
+ suggestions = [];
90
+ }
91
+ }
92
+ _send({ type: "ArgSuggestResponse", request_id: msg.request_id, suggestions });
93
+ }
74
94
  var Console = {
75
95
  register(spec) {
76
96
  if (!/^[a-z_]+$/.test(spec.name)) {
@@ -94,6 +114,10 @@ function _dispatch(msg) {
94
114
  _handleCommandInvoke(msg);
95
115
  return;
96
116
  }
117
+ if (msg.type === "ArgSuggestRequest") {
118
+ _handleArgSuggestRequest(msg);
119
+ return;
120
+ }
97
121
  if (msg.type === "Tick") {
98
122
  const handlers = _handlers.get("tick");
99
123
  const promises = [];
@@ -221,12 +245,24 @@ var Engine = {
221
245
  },
222
246
  setTickRate(ticks_per_second) {
223
247
  _send({ type: "SetTickRate", ticks_per_second });
248
+ },
249
+ setFpsCap(fps) {
250
+ _send({ type: "SetFpsCap", fps });
251
+ },
252
+ setVsync(enabled) {
253
+ _send({ type: "SetVsync", enabled });
224
254
  }
225
255
  };
226
256
  // src/components/window.ts
227
257
  var Window = {
228
258
  setTitle(title) {
229
259
  _send({ type: "SetWindowTitle", title });
260
+ },
261
+ setSize(width, height) {
262
+ _send({ type: "SetWindowSize", width, height });
263
+ },
264
+ setMode(mode) {
265
+ _send({ type: "SetWindowMode", mode });
230
266
  }
231
267
  };
232
268
  // src/components/file.ts
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Mester",
4
4
  "license": "Apache-2.0",
5
5
  "description": "TypeScript scripting API for Whatever Engine mods",
6
- "version": "0.2.0",
6
+ "version": "0.2.2",
7
7
  "module": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
9
  "exports": {