gdharness 1.2.24 → 1.2.26
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 +508 -174
- package/build/godot/addons/gdharness_editor/serialisation.gd +29 -0
- package/build/godot/addons/gdharness_runtime/runtime_accessibility.gd +290 -0
- package/build/godot/addons/gdharness_runtime/runtime_accessibility.gd.uid +1 -0
- package/build/godot/addons/gdharness_runtime/runtime_autoload.gd +7 -0
- package/build/godot/addons/gdharness_runtime/runtime_changes.gd +24 -4
- package/build/godot/addons/gdharness_runtime/runtime_pad.gd +150 -0
- package/build/godot/addons/gdharness_runtime/runtime_pad.gd.uid +1 -0
- package/build/godot/addons/gdharness_runtime/runtime_queries.gd +5 -0
- package/build/godot/addons/gdharness_runtime/runtime_values.gd +5 -0
- package/build/godot/addons/gdharness_runtime/serialisation.gd +29 -0
- package/build/godot/operations/godot_operations.gd +7 -0
- package/build/godot/operations/import_pipeline.gd +92 -0
- package/build/godot/operations/input_actions.gd +3 -2
- package/build/godot/operations/plugins.gd +3 -2
- package/build/godot/operations/project_config.gd +17 -9
- package/build/godot/operations/project_file.gd +202 -0
- package/build/godot/operations/serialisation.gd +29 -0
- package/build/index.js +520 -190
- package/build/keeper.js +16 -9
- package/package.json +1 -1
|
@@ -46,6 +46,9 @@ const IMPORTER_VERSIONS: Dictionary[String, int] = {"scene": 1, "animation_libra
|
|
|
46
46
|
## The VRAM compression formats a project can ask for, each behind its
|
|
47
47
|
## `rendering/textures/vram_compression/import_<format>` setting.
|
|
48
48
|
const VRAM_FORMATS: Array[String] = ["s3tc_bptc", "etc2_astc"]
|
|
49
|
+
## Options keyed by OpenType tags, by the importer that holds them. The engine keys them by the tag as
|
|
50
|
+
## an int, which a caller can also name, as "liga" for ligatures.
|
|
51
|
+
const OPENTYPE_OPTIONS: Dictionary[String, Array] = {"font_data_dynamic": ["opentype_features"]}
|
|
49
52
|
const EDITOR_DIRECTORY: String = "res://.godot/editor"
|
|
50
53
|
const EDITOR_CACHE_PREFIX: String = "filesystem_cache"
|
|
51
54
|
|
|
@@ -177,6 +180,7 @@ func set_import_options(params: Dictionary) -> Dictionary:
|
|
|
177
180
|
return _log.failure("Failed to parse import file: " + str(err))
|
|
178
181
|
|
|
179
182
|
# Every option checked before any is written, so a refused one leaves the sidecar as it was.
|
|
183
|
+
var importer: String = str(config.get_value("remap", "importer", ""))
|
|
180
184
|
var fitted_values: Dictionary = {}
|
|
181
185
|
var refused: Array[String] = []
|
|
182
186
|
for key: Variant in options:
|
|
@@ -184,6 +188,13 @@ func set_import_options(params: Dictionary) -> Dictionary:
|
|
|
184
188
|
var held: Variant = config.get_value("params", name, null)
|
|
185
189
|
var given: Variant = _values.deserialize_value(options[key])
|
|
186
190
|
var value: Variant = _as_option(_values.fitted(options[key], typeof(held)), held)
|
|
191
|
+
if value is Dictionary:
|
|
192
|
+
var entries: Dictionary = value
|
|
193
|
+
var keyed: Dictionary = _keyed_as_option(name, entries, held, importer)
|
|
194
|
+
if keyed.has("refused"):
|
|
195
|
+
refused.append(str(keyed["refused"]))
|
|
196
|
+
continue
|
|
197
|
+
value = keyed["value"]
|
|
187
198
|
# A number the option cannot hold whole is refused rather than truncated: 2.5 fitted to an
|
|
188
199
|
# enum option became 2, which is another setting.
|
|
189
200
|
var lossy: bool = (
|
|
@@ -227,6 +238,87 @@ static func _as_option(given: Variant, held: Variant) -> Variant:
|
|
|
227
238
|
return given
|
|
228
239
|
|
|
229
240
|
|
|
241
|
+
## [param given] with the keys and values a dictionary option holds as ints made ints again.
|
|
242
|
+
##
|
|
243
|
+
## JSON names every key as a string and every number as a float, so a font's opentype_features was
|
|
244
|
+
## written as {"1818847073": 0.0}. The importer hands that to FontFile.opentype_feature_overrides,
|
|
245
|
+
## which keys features by their tag as an int, so the call reported success and the font kept its
|
|
246
|
+
## ligatures. A key is an int where the importer keys the option by OpenType tags, or where every key
|
|
247
|
+
## the option holds already is one; a value is an int where every value held is, or for a tag.
|
|
248
|
+
## Answers the dictionary under value, or why it cannot be written under refused.
|
|
249
|
+
static func _keyed_as_option(name: String, given: Dictionary, held: Variant, importer: String) -> Dictionary:
|
|
250
|
+
var tag_options: Array = OPENTYPE_OPTIONS.get(importer, [])
|
|
251
|
+
var tagged: bool = name in tag_options
|
|
252
|
+
var numbered_keys: bool = tagged or _all_ints(held, true)
|
|
253
|
+
var whole_values: bool = tagged or _all_ints(held, false)
|
|
254
|
+
if not numbered_keys and not whole_values:
|
|
255
|
+
return {"value": given}
|
|
256
|
+
var keyed: Dictionary = {}
|
|
257
|
+
for key: Variant in given:
|
|
258
|
+
var as_key: Variant = key
|
|
259
|
+
if numbered_keys:
|
|
260
|
+
as_key = _int_key(key, tagged)
|
|
261
|
+
if as_key == null:
|
|
262
|
+
var wanted: String = (
|
|
263
|
+
'OpenType tags, by name such as "liga" or as the number TextServer.name_to_tag gives'
|
|
264
|
+
if tagged
|
|
265
|
+
else "ints"
|
|
266
|
+
)
|
|
267
|
+
return {
|
|
268
|
+
"refused": "%s is keyed by %s, and %s is not one" % [name, wanted, JSON.stringify(key)]
|
|
269
|
+
}
|
|
270
|
+
var value: Variant = given[key]
|
|
271
|
+
if whole_values and value is float:
|
|
272
|
+
var number: float = value
|
|
273
|
+
if number == floorf(number):
|
|
274
|
+
value = int(number)
|
|
275
|
+
keyed[as_key] = value
|
|
276
|
+
return {"value": keyed}
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
## [param key] as an int key, or null when it is not one: a whole number, written as a number or as
|
|
280
|
+
## a string of digits, or where [param tagged], an OpenType tag's four characters.
|
|
281
|
+
static func _int_key(key: Variant, tagged: bool) -> Variant:
|
|
282
|
+
if key is int:
|
|
283
|
+
return key
|
|
284
|
+
if key is float:
|
|
285
|
+
var number: float = key
|
|
286
|
+
if number != floorf(number):
|
|
287
|
+
return null
|
|
288
|
+
return int(number)
|
|
289
|
+
if not key is String:
|
|
290
|
+
return null
|
|
291
|
+
var text: String = key
|
|
292
|
+
if text.is_valid_int():
|
|
293
|
+
return text.to_int()
|
|
294
|
+
# Exactly four printable characters, since the engine reads a longer name by its first four and
|
|
295
|
+
# "ligatures" would quietly become "liga".
|
|
296
|
+
if tagged and text.length() == 4 and _printable(text):
|
|
297
|
+
return TextServerManager.get_primary_interface().name_to_tag(text)
|
|
298
|
+
return null
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
static func _printable(text: String) -> bool:
|
|
302
|
+
for i: int in text.length():
|
|
303
|
+
var code: int = text.unicode_at(i)
|
|
304
|
+
if code < 0x20 or code > 0x7e:
|
|
305
|
+
return false
|
|
306
|
+
return true
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
## Whether [param held] is a dictionary that is not empty and whose keys, or values, are all ints.
|
|
310
|
+
static func _all_ints(held: Variant, keys: bool) -> bool:
|
|
311
|
+
if not held is Dictionary:
|
|
312
|
+
return false
|
|
313
|
+
var dictionary: Dictionary = held
|
|
314
|
+
if dictionary.is_empty():
|
|
315
|
+
return false
|
|
316
|
+
for item: Variant in dictionary.keys() if keys else dictionary.values():
|
|
317
|
+
if not item is int:
|
|
318
|
+
return false
|
|
319
|
+
return true
|
|
320
|
+
|
|
321
|
+
|
|
230
322
|
# The names of the project's export presets, in the order export_presets.cfg holds them.
|
|
231
323
|
static func _preset_names() -> Array[String]:
|
|
232
324
|
var names: Array[String] = []
|
|
@@ -2,6 +2,7 @@ extends RefCounted
|
|
|
2
2
|
|
|
3
3
|
const Read = preload("reading.gd")
|
|
4
4
|
const Log = preload("logger.gd")
|
|
5
|
+
const ProjectFile = preload("project_file.gd")
|
|
5
6
|
|
|
6
7
|
# The key names a caller may write, and what the engine calls them.
|
|
7
8
|
const KEY_NAMES: Dictionary = {
|
|
@@ -172,7 +173,7 @@ func add_input_action(params: Dictionary) -> Dictionary:
|
|
|
172
173
|
# Through ProjectSettings so the file is saved the way the editor saves it, header and
|
|
173
174
|
# every other line kept; a ConfigFile of project.godot drops the comments on the way out.
|
|
174
175
|
ProjectSettings.set_setting("input/" + action_name, action)
|
|
175
|
-
var err: Error =
|
|
176
|
+
var err: Error = ProjectFile.save()
|
|
176
177
|
if err != OK:
|
|
177
178
|
return _log.failure("Failed to save project.godot: " + error_string(err))
|
|
178
179
|
|
|
@@ -205,7 +206,7 @@ func remove_input_action(params: Dictionary) -> Dictionary:
|
|
|
205
206
|
)
|
|
206
207
|
)
|
|
207
208
|
ProjectSettings.set_setting(setting, null)
|
|
208
|
-
var err: Error =
|
|
209
|
+
var err: Error = ProjectFile.save()
|
|
209
210
|
if err != OK:
|
|
210
211
|
return _log.failure("Failed to save project.godot: " + error_string(err))
|
|
211
212
|
return {"action_name": action_name, "removed": true}
|
|
@@ -2,6 +2,7 @@ extends RefCounted
|
|
|
2
2
|
|
|
3
3
|
const Patterns = preload("patterns.gd")
|
|
4
4
|
const Log = preload("logger.gd")
|
|
5
|
+
const ProjectFile = preload("project_file.gd")
|
|
5
6
|
|
|
6
7
|
var _log: Log
|
|
7
8
|
|
|
@@ -171,11 +172,11 @@ static func _names_of(paths: Array[String]) -> Array[String]:
|
|
|
171
172
|
func _save_enabled_paths(paths: Array[String]) -> Error:
|
|
172
173
|
if paths.is_empty():
|
|
173
174
|
ProjectSettings.set_setting("editor_plugins/enabled", null)
|
|
174
|
-
return
|
|
175
|
+
return ProjectFile.save()
|
|
175
176
|
|
|
176
177
|
# Kept in an Array[String] and converted here, because appending to a packed array answers with
|
|
177
178
|
# whether it worked and a project holding return_value_discarded at error level will not compile
|
|
178
179
|
# a script that drops that answer. The conversion is what matters: an Array[String] handed to
|
|
179
180
|
# set_setting is written as Array[String]([...]), which the editor does not read as a plugin list.
|
|
180
181
|
ProjectSettings.set_setting("editor_plugins/enabled", PackedStringArray(paths))
|
|
181
|
-
return
|
|
182
|
+
return ProjectFile.save()
|
|
@@ -2,6 +2,7 @@ extends RefCounted
|
|
|
2
2
|
|
|
3
3
|
const Read = preload("reading.gd")
|
|
4
4
|
const Log = preload("logger.gd")
|
|
5
|
+
const ProjectFile = preload("project_file.gd")
|
|
5
6
|
const Serialisation = preload("serialisation.gd")
|
|
6
7
|
|
|
7
8
|
var _log: Log
|
|
@@ -124,12 +125,7 @@ func set_project_setting(params: Dictionary) -> Dictionary:
|
|
|
124
125
|
)
|
|
125
126
|
final_value = type_convert(final_value, wanted)
|
|
126
127
|
|
|
127
|
-
|
|
128
|
-
var err: Error = ProjectSettings.save()
|
|
129
|
-
if err != OK:
|
|
130
|
-
return _log.failure("Failed to save project.godot: " + error_string(err))
|
|
131
|
-
|
|
132
|
-
return {
|
|
128
|
+
var answer: Dictionary = {
|
|
133
129
|
"setting_path": setting_path,
|
|
134
130
|
"old_value": _values.serialize_value(old_value) if had_value else null,
|
|
135
131
|
"new_value": _values.serialize_value(final_value),
|
|
@@ -137,6 +133,18 @@ func set_project_setting(params: Dictionary) -> Dictionary:
|
|
|
137
133
|
"was_default": was_default,
|
|
138
134
|
"saved": true,
|
|
139
135
|
}
|
|
136
|
+
# The same value in the same type is no change, and the file is left alone: a save rewrites it
|
|
137
|
+
# whole. The type is compared as well, so an int setting the file holds as 50.0 is still put right.
|
|
138
|
+
if had_value and typeof(old_value) == typeof(final_value) and old_value == final_value:
|
|
139
|
+
answer["saved"] = false
|
|
140
|
+
answer["unchanged"] = true
|
|
141
|
+
return answer
|
|
142
|
+
|
|
143
|
+
ProjectSettings.set_setting(setting_path, final_value)
|
|
144
|
+
var err: Error = ProjectFile.save()
|
|
145
|
+
if err != OK:
|
|
146
|
+
return _log.failure("Failed to save project.godot: " + error_string(err))
|
|
147
|
+
return answer
|
|
140
148
|
|
|
141
149
|
|
|
142
150
|
# The type a setting wants, or TYPE_NIL where the engine names none and there is nothing to go on.
|
|
@@ -201,7 +209,7 @@ func add_autoload(params: Dictionary) -> Dictionary:
|
|
|
201
209
|
# "Global Variable" column. Without it the node still comes up under the root; only the name
|
|
202
210
|
# stops resolving.
|
|
203
211
|
ProjectSettings.set_setting(setting, ("*" if global else "") + path)
|
|
204
|
-
var err: Error =
|
|
212
|
+
var err: Error = ProjectFile.save()
|
|
205
213
|
if err != OK:
|
|
206
214
|
return _log.failure("Failed to save project.godot: " + error_string(err))
|
|
207
215
|
|
|
@@ -226,7 +234,7 @@ func remove_autoload(params: Dictionary) -> Dictionary:
|
|
|
226
234
|
|
|
227
235
|
var old_value: String = str(ProjectSettings.get_setting(setting))
|
|
228
236
|
ProjectSettings.set_setting(setting, null)
|
|
229
|
-
var err: Error =
|
|
237
|
+
var err: Error = ProjectFile.save()
|
|
230
238
|
if err != OK:
|
|
231
239
|
return _log.failure("Failed to save project.godot: " + error_string(err))
|
|
232
240
|
|
|
@@ -275,7 +283,7 @@ func set_main_scene(params: Dictionary) -> Dictionary:
|
|
|
275
283
|
var old_main_scene: String = str(ProjectSettings.get_setting("application/run/main_scene", ""))
|
|
276
284
|
|
|
277
285
|
ProjectSettings.set_setting("application/run/main_scene", scene_path)
|
|
278
|
-
var err: Error =
|
|
286
|
+
var err: Error = ProjectFile.save()
|
|
279
287
|
|
|
280
288
|
if err != OK:
|
|
281
289
|
return _log.failure("Failed to save project settings: " + str(err))
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
extends RefCounted
|
|
2
|
+
|
|
3
|
+
## project.godot written through the engine's own save, in the order the file already held.
|
|
4
|
+
##
|
|
5
|
+
## The engine writes each section's keys in the order it registered them, and an engine running a
|
|
6
|
+
## script registers them in another order than the editor does, so a one-setting change moved lines
|
|
7
|
+
## nobody touched across several sections and a commit of it read as a rewrite. The save is still the
|
|
8
|
+
## engine's, for what only it gets right: the header, each value's text and dropping a key that is
|
|
9
|
+
## back at its default. Only the order is taken from the file as it was.
|
|
10
|
+
|
|
11
|
+
const PATH: String = "res://project.godot"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## Saves the project's settings, keeping the sections and keys already in the file where they were.
|
|
15
|
+
## A key or a section new to the file goes where the engine put it relative to its neighbours.
|
|
16
|
+
static func save() -> Error:
|
|
17
|
+
var before: String = FileAccess.get_file_as_string(PATH)
|
|
18
|
+
var err: Error = ProjectSettings.save()
|
|
19
|
+
if err != OK or before.is_empty():
|
|
20
|
+
return err
|
|
21
|
+
var written: String = FileAccess.get_file_as_string(PATH)
|
|
22
|
+
var kept: String = in_order_of(before, written)
|
|
23
|
+
if kept == written:
|
|
24
|
+
return OK
|
|
25
|
+
var file: FileAccess = FileAccess.open(PATH, FileAccess.WRITE)
|
|
26
|
+
if file == null:
|
|
27
|
+
return FileAccess.get_open_error()
|
|
28
|
+
if not file.store_string(kept):
|
|
29
|
+
return file.get_error()
|
|
30
|
+
file.close()
|
|
31
|
+
return OK
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## [param written] with its sections and their keys put in the order [param before] has them. Every
|
|
35
|
+
## line of the result is a line of [param written], so nothing the engine wrote is lost or changed.
|
|
36
|
+
static func in_order_of(before: String, written: String) -> String:
|
|
37
|
+
var old: Dictionary = _parsed(before)
|
|
38
|
+
var fresh: Dictionary = _parsed(written)
|
|
39
|
+
var old_sections: Array[Dictionary] = old["sections"]
|
|
40
|
+
var fresh_sections: Array[Dictionary] = fresh["sections"]
|
|
41
|
+
|
|
42
|
+
var old_names: Array[String] = []
|
|
43
|
+
var old_keys: Dictionary[String, Array] = {}
|
|
44
|
+
for section: Dictionary in old_sections:
|
|
45
|
+
var name: String = section["name"]
|
|
46
|
+
old_names.append(name)
|
|
47
|
+
var keys: Array[String] = []
|
|
48
|
+
for entry: Dictionary in section["entries"]:
|
|
49
|
+
keys.append(str(entry["key"]))
|
|
50
|
+
old_keys[name] = keys
|
|
51
|
+
|
|
52
|
+
var by_name: Dictionary[String, Dictionary] = {}
|
|
53
|
+
var fresh_names: Array[String] = []
|
|
54
|
+
for section: Dictionary in fresh_sections:
|
|
55
|
+
var name: String = section["name"]
|
|
56
|
+
by_name[name] = section
|
|
57
|
+
fresh_names.append(name)
|
|
58
|
+
|
|
59
|
+
var text: String = fresh["preamble"]
|
|
60
|
+
var at: int = 0
|
|
61
|
+
for name: String in _merged(old_names, fresh_names):
|
|
62
|
+
var section: Dictionary = by_name[name]
|
|
63
|
+
var entries: Array[Dictionary] = section["entries"]
|
|
64
|
+
var entry_of: Dictionary[String, String] = {}
|
|
65
|
+
var fresh_keys: Array[String] = []
|
|
66
|
+
for entry: Dictionary in entries:
|
|
67
|
+
var key: String = entry["key"]
|
|
68
|
+
entry_of[key] = str(entry["text"])
|
|
69
|
+
fresh_keys.append(key)
|
|
70
|
+
var known: Array = old_keys.get(name, [])
|
|
71
|
+
var held: Array[String] = []
|
|
72
|
+
held.assign(known)
|
|
73
|
+
text += str(section["head"])
|
|
74
|
+
for key: String in _merged(held, fresh_keys):
|
|
75
|
+
text += entry_of[key]
|
|
76
|
+
# The blank lines closing a section belong to its place in the file rather than to the
|
|
77
|
+
# section, so the last one keeps the ending the engine gave the file wherever it moved from.
|
|
78
|
+
var placed: Dictionary = fresh_sections[at]
|
|
79
|
+
text += str(placed["tail"])
|
|
80
|
+
at += 1
|
|
81
|
+
return text
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
## The names of [param wanted] in the order [param held] lists them, those [param held] lacks each
|
|
85
|
+
## placed after the name [param wanted] puts before it. Names [param wanted] lacks are left out.
|
|
86
|
+
static func _merged(held: Array[String], wanted: Array[String]) -> Array[String]:
|
|
87
|
+
var order: Array[String] = []
|
|
88
|
+
for name: String in held:
|
|
89
|
+
if name in wanted and not name in order:
|
|
90
|
+
order.append(name)
|
|
91
|
+
var after: int = -1
|
|
92
|
+
for name: String in wanted:
|
|
93
|
+
var placed: int = order.find(name)
|
|
94
|
+
if placed == -1:
|
|
95
|
+
after += 1
|
|
96
|
+
# Not checked: a position inside the array cannot be refused.
|
|
97
|
+
var _inserted: int = order.insert(after, name)
|
|
98
|
+
else:
|
|
99
|
+
after = placed
|
|
100
|
+
return order
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## [param text] as a preamble (the header and anything before the first section) and its sections,
|
|
104
|
+
## each with its header line and the blank lines after it, its entries, and the blank lines closing it.
|
|
105
|
+
static func _parsed(text: String) -> Dictionary:
|
|
106
|
+
var preamble: String = ""
|
|
107
|
+
var sections: Array[Dictionary] = []
|
|
108
|
+
var current: Dictionary = {}
|
|
109
|
+
var body: Array[String] = []
|
|
110
|
+
for line: String in _logical_lines(text):
|
|
111
|
+
var stripped: String = line.strip_edges()
|
|
112
|
+
if stripped.begins_with("[") and stripped.ends_with("]"):
|
|
113
|
+
if not current.is_empty():
|
|
114
|
+
_close(current, body)
|
|
115
|
+
sections.append(current)
|
|
116
|
+
current = {"name": stripped.substr(1, stripped.length() - 2), "head": line}
|
|
117
|
+
body = []
|
|
118
|
+
elif current.is_empty():
|
|
119
|
+
preamble += line
|
|
120
|
+
elif body.is_empty() and stripped.is_empty():
|
|
121
|
+
current["head"] = str(current["head"]) + line
|
|
122
|
+
else:
|
|
123
|
+
body.append(line)
|
|
124
|
+
if not current.is_empty():
|
|
125
|
+
_close(current, body)
|
|
126
|
+
sections.append(current)
|
|
127
|
+
return {"preamble": preamble, "sections": sections}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
## Fills in [param section]'s entries and closing blank lines from the lines after its head. A blank
|
|
131
|
+
## or comment line between two entries stays with the entry before it.
|
|
132
|
+
static func _close(section: Dictionary, body: Array[String]) -> void:
|
|
133
|
+
var tail: String = ""
|
|
134
|
+
while not body.is_empty() and body[body.size() - 1].strip_edges().is_empty():
|
|
135
|
+
tail = body[body.size() - 1] + tail
|
|
136
|
+
body.remove_at(body.size() - 1)
|
|
137
|
+
var entries: Array[Dictionary] = []
|
|
138
|
+
for line: String in body:
|
|
139
|
+
var stripped: String = line.strip_edges()
|
|
140
|
+
if entries.is_empty() or not (stripped.is_empty() or stripped.begins_with(";")):
|
|
141
|
+
entries.append({"key": _key_of(line), "text": line})
|
|
142
|
+
else:
|
|
143
|
+
var last: Dictionary = entries[entries.size() - 1]
|
|
144
|
+
last["text"] = str(last["text"]) + line
|
|
145
|
+
section["entries"] = entries
|
|
146
|
+
section["tail"] = tail
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
## The key an entry sets: everything before its first `=` outside quotes, since a key with spaces or
|
|
150
|
+
## symbols in it is written quoted.
|
|
151
|
+
static func _key_of(line: String) -> String:
|
|
152
|
+
var quoted: bool = false
|
|
153
|
+
for i: int in line.length():
|
|
154
|
+
var c: String = line[i]
|
|
155
|
+
if c == '"' and (i == 0 or line[i - 1] != "\\"):
|
|
156
|
+
quoted = not quoted
|
|
157
|
+
elif c == "=" and not quoted:
|
|
158
|
+
return line.substr(0, i).strip_edges()
|
|
159
|
+
return line.strip_edges()
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
## [param text] split into lines that each end where an entry does: a value holding a dictionary, an
|
|
163
|
+
## array or a string runs over several lines, and splitting it there would sort its halves apart.
|
|
164
|
+
## Each piece keeps its line ending, so joining them gives the text back.
|
|
165
|
+
static func _logical_lines(text: String) -> Array[String]:
|
|
166
|
+
var lines: Array[String] = []
|
|
167
|
+
var start: int = 0
|
|
168
|
+
var depth: int = 0
|
|
169
|
+
var quoted: bool = false
|
|
170
|
+
var escaped: bool = false
|
|
171
|
+
var comment: bool = false
|
|
172
|
+
for i: int in text.length():
|
|
173
|
+
var c: String = text[i]
|
|
174
|
+
if i == start:
|
|
175
|
+
comment = c == ";"
|
|
176
|
+
if comment:
|
|
177
|
+
if c == "\n":
|
|
178
|
+
lines.append(text.substr(start, i + 1 - start))
|
|
179
|
+
start = i + 1
|
|
180
|
+
continue
|
|
181
|
+
if quoted:
|
|
182
|
+
if escaped:
|
|
183
|
+
escaped = false
|
|
184
|
+
elif c == "\\":
|
|
185
|
+
escaped = true
|
|
186
|
+
elif c == '"':
|
|
187
|
+
quoted = false
|
|
188
|
+
continue
|
|
189
|
+
match c:
|
|
190
|
+
'"':
|
|
191
|
+
quoted = true
|
|
192
|
+
"[", "(", "{":
|
|
193
|
+
depth += 1
|
|
194
|
+
"]", ")", "}":
|
|
195
|
+
depth = maxi(depth - 1, 0)
|
|
196
|
+
"\n":
|
|
197
|
+
if depth == 0:
|
|
198
|
+
lines.append(text.substr(start, i + 1 - start))
|
|
199
|
+
start = i + 1
|
|
200
|
+
if start < text.length():
|
|
201
|
+
lines.append(text.substr(start))
|
|
202
|
+
return lines
|
|
@@ -321,11 +321,25 @@ static func acceptable(value: Variant, type: int) -> bool:
|
|
|
321
321
|
## The conversion is also what restores a packed array's exact type. Those cross as the plain JSON
|
|
322
322
|
## lists they fit into, so what comes back from the wire is an Array, and the parameter is what says
|
|
323
323
|
## it was a PackedStringArray.
|
|
324
|
+
##
|
|
325
|
+
## A dictionary with no tag is read as the type wanted when it carries that type's fields, as
|
|
326
|
+
## scene_node and resource_edit read one: runtime_invoke refused {"x": 140, "y": 300} for a Vector2
|
|
327
|
+
## argument the editor tools took, so one value was right for one tool and wrong for the next. The
|
|
328
|
+
## value as sent is what is tagged, since the builders read a nested vector from its own fields.
|
|
324
329
|
func fitted(value: Variant, type: int) -> Variant:
|
|
325
330
|
var rebuilt: Variant = deserialize_value(value)
|
|
326
331
|
if type == TYPE_NIL or typeof(rebuilt) == type:
|
|
327
332
|
return rebuilt
|
|
328
333
|
|
|
334
|
+
if value is Dictionary and type != TYPE_DICTIONARY:
|
|
335
|
+
var fields: Dictionary = value
|
|
336
|
+
if not fields.has("_type"):
|
|
337
|
+
var tagged: Dictionary = fields.duplicate()
|
|
338
|
+
tagged["_type"] = type_string(type)
|
|
339
|
+
var built: Variant = deserialize_value(tagged)
|
|
340
|
+
if typeof(built) == type:
|
|
341
|
+
return built
|
|
342
|
+
|
|
329
343
|
if rebuilt is Array and LIST_TYPES.has(type):
|
|
330
344
|
return type_convert(rebuilt, type)
|
|
331
345
|
|
|
@@ -348,6 +362,21 @@ func fitted(value: Variant, type: int) -> Variant:
|
|
|
348
362
|
return type_convert(rebuilt, type)
|
|
349
363
|
|
|
350
364
|
|
|
365
|
+
## How a value of [param type] is written to be read as one, for a refusal to name, or empty for a
|
|
366
|
+
## type that is not built from fields. A refusal naming only the two types left a caller to find
|
|
367
|
+
## the shape in the description of another op.
|
|
368
|
+
static func written_as(type: int) -> String:
|
|
369
|
+
var tag: String = type_string(type)
|
|
370
|
+
var alternatives: Array = REQUIRED.get(tag, [])
|
|
371
|
+
if alternatives.is_empty() or tag == "float" or tag == "Dictionary":
|
|
372
|
+
return ""
|
|
373
|
+
var keys: Array = alternatives[0]
|
|
374
|
+
var parts: Array[String] = []
|
|
375
|
+
for key: Variant in keys:
|
|
376
|
+
parts.append('"%s": ...' % key)
|
|
377
|
+
return "{%s}" % ", ".join(parts)
|
|
378
|
+
|
|
379
|
+
|
|
351
380
|
## Whether [param fields] carries every key of any one of [param alternatives].
|
|
352
381
|
##
|
|
353
382
|
## More than one spelling because a rectangle has two: the two corners it is answered with, and the
|