@whatever-engine/api 0.2.1 → 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 +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +30 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ Built-in component types: `core:transform`, `core:sprite_renderer`. `getComponen
|
|
|
73
73
|
|
|
74
74
|
Methods (all setters chainable, return `this`):
|
|
75
75
|
|
|
76
|
-
- `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
|
|
77
77
|
- `getPosition()` → `[x, y, z]`, `setPosition(x, y, z)` — full position
|
|
78
78
|
- `getScaleX/Y/Z()`, `setScaleX/Y/Z(v)` — individual scale components
|
|
79
79
|
- `getScale()` → `[x, y, z]`, `setScale(x, y, z)`, `setScaleUniform(s)` — full scale
|
package/dist/index.d.ts
CHANGED
|
@@ -368,6 +368,10 @@ export type ArgSpec = {
|
|
|
368
368
|
type: ArgType;
|
|
369
369
|
required?: boolean;
|
|
370
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[]>;
|
|
371
375
|
};
|
|
372
376
|
/** A command or subcommand specification. */
|
|
373
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 = [];
|
package/package.json
CHANGED