gdharness 1.0.17 → 1.0.19
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/build/cli.js +26 -7
- package/build/godot/addons/gdharness_runtime/runtime_paths.gd +251 -0
- package/build/godot/addons/gdharness_runtime/runtime_paths.gd.uid +1 -0
- package/build/godot/addons/gdharness_runtime/runtime_queries.gd +74 -230
- package/build/godot/addons/gdharness_runtime/runtime_values.gd +81 -0
- package/build/godot/addons/gdharness_runtime/runtime_waits.gd +4 -3
- package/build/index.js +26 -7
- package/package.json +1 -1
package/build/cli.js
CHANGED
|
@@ -16409,7 +16409,7 @@ var init_tool_definitions = __esm(() => {
|
|
|
16409
16409
|
},
|
|
16410
16410
|
{
|
|
16411
16411
|
name: "editor_status",
|
|
16412
|
-
description: "Whether the editor addon is connected, which Godot answers, whether the editor is playing something, and whether a game with the runtime addon is reachable. playingInEditor is null when the editor was not asked or did not answer, which is not the same as a no: with no editor connected there is nobody to ask, and an editor that does not serve the question is given a moment and then left. A game can be playing while this is null, so read it as unanswered rather than as nothing playing, and use processActive and runtimes, which come from elsewhere and do not depend on the editor answering. Each game under runtimes is pinged with a short wait, so one held at a breakpoint is listed as unreachable rather than making this call wait out the runtime timeout; for the run this server is reporting on, heldAt says whether that is what it is, with the same three answers editor_output gives. A game the editor played announces the editor under editorPid, and so does whatever that game started for itself; a game some other server started announces none, which is how the two are told apart when both are running from one project. When connected is false, mayYetConnect says whether that is final: the editor dials this server rather than the other way round and backs off between tries, so for the first half-minute after a server starts, false means \"not reached yet\" as often as it means \"no editor\". True is worth waiting out; false is an editor that is not there. False beside restartInterrupted is one that an editor_launch restart on a previous server asked to quit, where the launch half never ran because that server was ended in between, usually by the reconnect the restart was taken for; editor_launch open finishes it. listeningSince is when this server took the bridge port, which is what that window is measured from and what a caller wanting its own window should read. An editor this server opened counts for as long as its process lives, however far past that window the import runs, and awaitingLaunchedEditor names its pid so the two reasons for true are told apart. settingsDropped appears here once when the editor this server opened saved project.godot on its way in, which is the same reading editor_launch restart makes in its own answer. A game that has announced itself in a protocol this server does not speak is listed under unreadable rather than left out, with the protocol it speaks and whether the server or the addon is the older half. This happens during an upgrade that moves the runtime protocol, which most do not: installing replaces the addon on disk as soon as the pin moves, while a server that is already running stays on the version it started with, so the two speak different protocols until the server is reconnected. Those games are real and running, but no tool here can reach them until the halves match, so runtimes stays empty and runtimeConnected stays false. An upgrade that leaves the protocol alone opens no such window and this list stays empty through it.",
|
|
16412
|
+
description: "Whether the editor addon is connected, which Godot answers, whether the editor is playing something, and whether a game with the runtime addon is reachable: runtimeConnected counts the games of the project this server serves, and runtimes lists every game on the machine with ofThisProject saying which is which, since a game of another project is reached only by naming its projectPath. playingInEditor is null when the editor was not asked or did not answer, which is not the same as a no: with no editor connected there is nobody to ask, and an editor that does not serve the question is given a moment and then left. A game can be playing while this is null, so read it as unanswered rather than as nothing playing, and use processActive and runtimes, which come from elsewhere and do not depend on the editor answering. Each game under runtimes is pinged with a short wait, so one held at a breakpoint is listed as unreachable rather than making this call wait out the runtime timeout; for the run this server is reporting on, heldAt says whether that is what it is, with the same three answers editor_output gives. A game the editor played announces the editor under editorPid, and so does whatever that game started for itself; a game some other server started announces none, which is how the two are told apart when both are running from one project. When connected is false, mayYetConnect says whether that is final: the editor dials this server rather than the other way round and backs off between tries, so for the first half-minute after a server starts, false means \"not reached yet\" as often as it means \"no editor\". True is worth waiting out; false is an editor that is not there. False beside restartInterrupted is one that an editor_launch restart on a previous server asked to quit, where the launch half never ran because that server was ended in between, usually by the reconnect the restart was taken for; editor_launch open finishes it. listeningSince is when this server took the bridge port, which is what that window is measured from and what a caller wanting its own window should read. An editor this server opened counts for as long as its process lives, however far past that window the import runs, and awaitingLaunchedEditor names its pid so the two reasons for true are told apart. settingsDropped appears here once when the editor this server opened saved project.godot on its way in, which is the same reading editor_launch restart makes in its own answer. A game that has announced itself in a protocol this server does not speak is listed under unreadable rather than left out, with the protocol it speaks and whether the server or the addon is the older half. This happens during an upgrade that moves the runtime protocol, which most do not: installing replaces the addon on disk as soon as the pin moves, while a server that is already running stays on the version it started with, so the two speak different protocols until the server is reconnected. Those games are real and running, but no tool here can reach them until the halves match, so runtimes stays empty and runtimeConnected stays false. An upgrade that leaves the protocol alone opens no such window and this list stays empty through it.",
|
|
16413
16413
|
parameters: {},
|
|
16414
16414
|
requires: []
|
|
16415
16415
|
},
|
|
@@ -16569,7 +16569,7 @@ var init_tool_definitions = __esm(() => {
|
|
|
16569
16569
|
value: {
|
|
16570
16570
|
ops: ["set"],
|
|
16571
16571
|
blank: true,
|
|
16572
|
-
description: `set: the value, fitted to the property's type. "" writes an empty string.`
|
|
16572
|
+
description: `set: the value, fitted to the property's type. "" writes an empty string. A property typed as or holding an object takes a path naming one the game holds, the way call's args do, and holds that instance.`
|
|
16573
16573
|
},
|
|
16574
16574
|
method: {
|
|
16575
16575
|
type: "string",
|
|
@@ -16579,7 +16579,7 @@ var init_tool_definitions = __esm(() => {
|
|
|
16579
16579
|
args: {
|
|
16580
16580
|
type: "array",
|
|
16581
16581
|
ops: ["call"],
|
|
16582
|
-
description:
|
|
16582
|
+
description: `call: the arguments, fitted to the method's parameter types. A parameter typed as an object takes a path naming one the game holds and is handed that instance: a colon path read from nodePath, "_game:run:wares:3", or one starting at a node, "/root/Main/Hud" or "/root/Main:_game:run". A path that reaches no object, or an object of another class than the parameter declares, is refused.`
|
|
16583
16583
|
}
|
|
16584
16584
|
},
|
|
16585
16585
|
requires: ["nodePath"],
|
|
@@ -38130,6 +38130,19 @@ function runIsUp(run, editorSays, now = Date.now()) {
|
|
|
38130
38130
|
}
|
|
38131
38131
|
return editorSays ?? stillRunning(run);
|
|
38132
38132
|
}
|
|
38133
|
+
function noCodeWillCome(run) {
|
|
38134
|
+
return run.exitCode === null && run.process === null;
|
|
38135
|
+
}
|
|
38136
|
+
function endedWithoutACode(run) {
|
|
38137
|
+
if (!run.throughEditor) {
|
|
38138
|
+
return "This run was started by another server, the one this server replaced or one running beside it, and it ended with nothing here waiting on it, so its exit code was never collected. Everything it printed is below, read back from its transcript.";
|
|
38139
|
+
}
|
|
38140
|
+
const kept = "A game the editor plays is the editor's own child, so its exit code stays with the editor and none was collected here.";
|
|
38141
|
+
if (!run.announced && run.couldAnnounce) {
|
|
38142
|
+
return `The editor stopped playing this run before its game announced a runtime, so the game ended while it was starting or was closed in the editor. ${kept} What it printed is below, and editor_output with op "editor" has what the editor said about it.`;
|
|
38143
|
+
}
|
|
38144
|
+
return `The editor stopped playing this run. ${kept} What it printed is below.`;
|
|
38145
|
+
}
|
|
38133
38146
|
function endedPreviousRun(ended) {
|
|
38134
38147
|
if (ended === null) {
|
|
38135
38148
|
return;
|
|
@@ -39871,6 +39884,7 @@ class GodotServer {
|
|
|
39871
39884
|
pid: endpoint.pid,
|
|
39872
39885
|
port: endpoint.port,
|
|
39873
39886
|
project: endpoint.project,
|
|
39887
|
+
...this.ownProject === null ? {} : { ofThisProject: isSameDirectory(endpoint.project.path, this.ownProject) },
|
|
39874
39888
|
editorPid: endpoint.editorPid,
|
|
39875
39889
|
reachable: reply.ok,
|
|
39876
39890
|
problem: reply.ok ? null : reply.message
|
|
@@ -39902,7 +39916,7 @@ class GodotServer {
|
|
|
39902
39916
|
processActive: active,
|
|
39903
39917
|
playingInEditor: playing,
|
|
39904
39918
|
...hold,
|
|
39905
|
-
runtimeConnected: games.some((game) => game.reachable),
|
|
39919
|
+
runtimeConnected: games.some((game) => game.reachable && game.ofThisProject !== false),
|
|
39906
39920
|
runtimes: games,
|
|
39907
39921
|
unreadable: announced.unspoken.map((game) => ({
|
|
39908
39922
|
pid: game.pid,
|
|
@@ -40827,7 +40841,8 @@ class GodotServer {
|
|
|
40827
40841
|
}
|
|
40828
40842
|
const budgetMs = readPositiveNumber(args, "timeoutMs") ?? WAIT_FOR_RUN_MS;
|
|
40829
40843
|
const until = Date.now() + budgetMs;
|
|
40830
|
-
|
|
40844
|
+
const cancelled = callSignal();
|
|
40845
|
+
while (cancelled?.aborted !== true && await this.runStillGoing(run) && Date.now() < until) {
|
|
40831
40846
|
this.drainEditorOutput(run);
|
|
40832
40847
|
this.drainTranscript(run);
|
|
40833
40848
|
await delay3(RUN_POLL_MS);
|
|
@@ -40921,7 +40936,7 @@ class GodotServer {
|
|
|
40921
40936
|
const going = await this.runStillGoing(run);
|
|
40922
40937
|
if (run.endedUnwatched !== true && !going) {
|
|
40923
40938
|
run.log.finish();
|
|
40924
|
-
run.endedUnwatched = run
|
|
40939
|
+
run.endedUnwatched = noCodeWillCome(run);
|
|
40925
40940
|
}
|
|
40926
40941
|
const severity = readString(args, "severity");
|
|
40927
40942
|
const selected = run.log.select({
|
|
@@ -40943,7 +40958,11 @@ class GodotServer {
|
|
|
40943
40958
|
notes.push(`The wait of ${waitedMs}ms ran out and the run is still going, so this is what it had printed by then rather than everything it will print. editor_run wait again to keep waiting.`);
|
|
40944
40959
|
}
|
|
40945
40960
|
if (run.endedUnwatched === true) {
|
|
40946
|
-
notes.push(
|
|
40961
|
+
notes.push(endedWithoutACode({
|
|
40962
|
+
throughEditor: run.throughEditor,
|
|
40963
|
+
announced: announced !== undefined || run.announcedPid !== undefined,
|
|
40964
|
+
couldAnnounce: run.projectPath !== null && existsSync15(join23(run.projectPath, RUNTIME_AUTOLOAD2.path))
|
|
40965
|
+
}));
|
|
40947
40966
|
}
|
|
40948
40967
|
if (run.pickedUpPlaying === true) {
|
|
40949
40968
|
notes.push(run.transcript === null ? "The editor was already playing this when this server reached it, and the server that started it left no transcript, so this is not the run from its start: what it printed before that is only in the editor. It is the run the editor is holding now, which is the one the debug_* tools answer for." : "The editor was already playing this when this server reached it, and what it printed before that has been read back from its transcript. It is the run the editor is holding now, which is the one the debug_* tools answer for.");
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
extends RefCounted
|
|
2
|
+
|
|
3
|
+
## Colon paths through what a node holds: "/root/Main" with "_game:run:day" reaches the day off the
|
|
4
|
+
## run off the game the node keeps. Every op that reads, writes, calls or waits on a game's state
|
|
5
|
+
## walks the same way, so the walk and what it says when a step is not there live in one place.
|
|
6
|
+
|
|
7
|
+
const Values = preload("runtime_values.gd")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## What [param reaching] names something on, which is the node itself until the name has a colon
|
|
11
|
+
## in it, and the last name along that path.
|
|
12
|
+
##
|
|
13
|
+
## A game's state does not sit on nodes, it hangs off them: the speed of the clock is a property of
|
|
14
|
+
## a [RefCounted] held by a [RefCounted] held by the root, and that is what an agent asks about.
|
|
15
|
+
## What a game does hangs off them the same way, so the last name is a property to read, a property
|
|
16
|
+
## to write or a method to call, and the walk to it is one walk.
|
|
17
|
+
##
|
|
18
|
+
## Colons, because that is the separator [method Object.get_indexed] already takes. Walked a step
|
|
19
|
+
## at a time rather than handed to that method, which answers null for a path that goes wrong
|
|
20
|
+
## halfway along and for one that ends on null.
|
|
21
|
+
##
|
|
22
|
+
## A step written as a call, "get_viewport()", calls a method of that name that takes no arguments
|
|
23
|
+
## and walks into what it returned. Some of what hangs off a node is only reachable by asking:
|
|
24
|
+
## which control holds the focus is a question for the viewport a control is in, and the viewport
|
|
25
|
+
## is a method's answer rather than a property. Spelled with the brackets so a reader sees a call
|
|
26
|
+
## where one happens, and so a method can never shadow a property of the same name.
|
|
27
|
+
##
|
|
28
|
+
## Answers with a `message` instead when a step along the way is not there or holds something that
|
|
29
|
+
## is not an object, naming the step rather than the whole path: "/root/Main:_game has no property
|
|
30
|
+
## clocks" is a typo found, and "no property _game:clocks:speed" is a puzzle.
|
|
31
|
+
static func walk_to(node: Node, node_path: String, reaching: String) -> Dictionary:
|
|
32
|
+
var parts: PackedStringArray = reaching.split(":")
|
|
33
|
+
var holder: Variant = node
|
|
34
|
+
var called: String = node_path
|
|
35
|
+
for step: int in parts.size() - 1:
|
|
36
|
+
var named: String = parts[step]
|
|
37
|
+
if not can_read(holder, named):
|
|
38
|
+
return {"type": "error", "message": nothing_there(holder, named, called)}
|
|
39
|
+
holder = read_under(holder, named)
|
|
40
|
+
called = "%s:%s" % [called, named]
|
|
41
|
+
if not _can_hold(holder):
|
|
42
|
+
var wanted: String = parts[step + 1]
|
|
43
|
+
return {"type": "error", "message": "%s holds no object to read %s off" % [called, wanted]}
|
|
44
|
+
return {"holder": holder, "name": parts[parts.size() - 1], "called": called}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## The object [param given] names for a method's argument, as `{"object": ...}`, or as
|
|
48
|
+
## `{"message": ...}` saying why it names none.
|
|
49
|
+
##
|
|
50
|
+
## A colon path read from [param node], the node the call was made on, the way the method's own
|
|
51
|
+
## path is: "_ladder:shop:_wares:-15". One beginning with a slash starts at the node it names
|
|
52
|
+
## instead, "/root/Main/Hud" or "/root/Main:_game:run". The record runtime_inspect answers an object
|
|
53
|
+
## with is not accepted, because its id is a 64-bit number and does not survive being sent as JSON:
|
|
54
|
+
## a rounded id names another object or none, and the path names the one meant.
|
|
55
|
+
static func object_at(root: Node, node: Node, node_path: String, given: Variant) -> Dictionary:
|
|
56
|
+
if given is Dictionary:
|
|
57
|
+
return {
|
|
58
|
+
"message":
|
|
59
|
+
(
|
|
60
|
+
"an object is named by its path, not by the record runtime_inspect answered with:"
|
|
61
|
+
+ " its id does not survive the trip as a number"
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
var path: String = given
|
|
65
|
+
var start: Node = node
|
|
66
|
+
var start_path: String = node_path
|
|
67
|
+
var reaching: String = path
|
|
68
|
+
if path.begins_with("/"):
|
|
69
|
+
var colon: int = path.find(":")
|
|
70
|
+
start_path = path if colon == -1 else path.substr(0, colon)
|
|
71
|
+
var standing: Dictionary = Values.node_at(root, start_path)
|
|
72
|
+
if standing.has("message"):
|
|
73
|
+
return {"message": str(standing["message"])}
|
|
74
|
+
start = standing["node"]
|
|
75
|
+
if colon == -1:
|
|
76
|
+
return {"object": start}
|
|
77
|
+
reaching = path.substr(colon + 1)
|
|
78
|
+
if reaching.is_empty():
|
|
79
|
+
return {"message": "%s names nothing past the node" % path}
|
|
80
|
+
var reached: Dictionary = walk_to(start, start_path, reaching)
|
|
81
|
+
if reached.has("message"):
|
|
82
|
+
return {"message": str(reached["message"])}
|
|
83
|
+
var holder: Variant = reached["holder"]
|
|
84
|
+
var name: String = reached["name"]
|
|
85
|
+
if not can_read(holder, name):
|
|
86
|
+
return {"message": nothing_there(holder, name, str(reached["called"]))}
|
|
87
|
+
var value: Variant = read_under(holder, name)
|
|
88
|
+
if not value is Object or not is_instance_valid(value):
|
|
89
|
+
return {
|
|
90
|
+
"message": "%s:%s holds %s, not an object" % [reached["called"], name, type_string(typeof(value))]
|
|
91
|
+
}
|
|
92
|
+
return {"object": value}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
## Whether a step can be taken into [param value] at all: an object, a list or a map can be walked
|
|
96
|
+
## into, and a number or a string is where a path ends whether the caller meant it to or not.
|
|
97
|
+
static func _can_hold(value: Variant) -> bool:
|
|
98
|
+
return value is Object or value is Array or value is Dictionary
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## What is wrong with reading [param named] off [param holder], or "" when nothing is.
|
|
102
|
+
##
|
|
103
|
+
## Public because a wait asks the same question before it starts waiting, and used to answer it by
|
|
104
|
+
## waiting: a property nobody has spends the whole timeout and comes back "not met", which reads
|
|
105
|
+
## exactly like a game that never reached the state. The read refuses a mistyped name in one call
|
|
106
|
+
## and says so, and the two tools disagreeing about one typo is worth more than the duplication.
|
|
107
|
+
static func nothing_under(holder: Variant, named: String, called: String) -> String:
|
|
108
|
+
return "" if can_read(holder, named) else nothing_there(holder, named, called)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
## Whether [param named] is something [param holder] has.
|
|
112
|
+
##
|
|
113
|
+
## Three kinds of holder, because the state a game keeps is not all properties of objects: a roster
|
|
114
|
+
## is a list and an in-tray is a map, and a path that could not step into either stopped at the
|
|
115
|
+
## first one. An index reads the way a property does, and a negative one counts from the end the
|
|
116
|
+
## way GDScript's own does, so reading the last of something does not mean asking how many first.
|
|
117
|
+
static func can_read(holder: Variant, named: String) -> bool:
|
|
118
|
+
if holder is Array:
|
|
119
|
+
var items: Array = holder
|
|
120
|
+
return _index_in(named, items.size()) != -1
|
|
121
|
+
if holder is Dictionary:
|
|
122
|
+
var map: Dictionary = holder
|
|
123
|
+
return map.has(named) or map.has(StringName(named))
|
|
124
|
+
if holder is Object:
|
|
125
|
+
var object: Object = holder
|
|
126
|
+
var method: String = method_of(named)
|
|
127
|
+
if not method.is_empty():
|
|
128
|
+
return _arguments_required(object, method) == 0
|
|
129
|
+
return _has_property(object, named)
|
|
130
|
+
return false
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
## The method a step written as a call names, "get_viewport()" being get_viewport, or "" for a
|
|
134
|
+
## step that is a name.
|
|
135
|
+
static func method_of(named: String) -> String:
|
|
136
|
+
return named.trim_suffix("()") if named.ends_with("()") else ""
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
## How many arguments [param method] on [param object] has to be given, or -1 when there is no such
|
|
140
|
+
## method. Read off the method list rather than [method Object.has_method], because a path can only
|
|
141
|
+
## call a method with nothing, and a method with a required argument called with nothing raises
|
|
142
|
+
## inside the game rather than answering.
|
|
143
|
+
static func _arguments_required(object: Object, method: String) -> int:
|
|
144
|
+
for entry: Dictionary in object.get_method_list():
|
|
145
|
+
if str(entry.get("name", "")) != method:
|
|
146
|
+
continue
|
|
147
|
+
var params: Array = entry.get("args", [])
|
|
148
|
+
var defaults: Array = entry.get("default_args", [])
|
|
149
|
+
return params.size() - defaults.size()
|
|
150
|
+
return -1
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
## Put [param value] where [param named] points. Only ever called once [method can_read] agrees,
|
|
154
|
+
## and lists and maps are reference types, so writing into one reaches the game's own copy.
|
|
155
|
+
static func write(holder: Variant, named: String, value: Variant) -> void:
|
|
156
|
+
if holder is Array:
|
|
157
|
+
var items: Array = holder
|
|
158
|
+
items[_index_in(named, items.size())] = value
|
|
159
|
+
return
|
|
160
|
+
if holder is Dictionary:
|
|
161
|
+
var map: Dictionary = holder
|
|
162
|
+
# Written back under the key it was found under, since a map keyed by StringName and one
|
|
163
|
+
# keyed by String both read the same way and a write to the wrong one adds a second entry.
|
|
164
|
+
if map.has(named):
|
|
165
|
+
map[named] = value
|
|
166
|
+
else:
|
|
167
|
+
map[StringName(named)] = value
|
|
168
|
+
return
|
|
169
|
+
var object: Object = holder
|
|
170
|
+
object.set(named, value)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
## What [param holder] holds under [param named], or answers to it when [param named] is a call.
|
|
174
|
+
## Only ever called once [method can_read] agrees.
|
|
175
|
+
static func read_under(holder: Variant, named: String) -> Variant:
|
|
176
|
+
if holder is Array:
|
|
177
|
+
var items: Array = holder
|
|
178
|
+
return items[_index_in(named, items.size())]
|
|
179
|
+
if holder is Dictionary:
|
|
180
|
+
var map: Dictionary = holder
|
|
181
|
+
if map.has(named):
|
|
182
|
+
return map[named]
|
|
183
|
+
return map[StringName(named)]
|
|
184
|
+
var object: Object = holder
|
|
185
|
+
var method: String = method_of(named)
|
|
186
|
+
if not method.is_empty():
|
|
187
|
+
return object.call(method)
|
|
188
|
+
return object.get(named)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
## Where [param named] lands in a list of [param size], or -1 for a step that is not in it.
|
|
192
|
+
##
|
|
193
|
+
## -1 for "nowhere" is safe because every answer this gives is an index into a list that long, so a
|
|
194
|
+
## real one is never negative by the time it is returned.
|
|
195
|
+
static func _index_in(named: String, size: int) -> int:
|
|
196
|
+
if not named.is_valid_int():
|
|
197
|
+
return -1
|
|
198
|
+
var index: int = int(named)
|
|
199
|
+
if index < 0:
|
|
200
|
+
index += size
|
|
201
|
+
return index if index >= 0 and index < size else -1
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
## Why a step could not be taken, said in the terms of what was actually there.
|
|
205
|
+
##
|
|
206
|
+
## "has no property 0" about a list is a true sentence that sends somebody looking for a property,
|
|
207
|
+
## so a list says how long it is and a map says what it is keyed by. The step is named rather than
|
|
208
|
+
## the whole path, because the step is the typo.
|
|
209
|
+
static func nothing_there(holder: Variant, named: String, called_as: String) -> String:
|
|
210
|
+
if holder is Array:
|
|
211
|
+
var items: Array = holder
|
|
212
|
+
return "%s is a list of %d, so there is no %s in it" % [called_as, items.size(), named]
|
|
213
|
+
if holder is Dictionary:
|
|
214
|
+
var map: Dictionary = holder
|
|
215
|
+
var keys: Array = map.keys()
|
|
216
|
+
# Eight of them, because a map keyed by something unexpected is told by the first few and a
|
|
217
|
+
# map of two hundred would bury the sentence saying which key was missing.
|
|
218
|
+
var some: Array[String] = []
|
|
219
|
+
for key: Variant in keys.slice(0, 8):
|
|
220
|
+
some.append(str(key))
|
|
221
|
+
var rest: String = ""
|
|
222
|
+
if keys.size() > 8:
|
|
223
|
+
rest = " and %d more" % [keys.size() - 8]
|
|
224
|
+
return "%s has no key %s; it is keyed by %s%s" % [called_as, named, ", ".join(some), rest]
|
|
225
|
+
var object: Object = holder
|
|
226
|
+
var method: String = method_of(named)
|
|
227
|
+
if not method.is_empty():
|
|
228
|
+
var required: int = _arguments_required(object, method)
|
|
229
|
+
if required == -1:
|
|
230
|
+
return "%s has no method %s" % [called_as, method]
|
|
231
|
+
return (
|
|
232
|
+
"%s.%s takes %d argument%s, and a path can only call a method that takes none"
|
|
233
|
+
% [called_as, method, required, "" if required == 1 else "s"]
|
|
234
|
+
)
|
|
235
|
+
# A method spelled as a property is the likeliest thing behind a name the object has no property
|
|
236
|
+
# for, and the caller is one pair of brackets away from what they meant.
|
|
237
|
+
if object.has_method(named):
|
|
238
|
+
return (
|
|
239
|
+
"%s has no property %s; it has a method of that name, which a path calls as %s()"
|
|
240
|
+
% [called_as, named, named]
|
|
241
|
+
)
|
|
242
|
+
return "%s has no property %s" % [called_as, named]
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
## Whether [param holder] declares [param named]. Asked of the list rather than read, because a
|
|
246
|
+
## property read back as null answers it wrongly.
|
|
247
|
+
static func _has_property(holder: Object, named: String) -> bool:
|
|
248
|
+
for entry: Dictionary in holder.get_property_list():
|
|
249
|
+
if str(entry["name"]) == named:
|
|
250
|
+
return true
|
|
251
|
+
return false
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://cna71d704esno
|
|
@@ -3,6 +3,7 @@ extends RefCounted
|
|
|
3
3
|
## What the server asks about the running tree: its shape, one node, the nodes matching a
|
|
4
4
|
## question, where one is on screen, a property set, a method called, the metrics.
|
|
5
5
|
|
|
6
|
+
const Paths = preload("runtime_paths.gd")
|
|
6
7
|
const Read = preload("reading.gd")
|
|
7
8
|
const Values = preload("runtime_values.gd")
|
|
8
9
|
|
|
@@ -182,19 +183,19 @@ func _found(node: Node, wanted_property: String) -> Dictionary:
|
|
|
182
183
|
if wanted_property.is_empty():
|
|
183
184
|
return entry
|
|
184
185
|
entry["property"] = wanted_property
|
|
185
|
-
# Through a path as well, for the reason [method walk_to] gives. A step that is not there on
|
|
186
|
+
# Through a path as well, for the reason [method Paths.walk_to] gives. A step that is not there on
|
|
186
187
|
# this node reads as not having the property rather than as a refusal, which is the rule this
|
|
187
188
|
# whole function is written to: a find matches nodes of several classes on purpose.
|
|
188
|
-
var reached: Dictionary = walk_to(node, str(entry["path"]), wanted_property)
|
|
189
|
+
var reached: Dictionary = Paths.walk_to(node, str(entry["path"]), wanted_property)
|
|
189
190
|
if reached.has("message"):
|
|
190
191
|
entry["has_property"] = false
|
|
191
192
|
return entry
|
|
192
193
|
var holder: Variant = reached["holder"]
|
|
193
194
|
var named: String = reached["name"]
|
|
194
|
-
var has: bool =
|
|
195
|
+
var has: bool = Paths.can_read(holder, named)
|
|
195
196
|
entry["has_property"] = has
|
|
196
197
|
if has:
|
|
197
|
-
entry["value"] = _values.serialize(read_under(holder, named))
|
|
198
|
+
entry["value"] = _values.serialize(Paths.read_under(holder, named))
|
|
198
199
|
return entry
|
|
199
200
|
|
|
200
201
|
|
|
@@ -548,7 +549,7 @@ func get_property(params: Dictionary) -> Dictionary:
|
|
|
548
549
|
return standing
|
|
549
550
|
var node: Node = standing["node"]
|
|
550
551
|
|
|
551
|
-
var reached: Dictionary = walk_to(node, node_path, property)
|
|
552
|
+
var reached: Dictionary = Paths.walk_to(node, node_path, property)
|
|
552
553
|
if reached.has("message"):
|
|
553
554
|
return reached
|
|
554
555
|
|
|
@@ -556,213 +557,17 @@ func get_property(params: Dictionary) -> Dictionary:
|
|
|
556
557
|
var named: String = reached["name"]
|
|
557
558
|
# Asked of the holder rather than read and compared to null, because a property the holder does
|
|
558
559
|
# not have and a property that is null both read as null.
|
|
559
|
-
if not
|
|
560
|
-
return {"type": "error", "message":
|
|
560
|
+
if not Paths.can_read(holder, named):
|
|
561
|
+
return {"type": "error", "message": Paths.nothing_there(holder, named, str(reached["called"]))}
|
|
561
562
|
|
|
562
563
|
return {
|
|
563
564
|
"type": "property",
|
|
564
565
|
"path": node_path,
|
|
565
566
|
"property": property,
|
|
566
|
-
"value": _values.serialize(read_under(holder, named)),
|
|
567
|
+
"value": _values.serialize(Paths.read_under(holder, named)),
|
|
567
568
|
}
|
|
568
569
|
|
|
569
570
|
|
|
570
|
-
## What [param reaching] names something on, which is the node itself until the name has a colon
|
|
571
|
-
## in it, and the last name along that path.
|
|
572
|
-
##
|
|
573
|
-
## A game's state does not sit on nodes, it hangs off them: the speed of the clock is a property of
|
|
574
|
-
## a [RefCounted] held by a [RefCounted] held by the root, and that is what an agent asks about.
|
|
575
|
-
## What a game does hangs off them the same way, so the last name is a property to read, a property
|
|
576
|
-
## to write or a method to call, and the walk to it is one walk.
|
|
577
|
-
##
|
|
578
|
-
## Colons, because that is the separator [method Object.get_indexed] already takes. Walked a step
|
|
579
|
-
## at a time rather than handed to that method, which answers null for a path that goes wrong
|
|
580
|
-
## halfway along and for one that ends on null.
|
|
581
|
-
##
|
|
582
|
-
## A step written as a call, "get_viewport()", calls a method of that name that takes no arguments
|
|
583
|
-
## and walks into what it returned. Some of what hangs off a node is only reachable by asking:
|
|
584
|
-
## which control holds the focus is a question for the viewport a control is in, and the viewport
|
|
585
|
-
## is a method's answer rather than a property. Spelled with the brackets so a reader sees a call
|
|
586
|
-
## where one happens, and so a method can never shadow a property of the same name.
|
|
587
|
-
##
|
|
588
|
-
## Answers with a `message` instead when a step along the way is not there or holds something that
|
|
589
|
-
## is not an object, naming the step rather than the whole path: "/root/Main:_game has no property
|
|
590
|
-
## clocks" is a typo found, and "no property _game:clocks:speed" is a puzzle.
|
|
591
|
-
static func walk_to(node: Node, node_path: String, reaching: String) -> Dictionary:
|
|
592
|
-
var parts: PackedStringArray = reaching.split(":")
|
|
593
|
-
var holder: Variant = node
|
|
594
|
-
var called: String = node_path
|
|
595
|
-
for step: int in parts.size() - 1:
|
|
596
|
-
var named: String = parts[step]
|
|
597
|
-
if not _can_read(holder, named):
|
|
598
|
-
return {"type": "error", "message": _nothing_there(holder, named, called)}
|
|
599
|
-
holder = read_under(holder, named)
|
|
600
|
-
called = "%s:%s" % [called, named]
|
|
601
|
-
if not _can_hold(holder):
|
|
602
|
-
var wanted: String = parts[step + 1]
|
|
603
|
-
return {"type": "error", "message": "%s holds no object to read %s off" % [called, wanted]}
|
|
604
|
-
return {"holder": holder, "name": parts[parts.size() - 1], "called": called}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
## Whether a step can be taken into [param value] at all: an object, a list or a map can be walked
|
|
608
|
-
## into, and a number or a string is where a path ends whether the caller meant it to or not.
|
|
609
|
-
static func _can_hold(value: Variant) -> bool:
|
|
610
|
-
return value is Object or value is Array or value is Dictionary
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
## Whether [param named] is something [param holder] has.
|
|
614
|
-
##
|
|
615
|
-
## Three kinds of holder, because the state a game keeps is not all properties of objects: a roster
|
|
616
|
-
## is a list and an in-tray is a map, and a path that could not step into either stopped at the
|
|
617
|
-
## first one. An index reads the way a property does, and a negative one counts from the end the
|
|
618
|
-
## way GDScript's own does, so reading the last of something does not mean asking how many first.
|
|
619
|
-
## What is wrong with reading [param named] off [param holder], or "" when nothing is.
|
|
620
|
-
##
|
|
621
|
-
## Public because a wait asks the same question before it starts waiting, and used to answer it by
|
|
622
|
-
## waiting: a property nobody has spends the whole timeout and comes back "not met", which reads
|
|
623
|
-
## exactly like a game that never reached the state. The read refuses a mistyped name in one call
|
|
624
|
-
## and says so, and the two tools disagreeing about one typo is worth more than the duplication.
|
|
625
|
-
static func nothing_under(holder: Variant, named: String, called: String) -> String:
|
|
626
|
-
return "" if _can_read(holder, named) else _nothing_there(holder, named, called)
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
static func _can_read(holder: Variant, named: String) -> bool:
|
|
630
|
-
if holder is Array:
|
|
631
|
-
var items: Array = holder
|
|
632
|
-
return _index_in(named, items.size()) != -1
|
|
633
|
-
if holder is Dictionary:
|
|
634
|
-
var map: Dictionary = holder
|
|
635
|
-
return map.has(named) or map.has(StringName(named))
|
|
636
|
-
if holder is Object:
|
|
637
|
-
var object: Object = holder
|
|
638
|
-
var method: String = _called(named)
|
|
639
|
-
if not method.is_empty():
|
|
640
|
-
return _arguments_required(object, method) == 0
|
|
641
|
-
return _has_property(object, named)
|
|
642
|
-
return false
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
## The method a step written as a call names, "get_viewport()" being get_viewport, or "" for a
|
|
646
|
-
## step that is a name.
|
|
647
|
-
static func _called(named: String) -> String:
|
|
648
|
-
return named.trim_suffix("()") if named.ends_with("()") else ""
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
## How many arguments [param method] on [param object] has to be given, or -1 when there is no such
|
|
652
|
-
## method. Read off the method list rather than [method Object.has_method], because a path can only
|
|
653
|
-
## call a method with nothing, and a method with a required argument called with nothing raises
|
|
654
|
-
## inside the game rather than answering.
|
|
655
|
-
static func _arguments_required(object: Object, method: String) -> int:
|
|
656
|
-
for entry: Dictionary in object.get_method_list():
|
|
657
|
-
if str(entry.get("name", "")) != method:
|
|
658
|
-
continue
|
|
659
|
-
var params: Array = entry.get("args", [])
|
|
660
|
-
var defaults: Array = entry.get("default_args", [])
|
|
661
|
-
return params.size() - defaults.size()
|
|
662
|
-
return -1
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
## Put [param value] where [param named] points. Only ever called once [method _can_read] agrees,
|
|
666
|
-
## and lists and maps are reference types, so writing into one reaches the game's own copy.
|
|
667
|
-
static func _write(holder: Variant, named: String, value: Variant) -> void:
|
|
668
|
-
if holder is Array:
|
|
669
|
-
var items: Array = holder
|
|
670
|
-
items[_index_in(named, items.size())] = value
|
|
671
|
-
return
|
|
672
|
-
if holder is Dictionary:
|
|
673
|
-
var map: Dictionary = holder
|
|
674
|
-
# Written back under the key it was found under, since a map keyed by StringName and one
|
|
675
|
-
# keyed by String both read the same way and a write to the wrong one adds a second entry.
|
|
676
|
-
if map.has(named):
|
|
677
|
-
map[named] = value
|
|
678
|
-
else:
|
|
679
|
-
map[StringName(named)] = value
|
|
680
|
-
return
|
|
681
|
-
var object: Object = holder
|
|
682
|
-
object.set(named, value)
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
## What [param holder] holds under [param named], or answers to it when [param named] is a call.
|
|
686
|
-
## Only ever called once [method _can_read] agrees.
|
|
687
|
-
static func read_under(holder: Variant, named: String) -> Variant:
|
|
688
|
-
if holder is Array:
|
|
689
|
-
var items: Array = holder
|
|
690
|
-
return items[_index_in(named, items.size())]
|
|
691
|
-
if holder is Dictionary:
|
|
692
|
-
var map: Dictionary = holder
|
|
693
|
-
if map.has(named):
|
|
694
|
-
return map[named]
|
|
695
|
-
return map[StringName(named)]
|
|
696
|
-
var object: Object = holder
|
|
697
|
-
var method: String = _called(named)
|
|
698
|
-
if not method.is_empty():
|
|
699
|
-
return object.call(method)
|
|
700
|
-
return object.get(named)
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
## Where [param named] lands in a list of [param size], or -1 for a step that is not in it.
|
|
704
|
-
##
|
|
705
|
-
## -1 for "nowhere" is safe because every answer this gives is an index into a list that long, so a
|
|
706
|
-
## real one is never negative by the time it is returned.
|
|
707
|
-
static func _index_in(named: String, size: int) -> int:
|
|
708
|
-
if not named.is_valid_int():
|
|
709
|
-
return -1
|
|
710
|
-
var index: int = int(named)
|
|
711
|
-
if index < 0:
|
|
712
|
-
index += size
|
|
713
|
-
return index if index >= 0 and index < size else -1
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
## Why a step could not be taken, said in the terms of what was actually there.
|
|
717
|
-
##
|
|
718
|
-
## "has no property 0" about a list is a true sentence that sends somebody looking for a property,
|
|
719
|
-
## so a list says how long it is and a map says what it is keyed by. The step is named rather than
|
|
720
|
-
## the whole path, because the step is the typo.
|
|
721
|
-
static func _nothing_there(holder: Variant, named: String, called: String) -> String:
|
|
722
|
-
if holder is Array:
|
|
723
|
-
var items: Array = holder
|
|
724
|
-
return "%s is a list of %d, so there is no %s in it" % [called, items.size(), named]
|
|
725
|
-
if holder is Dictionary:
|
|
726
|
-
var map: Dictionary = holder
|
|
727
|
-
var keys: Array = map.keys()
|
|
728
|
-
# Eight of them, because a map keyed by something unexpected is told by the first few and a
|
|
729
|
-
# map of two hundred would bury the sentence saying which key was missing.
|
|
730
|
-
var some: Array[String] = []
|
|
731
|
-
for key: Variant in keys.slice(0, 8):
|
|
732
|
-
some.append(str(key))
|
|
733
|
-
var rest: String = ""
|
|
734
|
-
if keys.size() > 8:
|
|
735
|
-
rest = " and %d more" % [keys.size() - 8]
|
|
736
|
-
return "%s has no key %s; it is keyed by %s%s" % [called, named, ", ".join(some), rest]
|
|
737
|
-
var object: Object = holder
|
|
738
|
-
var method: String = _called(named)
|
|
739
|
-
if not method.is_empty():
|
|
740
|
-
var required: int = _arguments_required(object, method)
|
|
741
|
-
if required == -1:
|
|
742
|
-
return "%s has no method %s" % [called, method]
|
|
743
|
-
return (
|
|
744
|
-
"%s.%s takes %d argument%s, and a path can only call a method that takes none"
|
|
745
|
-
% [called, method, required, "" if required == 1 else "s"]
|
|
746
|
-
)
|
|
747
|
-
# A method spelled as a property is the likeliest thing behind a name the object has no property
|
|
748
|
-
# for, and the caller is one pair of brackets away from what they meant.
|
|
749
|
-
if object.has_method(named):
|
|
750
|
-
return (
|
|
751
|
-
"%s has no property %s; it has a method of that name, which a path calls as %s()"
|
|
752
|
-
% [called, named, named]
|
|
753
|
-
)
|
|
754
|
-
return "%s has no property %s" % [called, named]
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
## Whether [param holder] declares [param named]. Its own function because three ops ask it and a
|
|
758
|
-
## property read back as null answers it wrongly.
|
|
759
|
-
static func _has_property(holder: Object, named: String) -> bool:
|
|
760
|
-
for entry: Dictionary in holder.get_property_list():
|
|
761
|
-
if str(entry["name"]) == named:
|
|
762
|
-
return true
|
|
763
|
-
return false
|
|
764
|
-
|
|
765
|
-
|
|
766
571
|
func set_property(params: Dictionary) -> Dictionary:
|
|
767
572
|
var node_path: String = str(params.get("path", ""))
|
|
768
573
|
var property: String = str(params.get("property", ""))
|
|
@@ -776,10 +581,10 @@ func set_property(params: Dictionary) -> Dictionary:
|
|
|
776
581
|
return standing
|
|
777
582
|
var node: Node = standing["node"]
|
|
778
583
|
|
|
779
|
-
# Through a path as well, for the reason [method walk_to] gives, and read back off the same
|
|
584
|
+
# Through a path as well, for the reason [method Paths.walk_to] gives, and read back off the same
|
|
780
585
|
# holder afterwards: a set that does not take says so by answering with the old value, which is
|
|
781
586
|
# how a typed container refusing a write is told from one accepting it.
|
|
782
|
-
var reached: Dictionary = walk_to(node, node_path, property)
|
|
587
|
+
var reached: Dictionary = Paths.walk_to(node, node_path, property)
|
|
783
588
|
if reached.has("message"):
|
|
784
589
|
return reached
|
|
785
590
|
|
|
@@ -787,7 +592,7 @@ func set_property(params: Dictionary) -> Dictionary:
|
|
|
787
592
|
var named: String = reached["name"]
|
|
788
593
|
# A call can be walked through and read, and is not a place: what it returns is the method's
|
|
789
594
|
# to hand out, and writing "into" it would set nothing the game keeps.
|
|
790
|
-
if not
|
|
595
|
+
if not Paths.method_of(named).is_empty():
|
|
791
596
|
return {
|
|
792
597
|
"type": "error",
|
|
793
598
|
"message":
|
|
@@ -796,31 +601,42 @@ func set_property(params: Dictionary) -> Dictionary:
|
|
|
796
601
|
% [reached["called"], named]
|
|
797
602
|
)
|
|
798
603
|
}
|
|
799
|
-
if not
|
|
800
|
-
return {"type": "error", "message":
|
|
801
|
-
var old_value: Variant = read_under(holder, named)
|
|
604
|
+
if not Paths.can_read(holder, named):
|
|
605
|
+
return {"type": "error", "message": Paths.nothing_there(holder, named, str(reached["called"]))}
|
|
606
|
+
var old_value: Variant = Paths.read_under(holder, named)
|
|
802
607
|
# The same rule the call path holds: a value that cannot become what the property holds is
|
|
803
608
|
# refused rather than written. Writing it means the engine picks something, and what it picks
|
|
804
609
|
# for a word where a number goes is zero, which the answer then reports as the new value.
|
|
805
|
-
var
|
|
806
|
-
var
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
"
|
|
813
|
-
% [reached["called"], named,
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
610
|
+
var slot: Dictionary = Values.slot_declared(holder, named)
|
|
611
|
+
var wanted: int = slot["type"] if slot["type"] != TYPE_NIL else typeof(old_value)
|
|
612
|
+
var given: Variant
|
|
613
|
+
if wanted == TYPE_OBJECT and (value is String or value is Dictionary):
|
|
614
|
+
var named_object: Dictionary = _object_named(node, node_path, value, str(slot["class"]))
|
|
615
|
+
if named_object.has("message"):
|
|
616
|
+
return {
|
|
617
|
+
"type": "error",
|
|
618
|
+
"message": "%s.%s holds an object: %s" % [reached["called"], named, named_object["message"]]
|
|
619
|
+
}
|
|
620
|
+
given = named_object["object"]
|
|
621
|
+
else:
|
|
622
|
+
given = _values.fitted(value, wanted)
|
|
623
|
+
if not Values.acceptable(given, wanted):
|
|
624
|
+
return {
|
|
625
|
+
"type": "error",
|
|
626
|
+
"message":
|
|
627
|
+
(
|
|
628
|
+
"%s.%s holds %s and the value given is %s, which cannot become one."
|
|
629
|
+
% [reached["called"], named, type_string(wanted), type_string(typeof(given))]
|
|
630
|
+
)
|
|
631
|
+
}
|
|
632
|
+
Paths.write(holder, named, given)
|
|
817
633
|
|
|
818
634
|
return {
|
|
819
635
|
"type": "property_set",
|
|
820
636
|
"path": node_path,
|
|
821
637
|
"property": property,
|
|
822
638
|
"old_value": _values.serialize(old_value),
|
|
823
|
-
"new_value": _values.serialize(read_under(holder, named))
|
|
639
|
+
"new_value": _values.serialize(Paths.read_under(holder, named))
|
|
824
640
|
}
|
|
825
641
|
|
|
826
642
|
|
|
@@ -837,10 +653,10 @@ func call_method(params: Dictionary) -> Dictionary:
|
|
|
837
653
|
return standing
|
|
838
654
|
var node: Node = standing["node"]
|
|
839
655
|
|
|
840
|
-
# Through a path as well, for the reason [method walk_to] gives. What a game does hangs off its
|
|
656
|
+
# Through a path as well, for the reason [method Paths.walk_to] gives. What a game does hangs off its
|
|
841
657
|
# nodes as much as its state does, so reading `_game:run:day` while being unable to call
|
|
842
658
|
# `_game:run:advance` answers half of what a node holds and refuses the other half.
|
|
843
|
-
var reached: Dictionary = walk_to(node, node_path, method)
|
|
659
|
+
var reached: Dictionary = Paths.walk_to(node, node_path, method)
|
|
844
660
|
if reached.has("message"):
|
|
845
661
|
return reached
|
|
846
662
|
|
|
@@ -862,8 +678,8 @@ func call_method(params: Dictionary) -> Dictionary:
|
|
|
862
678
|
# The method a call ends on is the one being called whether or not it carries the brackets a
|
|
863
679
|
# step along the way would: "get_viewport():gui_get_focus_owner()" is the same call as without
|
|
864
680
|
# the last pair.
|
|
865
|
-
if not
|
|
866
|
-
named =
|
|
681
|
+
if not Paths.method_of(named).is_empty():
|
|
682
|
+
named = Paths.method_of(named)
|
|
867
683
|
if not holder.has_method(named):
|
|
868
684
|
return {"type": "error", "message": "%s has no method %s" % [reached["called"], named]}
|
|
869
685
|
|
|
@@ -874,6 +690,17 @@ func call_method(params: Dictionary) -> Dictionary:
|
|
|
874
690
|
var deserialized_args: Array = []
|
|
875
691
|
for index: int in args.size():
|
|
876
692
|
var wants: int = _values.parameter_type(holder, named, index)
|
|
693
|
+
if wants == TYPE_OBJECT and (args[index] is String or args[index] is Dictionary):
|
|
694
|
+
var declared: String = _values.parameter_class(holder, named, index)
|
|
695
|
+
var named_object: Dictionary = _object_named(node, node_path, args[index], declared)
|
|
696
|
+
if named_object.has("message"):
|
|
697
|
+
return {
|
|
698
|
+
"type": "error",
|
|
699
|
+
"message":
|
|
700
|
+
"%s.%s argument %d: %s" % [reached["called"], named, index + 1, named_object["message"]]
|
|
701
|
+
}
|
|
702
|
+
deserialized_args.append(named_object["object"])
|
|
703
|
+
continue
|
|
877
704
|
var given: Variant = _values.fitted(args[index], wants)
|
|
878
705
|
if not Values.acceptable(given, wants):
|
|
879
706
|
return {
|
|
@@ -891,6 +718,23 @@ func call_method(params: Dictionary) -> Dictionary:
|
|
|
891
718
|
return {"type": "method_result", "path": node_path, "method": method, "result": _values.serialize(result)}
|
|
892
719
|
|
|
893
720
|
|
|
721
|
+
## The object [param given] names for a slot or a parameter declared as [param declared], as
|
|
722
|
+
## `{"object": ...}`, or `{"message": ...}` saying why it names none that fits.
|
|
723
|
+
##
|
|
724
|
+
## JSON cannot carry an object, so one the game holds is named by its path, read from the node the
|
|
725
|
+
## call or the write was made on, and handed over as that instance rather than a copy: a method
|
|
726
|
+
## given a piece of the game's state acts on the piece the game keeps, and a slot written with one
|
|
727
|
+
## holds the game's own.
|
|
728
|
+
func _object_named(node: Node, node_path: String, given: Variant, declared: String) -> Dictionary:
|
|
729
|
+
var found: Dictionary = Paths.object_at(_host.get_tree().root, node, node_path, given)
|
|
730
|
+
if found.has("message"):
|
|
731
|
+
return found
|
|
732
|
+
var instance: Object = found["object"]
|
|
733
|
+
if not declared.is_empty() and not Values.is_a(instance, declared):
|
|
734
|
+
return {"message": "%s is %s, not a %s" % [str(given), Values.class_of(instance), declared]}
|
|
735
|
+
return found
|
|
736
|
+
|
|
737
|
+
|
|
894
738
|
func get_metrics(params: Dictionary) -> Dictionary:
|
|
895
739
|
var metrics: Array = params.get("metrics", [])
|
|
896
740
|
var all: Dictionary = {
|
|
@@ -954,13 +798,13 @@ func _serialize_node_tree(
|
|
|
954
798
|
func _named_properties_of(node: Node, path: String, named: Array[String]) -> Dictionary:
|
|
955
799
|
var properties: Dictionary = {}
|
|
956
800
|
for wanted: String in named:
|
|
957
|
-
var reached: Dictionary = walk_to(node, path, wanted)
|
|
801
|
+
var reached: Dictionary = Paths.walk_to(node, path, wanted)
|
|
958
802
|
if reached.has("message"):
|
|
959
803
|
continue
|
|
960
804
|
var holder: Variant = reached["holder"]
|
|
961
805
|
var name: String = reached["name"]
|
|
962
|
-
if
|
|
963
|
-
properties[wanted] = _values.serialize(read_under(holder, name))
|
|
806
|
+
if Paths.can_read(holder, name):
|
|
807
|
+
properties[wanted] = _values.serialize(Paths.read_under(holder, name))
|
|
964
808
|
return properties
|
|
965
809
|
|
|
966
810
|
|
|
@@ -79,6 +79,87 @@ func parameter_type(object: Object, method: String, index: int) -> int:
|
|
|
79
79
|
return TYPE_NIL
|
|
80
80
|
|
|
81
81
|
|
|
82
|
+
## The class a method declares for argument [param index], or "" when it names none: an untyped
|
|
83
|
+
## parameter, a Variant, or a type that is not an object.
|
|
84
|
+
func parameter_class(object: Object, method: String, index: int) -> String:
|
|
85
|
+
for entry: Dictionary in object.get_method_list():
|
|
86
|
+
if entry.get("name", "") != method:
|
|
87
|
+
continue
|
|
88
|
+
var params: Array = entry.get("args", [])
|
|
89
|
+
if index < 0 or index >= params.size():
|
|
90
|
+
return ""
|
|
91
|
+
var parameter: Dictionary = params[index]
|
|
92
|
+
return str(parameter.get("class_name", ""))
|
|
93
|
+
return ""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
## What the slot [param named] on [param holder] declares it holds, as `{"type": int, "class":
|
|
97
|
+
## String}`: a property's declaration, or the element type of a typed list or the value type of a
|
|
98
|
+
## typed map. TYPE_NIL when nothing is declared.
|
|
99
|
+
##
|
|
100
|
+
## Asked rather than read off the value in the slot, because an object slot can be empty: a
|
|
101
|
+
## property typed `Gear` holding null reads as TYPE_NIL, and anything written into it passed the
|
|
102
|
+
## check and was then dropped by the engine, which answered with the slot still null.
|
|
103
|
+
static func slot_declared(holder: Variant, named: String) -> Dictionary:
|
|
104
|
+
if holder is Array:
|
|
105
|
+
var items: Array = holder
|
|
106
|
+
if items.is_typed():
|
|
107
|
+
return {
|
|
108
|
+
"type": items.get_typed_builtin(),
|
|
109
|
+
"class": _typed_class(items.get_typed_script(), items.get_typed_class_name()),
|
|
110
|
+
}
|
|
111
|
+
elif holder is Dictionary:
|
|
112
|
+
var map: Dictionary = holder
|
|
113
|
+
if map.is_typed_value():
|
|
114
|
+
return {
|
|
115
|
+
"type": map.get_typed_value_builtin(),
|
|
116
|
+
"class": _typed_class(map.get_typed_value_script(), map.get_typed_value_class_name()),
|
|
117
|
+
}
|
|
118
|
+
elif holder is Object:
|
|
119
|
+
var object: Object = holder
|
|
120
|
+
for entry: Dictionary in object.get_property_list():
|
|
121
|
+
if str(entry.get("name", "")) == named:
|
|
122
|
+
return {
|
|
123
|
+
"type": Read.as_int(entry.get("type", TYPE_NIL), TYPE_NIL),
|
|
124
|
+
"class": str(entry.get("class_name", "")),
|
|
125
|
+
}
|
|
126
|
+
return {"type": TYPE_NIL, "class": ""}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
## The class a typed container names: its script's global name where it has one, since the engine
|
|
130
|
+
## class of a script class is only what the script extends.
|
|
131
|
+
static func _typed_class(script: Variant, engine_class: StringName) -> String:
|
|
132
|
+
if script is Script:
|
|
133
|
+
var typed: Script = script
|
|
134
|
+
if not typed.get_global_name().is_empty():
|
|
135
|
+
return str(typed.get_global_name())
|
|
136
|
+
return str(engine_class)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
## Whether [param object] is a [param declared]: an engine class, or a script class by its global
|
|
140
|
+
## name anywhere along the script's inheritance.
|
|
141
|
+
static func is_a(object: Object, declared: String) -> bool:
|
|
142
|
+
if object.is_class(declared):
|
|
143
|
+
return true
|
|
144
|
+
var script: Variant = object.get_script()
|
|
145
|
+
while script is Script:
|
|
146
|
+
var current: Script = script
|
|
147
|
+
if current.get_global_name() == StringName(declared):
|
|
148
|
+
return true
|
|
149
|
+
script = current.get_base_script()
|
|
150
|
+
return false
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
## What [param object] is, by its script class where it has one.
|
|
154
|
+
static func class_of(object: Object) -> String:
|
|
155
|
+
var script: Variant = object.get_script()
|
|
156
|
+
if script is Script:
|
|
157
|
+
var current: Script = script
|
|
158
|
+
if not current.get_global_name().is_empty():
|
|
159
|
+
return str(current.get_global_name())
|
|
160
|
+
return object.get_class()
|
|
161
|
+
|
|
162
|
+
|
|
82
163
|
## A value from the wire fitted to the type a property or parameter declares.
|
|
83
164
|
func fitted(value: Variant, type: int) -> Variant:
|
|
84
165
|
return _shared.fitted(value, type)
|
|
@@ -3,6 +3,7 @@ extends RefCounted
|
|
|
3
3
|
## The commands that take time: they let the game run and answer when what was waited for has
|
|
4
4
|
## happened, or when the time ran out, so the caller never sleeps for a guessed length.
|
|
5
5
|
|
|
6
|
+
const Paths = preload("runtime_paths.gd")
|
|
6
7
|
const Queries = preload("runtime_queries.gd")
|
|
7
8
|
const Read = preload("reading.gd")
|
|
8
9
|
const Values = preload("runtime_values.gd")
|
|
@@ -207,15 +208,15 @@ static func _not_comparable(current: Variant, wanted: Variant, node_path: String
|
|
|
207
208
|
## its nodes hold: a run object built afresh each day would leave a wait watching the day before. A
|
|
208
209
|
## step that has gone in the meantime ends the wait with what went.
|
|
209
210
|
static func _watched(node: Node, node_path: String, property: String) -> Dictionary:
|
|
210
|
-
var reached: Dictionary =
|
|
211
|
+
var reached: Dictionary = Paths.walk_to(node, node_path, property)
|
|
211
212
|
if reached.has("message"):
|
|
212
213
|
return reached
|
|
213
214
|
var holder: Variant = reached["holder"]
|
|
214
215
|
var named: String = reached["name"]
|
|
215
|
-
var missing: String =
|
|
216
|
+
var missing: String = Paths.nothing_under(holder, named, str(reached["called"]))
|
|
216
217
|
if not missing.is_empty():
|
|
217
218
|
return {"type": "error", "message": missing}
|
|
218
|
-
return {"value":
|
|
219
|
+
return {"value": Paths.read_under(holder, named)}
|
|
219
220
|
|
|
220
221
|
|
|
221
222
|
## Waits until something under [param node_path] has [param said] written on it.
|
package/build/index.js
CHANGED
|
@@ -30280,7 +30280,7 @@ var TOOL_SPECS = [
|
|
|
30280
30280
|
},
|
|
30281
30281
|
{
|
|
30282
30282
|
name: "editor_status",
|
|
30283
|
-
description: "Whether the editor addon is connected, which Godot answers, whether the editor is playing something, and whether a game with the runtime addon is reachable. playingInEditor is null when the editor was not asked or did not answer, which is not the same as a no: with no editor connected there is nobody to ask, and an editor that does not serve the question is given a moment and then left. A game can be playing while this is null, so read it as unanswered rather than as nothing playing, and use processActive and runtimes, which come from elsewhere and do not depend on the editor answering. Each game under runtimes is pinged with a short wait, so one held at a breakpoint is listed as unreachable rather than making this call wait out the runtime timeout; for the run this server is reporting on, heldAt says whether that is what it is, with the same three answers editor_output gives. A game the editor played announces the editor under editorPid, and so does whatever that game started for itself; a game some other server started announces none, which is how the two are told apart when both are running from one project. When connected is false, mayYetConnect says whether that is final: the editor dials this server rather than the other way round and backs off between tries, so for the first half-minute after a server starts, false means \"not reached yet\" as often as it means \"no editor\". True is worth waiting out; false is an editor that is not there. False beside restartInterrupted is one that an editor_launch restart on a previous server asked to quit, where the launch half never ran because that server was ended in between, usually by the reconnect the restart was taken for; editor_launch open finishes it. listeningSince is when this server took the bridge port, which is what that window is measured from and what a caller wanting its own window should read. An editor this server opened counts for as long as its process lives, however far past that window the import runs, and awaitingLaunchedEditor names its pid so the two reasons for true are told apart. settingsDropped appears here once when the editor this server opened saved project.godot on its way in, which is the same reading editor_launch restart makes in its own answer. A game that has announced itself in a protocol this server does not speak is listed under unreadable rather than left out, with the protocol it speaks and whether the server or the addon is the older half. This happens during an upgrade that moves the runtime protocol, which most do not: installing replaces the addon on disk as soon as the pin moves, while a server that is already running stays on the version it started with, so the two speak different protocols until the server is reconnected. Those games are real and running, but no tool here can reach them until the halves match, so runtimes stays empty and runtimeConnected stays false. An upgrade that leaves the protocol alone opens no such window and this list stays empty through it.",
|
|
30283
|
+
description: "Whether the editor addon is connected, which Godot answers, whether the editor is playing something, and whether a game with the runtime addon is reachable: runtimeConnected counts the games of the project this server serves, and runtimes lists every game on the machine with ofThisProject saying which is which, since a game of another project is reached only by naming its projectPath. playingInEditor is null when the editor was not asked or did not answer, which is not the same as a no: with no editor connected there is nobody to ask, and an editor that does not serve the question is given a moment and then left. A game can be playing while this is null, so read it as unanswered rather than as nothing playing, and use processActive and runtimes, which come from elsewhere and do not depend on the editor answering. Each game under runtimes is pinged with a short wait, so one held at a breakpoint is listed as unreachable rather than making this call wait out the runtime timeout; for the run this server is reporting on, heldAt says whether that is what it is, with the same three answers editor_output gives. A game the editor played announces the editor under editorPid, and so does whatever that game started for itself; a game some other server started announces none, which is how the two are told apart when both are running from one project. When connected is false, mayYetConnect says whether that is final: the editor dials this server rather than the other way round and backs off between tries, so for the first half-minute after a server starts, false means \"not reached yet\" as often as it means \"no editor\". True is worth waiting out; false is an editor that is not there. False beside restartInterrupted is one that an editor_launch restart on a previous server asked to quit, where the launch half never ran because that server was ended in between, usually by the reconnect the restart was taken for; editor_launch open finishes it. listeningSince is when this server took the bridge port, which is what that window is measured from and what a caller wanting its own window should read. An editor this server opened counts for as long as its process lives, however far past that window the import runs, and awaitingLaunchedEditor names its pid so the two reasons for true are told apart. settingsDropped appears here once when the editor this server opened saved project.godot on its way in, which is the same reading editor_launch restart makes in its own answer. A game that has announced itself in a protocol this server does not speak is listed under unreadable rather than left out, with the protocol it speaks and whether the server or the addon is the older half. This happens during an upgrade that moves the runtime protocol, which most do not: installing replaces the addon on disk as soon as the pin moves, while a server that is already running stays on the version it started with, so the two speak different protocols until the server is reconnected. Those games are real and running, but no tool here can reach them until the halves match, so runtimes stays empty and runtimeConnected stays false. An upgrade that leaves the protocol alone opens no such window and this list stays empty through it.",
|
|
30284
30284
|
parameters: {},
|
|
30285
30285
|
requires: []
|
|
30286
30286
|
},
|
|
@@ -30440,7 +30440,7 @@ var TOOL_SPECS = [
|
|
|
30440
30440
|
value: {
|
|
30441
30441
|
ops: ["set"],
|
|
30442
30442
|
blank: true,
|
|
30443
|
-
description: `set: the value, fitted to the property's type. "" writes an empty string.`
|
|
30443
|
+
description: `set: the value, fitted to the property's type. "" writes an empty string. A property typed as or holding an object takes a path naming one the game holds, the way call's args do, and holds that instance.`
|
|
30444
30444
|
},
|
|
30445
30445
|
method: {
|
|
30446
30446
|
type: "string",
|
|
@@ -30450,7 +30450,7 @@ var TOOL_SPECS = [
|
|
|
30450
30450
|
args: {
|
|
30451
30451
|
type: "array",
|
|
30452
30452
|
ops: ["call"],
|
|
30453
|
-
description:
|
|
30453
|
+
description: `call: the arguments, fitted to the method's parameter types. A parameter typed as an object takes a path naming one the game holds and is handed that instance: a colon path read from nodePath, "_game:run:wares:3", or one starting at a node, "/root/Main/Hud" or "/root/Main:_game:run". A path that reaches no object, or an object of another class than the parameter declares, is refused.`
|
|
30454
30454
|
}
|
|
30455
30455
|
},
|
|
30456
30456
|
requires: ["nodePath"],
|
|
@@ -30818,6 +30818,19 @@ function runIsUp(run, editorSays, now = Date.now()) {
|
|
|
30818
30818
|
}
|
|
30819
30819
|
return editorSays ?? stillRunning(run);
|
|
30820
30820
|
}
|
|
30821
|
+
function noCodeWillCome(run) {
|
|
30822
|
+
return run.exitCode === null && run.process === null;
|
|
30823
|
+
}
|
|
30824
|
+
function endedWithoutACode(run) {
|
|
30825
|
+
if (!run.throughEditor) {
|
|
30826
|
+
return "This run was started by another server, the one this server replaced or one running beside it, and it ended with nothing here waiting on it, so its exit code was never collected. Everything it printed is below, read back from its transcript.";
|
|
30827
|
+
}
|
|
30828
|
+
const kept = "A game the editor plays is the editor's own child, so its exit code stays with the editor and none was collected here.";
|
|
30829
|
+
if (!run.announced && run.couldAnnounce) {
|
|
30830
|
+
return `The editor stopped playing this run before its game announced a runtime, so the game ended while it was starting or was closed in the editor. ${kept} What it printed is below, and editor_output with op "editor" has what the editor said about it.`;
|
|
30831
|
+
}
|
|
30832
|
+
return `The editor stopped playing this run. ${kept} What it printed is below.`;
|
|
30833
|
+
}
|
|
30821
30834
|
function endedPreviousRun(ended) {
|
|
30822
30835
|
if (ended === null) {
|
|
30823
30836
|
return;
|
|
@@ -32604,6 +32617,7 @@ class GodotServer {
|
|
|
32604
32617
|
pid: endpoint.pid,
|
|
32605
32618
|
port: endpoint.port,
|
|
32606
32619
|
project: endpoint.project,
|
|
32620
|
+
...this.ownProject === null ? {} : { ofThisProject: isSameDirectory(endpoint.project.path, this.ownProject) },
|
|
32607
32621
|
editorPid: endpoint.editorPid,
|
|
32608
32622
|
reachable: reply.ok,
|
|
32609
32623
|
problem: reply.ok ? null : reply.message
|
|
@@ -32635,7 +32649,7 @@ class GodotServer {
|
|
|
32635
32649
|
processActive: active,
|
|
32636
32650
|
playingInEditor: playing,
|
|
32637
32651
|
...hold,
|
|
32638
|
-
runtimeConnected: games.some((game) => game.reachable),
|
|
32652
|
+
runtimeConnected: games.some((game) => game.reachable && game.ofThisProject !== false),
|
|
32639
32653
|
runtimes: games,
|
|
32640
32654
|
unreadable: announced.unspoken.map((game) => ({
|
|
32641
32655
|
pid: game.pid,
|
|
@@ -33560,7 +33574,8 @@ class GodotServer {
|
|
|
33560
33574
|
}
|
|
33561
33575
|
const budgetMs = readPositiveNumber(args, "timeoutMs") ?? WAIT_FOR_RUN_MS;
|
|
33562
33576
|
const until = Date.now() + budgetMs;
|
|
33563
|
-
|
|
33577
|
+
const cancelled = callSignal();
|
|
33578
|
+
while (cancelled?.aborted !== true && await this.runStillGoing(run) && Date.now() < until) {
|
|
33564
33579
|
this.drainEditorOutput(run);
|
|
33565
33580
|
this.drainTranscript(run);
|
|
33566
33581
|
await delay3(RUN_POLL_MS);
|
|
@@ -33654,7 +33669,7 @@ class GodotServer {
|
|
|
33654
33669
|
const going = await this.runStillGoing(run);
|
|
33655
33670
|
if (run.endedUnwatched !== true && !going) {
|
|
33656
33671
|
run.log.finish();
|
|
33657
|
-
run.endedUnwatched = run
|
|
33672
|
+
run.endedUnwatched = noCodeWillCome(run);
|
|
33658
33673
|
}
|
|
33659
33674
|
const severity = readString(args, "severity");
|
|
33660
33675
|
const selected = run.log.select({
|
|
@@ -33676,7 +33691,11 @@ class GodotServer {
|
|
|
33676
33691
|
notes.push(`The wait of ${waitedMs}ms ran out and the run is still going, so this is what it had printed by then rather than everything it will print. editor_run wait again to keep waiting.`);
|
|
33677
33692
|
}
|
|
33678
33693
|
if (run.endedUnwatched === true) {
|
|
33679
|
-
notes.push(
|
|
33694
|
+
notes.push(endedWithoutACode({
|
|
33695
|
+
throughEditor: run.throughEditor,
|
|
33696
|
+
announced: announced !== undefined || run.announcedPid !== undefined,
|
|
33697
|
+
couldAnnounce: run.projectPath !== null && existsSync10(join16(run.projectPath, RUNTIME_AUTOLOAD.path))
|
|
33698
|
+
}));
|
|
33680
33699
|
}
|
|
33681
33700
|
if (run.pickedUpPlaying === true) {
|
|
33682
33701
|
notes.push(run.transcript === null ? "The editor was already playing this when this server reached it, and the server that started it left no transcript, so this is not the run from its start: what it printed before that is only in the editor. It is the run the editor is holding now, which is the one the debug_* tools answer for." : "The editor was already playing this when this server reached it, and what it printed before that has been read back from its transcript. It is the run the editor is holding now, which is the one the debug_* tools answer for.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gdharness",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"mcpName": "io.github.Aureliolo/gdharness",
|
|
5
5
|
"description": "A harness for driving a Godot 4 project from an agent: editor addons, a runtime bridge into the running game, an MCP server in front of them, and a CLI that installs and diagnoses the Godot side.",
|
|
6
6
|
"type": "module",
|