ravensight-playtest 0.13.2 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +99 -4
  2. package/addons/ravensight_driver/driver.gd +472 -28
  3. package/docs/godot-driver.md +66 -2
  4. package/package.json +7 -5
  5. package/src/api/README.md +8 -1
  6. package/src/api/client.js +24 -1
  7. package/src/cli.js +14 -0
  8. package/src/commands/check.js +5 -2
  9. package/src/commands/fix.js +1 -1
  10. package/src/commands/run.js +26 -4
  11. package/src/commands/setup.js +176 -0
  12. package/src/packs/index.js +37 -5
  13. package/src/packs/keys.json +11 -0
  14. package/src/packs/pack-signing-hashes.json +7 -0
  15. package/src/packs/pack-signing-vectors.json +119 -0
  16. package/src/packs/signature.js +186 -0
  17. package/src/run/anygame/gamenotes.js +74 -12
  18. package/src/run/anygame/index.js +97 -34
  19. package/src/run/anygame/language.js +100 -10
  20. package/src/run/anygame/memory.js +70 -13
  21. package/src/run/anygame/shared-hashes.json +7 -7
  22. package/src/run/anygame/sound.js +59 -16
  23. package/src/run/args.js +2 -0
  24. package/src/run/claimwords.js +43 -7
  25. package/src/run/drivers/godot-cursor.js +96 -0
  26. package/src/run/drivers/godot-observation.js +29 -5
  27. package/src/run/drivers/godot.js +60 -5
  28. package/src/run/drivers/web.js +124 -14
  29. package/src/run/eventclaims.js +102 -6
  30. package/src/run/events.js +64 -6
  31. package/src/run/gameMemory.js +14 -5
  32. package/src/run/honesty.js +49 -2
  33. package/src/run/judge.js +22 -10
  34. package/src/run/liveFeed.js +254 -0
  35. package/src/run/personaLoop.js +103 -25
  36. package/src/run/pixels.js +491 -2
  37. package/src/run/replay.js +11 -0
  38. package/src/run/sdkSession.js +279 -16
  39. package/src/run/synthetic.js +12 -8
  40. package/src/run/tools.js +2 -2
@@ -30,7 +30,7 @@
30
30
  # it was parked, which is one of the limits docs/REPLAY.md names.
31
31
  extends Node
32
32
 
33
- const DRIVER_VERSION := "1.5.1"
33
+ const DRIVER_VERSION := "1.7.0"
34
34
  const DEFAULT_PORT := 47800
35
35
  const FEATURE_TAG := "ravensight_driver"
36
36
  const ADDON_DIR := "ravensight_driver"
@@ -45,6 +45,7 @@ const MAX_PRESS_MS := 10000
45
45
  const MAX_WAIT_FRAMES := 3600
46
46
  const MAX_STATE_DEPTH := 8
47
47
  const MAX_HOOK_BYTES := 65536
48
+ const MAX_MENU_ITEMS := 40
48
49
  const STATE_GROUP := "ravensight_state"
49
50
 
50
51
  const ERR_PARSE := -32700
@@ -92,6 +93,36 @@ var _step_selects: Array = []
92
93
  ## drag is a press, moves that carry the held button, and a release.
93
94
  var _mouse_pos := Vector2.ZERO
94
95
  var _mouse_mask := 0
96
+ ## In lockstep the game hears only the run's pointer (driver 1.6.0): a node last in
97
+ ## the root's input order swallows any mouse event the driver is not sending.
98
+ var _pointer_guard: Node = null
99
+ var _injecting := false
100
+ ## What desktop mouse events did to the engine's own pointer state before the
101
+ ## guard could stop them (driver 1.7.0): Input moves its pointer, its speed and
102
+ ## its buttons as an event is parsed, before any node sees it. The driver puts
103
+ ## the run's pointer back before the game's next physics tick or frame.
104
+ const RESTORE_META := &"ravensight_restore"
105
+ var _restoring := false
106
+ var _pointer_disturbed := false
107
+ var _desktop_relative := Vector2.ZERO
108
+ var _desktop_buttons := {}
109
+ ## How many desktop mouse events reached the engine in lockstep, for ping and
110
+ ## every step answer: a run where this is not zero had its pointer put back.
111
+ var _desktop_pointer := 0
112
+
113
+
114
+ ## Last in the root's input order, so the first `_input` a mouse event reaches. It
115
+ ## ends a mouse event from the desktop there, before the game's `_input`, its GUI
116
+ ## and its picking; the driver's own are let through.
117
+ class PointerGuard extends Node:
118
+ var driver: Node
119
+
120
+ func _input(event: InputEvent) -> void:
121
+ if event is InputEventMouse and driver != null and not driver._injecting:
122
+ get_viewport().set_input_as_handled()
123
+ # The driver's own putting back is swallowed too, and is not counted.
124
+ if not driver._restoring and not event.has_meta(RESTORE_META):
125
+ driver._note_desktop_pointer(event)
95
126
  ## Keys held with `repeat`, which echo while they are down as a keyboard's do.
96
127
  var _repeat_keys := {}
97
128
  # The frame strip (driver 1.5.0): small frames taken while an input plays, the
@@ -203,6 +234,7 @@ func _on_sdk_event(event_name: String, data: Dictionary) -> void:
203
234
 
204
235
  func _process(_delta: float) -> void:
205
236
  if _lockstep:
237
+ _restore_pointer()
206
238
  _advance_lockstep()
207
239
  else:
208
240
  _echo_held_keys_by_clock()
@@ -428,6 +460,7 @@ func _rpc_ping(id: Variant) -> void:
428
460
  "seed": _seed_value,
429
461
  "ticks_per_second": Engine.physics_ticks_per_second,
430
462
  "forced_draws": _forced_draws,
463
+ "desktop_pointer": _desktop_pointer,
431
464
  })
432
465
 
433
466
 
@@ -637,8 +670,14 @@ func _rpc_click(id: Variant, params: Dictionary) -> void:
637
670
 
638
671
  ## Where a Control's centre is in the window. Mouse events are in window pixels and
639
672
  ## a stretched project draws its canvas at another size, so the canvas position alone
640
- ## landed somewhere else on any game with a stretch mode.
673
+ ## landed somewhere else on any game with a stretch mode. A control inside a dialog
674
+ ## or popup window is placed in that window's own pixels, so its viewport's screen
675
+ ## transform (the window's place in the game's window, and both stretches) is what
676
+ ## puts it in the game's window: a dialog's OK button was clicked at the top left.
641
677
  func _window_position(control: Control) -> Vector2:
678
+ var viewport := control.get_viewport()
679
+ if viewport != null and viewport != get_tree().root:
680
+ return viewport.get_screen_transform() * control.get_global_transform_with_canvas() * (control.size / 2.0)
642
681
  return get_window().get_final_transform() * control.get_global_rect().get_center()
643
682
 
644
683
 
@@ -693,7 +732,7 @@ func _send_mouse_event(kind: String, pos: Vector2, params: Dictionary) -> void:
693
732
  motion.button_mask = _mouse_mask
694
733
  _stamp_modifiers(motion)
695
734
  _mouse_pos = pos
696
- Input.parse_input_event(motion)
735
+ _parse_pointer(motion)
697
736
  "down", "up":
698
737
  var pressed := kind == "down"
699
738
  var button := _button_index(params)
@@ -710,7 +749,7 @@ func _send_mouse_event(kind: String, pos: Vector2, params: Dictionary) -> void:
710
749
  click.button_mask = _mouse_mask
711
750
  _stamp_modifiers(click)
712
751
  _mouse_pos = pos
713
- Input.parse_input_event(click)
752
+ _parse_pointer(click)
714
753
  "wheel":
715
754
  _send_mouse_event("move", pos, params)
716
755
  var dy := float(params.get("dy", 0.0))
@@ -739,7 +778,7 @@ func _send_wheel(pos: Vector2, button: MouseButton, amount: float, params: Dicti
739
778
  wheel.shift_pressed = true
740
779
  if bool(params.get("alt", false)):
741
780
  wheel.alt_pressed = true
742
- Input.parse_input_event(wheel)
781
+ _parse_pointer(wheel)
743
782
 
744
783
 
745
784
  const MOUSE_KINDS := ["move", "down", "up", "wheel"]
@@ -979,28 +1018,107 @@ func _select_plan(params: Dictionary) -> Dictionary:
979
1018
  if node is Slider and not (node as Slider).editable:
980
1019
  return {"code": ERR_INVALID_PARAMS, "message": "that slider is not editable"}
981
1020
  return {"node": node, "kind": "range", "value": clampf(float(params.get("value")), range_node.min_value, range_node.max_value)}
982
- if not (node is OptionButton or node is ItemList or node is TabBar or node is TabContainer):
983
- return {"code": ERR_INVALID_PARAMS, "message": "%s is a %s, not a dropdown, a list, a tab bar, a slider or a spin box" % [str(node.name), node.get_class()]}
1021
+ if not _is_choice(node):
1022
+ return {"code": ERR_INVALID_PARAMS, "message": "%s is a %s, not a dropdown, a menu, a list, a tab bar, a slider or a spin box" % [str(node.name), node.get_class()]}
1023
+ var opener: Node = null
1024
+ if node is MenuButton:
1025
+ if (node as MenuButton).disabled:
1026
+ return {"code": ERR_INVALID_PARAMS, "message": "that menu button is disabled"}
1027
+ opener = node
1028
+ node = (node as MenuButton).get_popup()
1029
+ elif node is PopupMenu and not (node as PopupMenu).visible:
1030
+ return {"code": ERR_INVALID_PARAMS, "message": "that menu is not open; a player opens it first, with a click or a right click on what shows it"}
1031
+ if node is OptionButton and (node as OptionButton).disabled:
1032
+ return {"code": ERR_INVALID_PARAMS, "message": "that dropdown is disabled"}
1033
+ if node is PopupMenu:
1034
+ return _menu_plan(node as PopupMenu, params, opener)
1035
+ var found := _find_option(node, params)
1036
+ if found.has("code"):
1037
+ return found
1038
+ var index := int(found["index"])
1039
+ var locked := _locked_reason(node, index)
1040
+ if not locked.is_empty():
1041
+ return {"code": ERR_INVALID_PARAMS, "message": locked}
1042
+ return {"node": node, "kind": "option", "index": index, "option": str(found["name"])}
1043
+
1044
+
1045
+ ## The option a select names in this control, by its place or its text (the
1046
+ ## whole text first, then a part of it), as {index, name}, or the refusal that
1047
+ ## lists what the control offers. A separator and a hidden tab are not offered.
1048
+ func _find_option(node: Node, params: Dictionary) -> Dictionary:
984
1049
  var names: Array = _option_names(node)
1050
+ var offered: Array = []
1051
+ for i in names.size():
1052
+ if _is_offered(node, i):
1053
+ offered.append(i)
1054
+ var listed := PackedStringArray()
1055
+ for i in offered.slice(0, 20):
1056
+ listed.append(str(names[i]))
1057
+ var refused := {"code": ERR_INVALID_PARAMS, "message": "no such option; this control offers: %s" % ", ".join(listed), "data": {"options": Array(listed)}}
985
1058
  var index := -1
986
1059
  if params.has("index"):
987
1060
  index = int(params.get("index"))
1061
+ if not offered.has(index):
1062
+ return refused
988
1063
  elif params.has("option"):
989
1064
  var wanted := str(params.get("option")).strip_edges().to_lower()
990
- for i in names.size():
1065
+ if wanted.is_empty():
1066
+ return refused
1067
+ for i in offered:
991
1068
  if str(names[i]).strip_edges().to_lower() == wanted:
992
1069
  index = i
993
1070
  break
994
1071
  if index < 0:
995
- for i in names.size():
1072
+ for i in offered:
996
1073
  if str(names[i]).to_lower().contains(wanted):
997
1074
  index = i
998
1075
  break
999
- if index < 0 or index >= names.size():
1000
- return {"code": ERR_INVALID_PARAMS, "message": "no such option; this control offers: %s" % ", ".join(PackedStringArray(names.slice(0, 20))), "data": {"options": names.slice(0, 40)}}
1001
- if node is OptionButton and ((node as OptionButton).disabled or (node as OptionButton).is_item_disabled(index)):
1002
- return {"code": ERR_INVALID_PARAMS, "message": "that option is disabled"}
1003
- return {"node": node, "kind": "option", "index": index, "option": str(names[index])}
1076
+ if index < 0:
1077
+ return refused
1078
+ return {"index": index, "name": str(names[index])}
1079
+
1080
+
1081
+ ## A pick in a menu, through the further menus its items open (driver 1.7.0).
1082
+ ## `option` may be a path, "Export > PNG": each part but the last names an item
1083
+ ## that opens a further menu, and the last is chosen in the deepest one. A path
1084
+ ## that ends on such an item opens it and chooses nothing, as a player's hover
1085
+ ## does. The whole path is checked before anything is opened.
1086
+ func _menu_plan(menu: PopupMenu, params: Dictionary, opener: Node) -> Dictionary:
1087
+ var parts: Array = [params]
1088
+ var wanted := str(params.get("option", ""))
1089
+ if not params.has("index") and wanted.contains(">") and _find_option(menu, params).has("code"):
1090
+ parts = []
1091
+ for part in wanted.split(">"):
1092
+ if part.strip_edges().is_empty():
1093
+ return {"code": ERR_INVALID_PARAMS, "message": "a menu path names each item in turn, such as \"Export > PNG\""}
1094
+ parts.append({"option": part.strip_edges()})
1095
+ var chain: Array = []
1096
+ var names := PackedStringArray()
1097
+ var current := menu
1098
+ for i in parts.size():
1099
+ var found := _find_option(current, parts[i])
1100
+ if found.has("code"):
1101
+ if i > 0:
1102
+ found["message"] = "\"%s\" opens a menu with no such item; it offers: %s" % [names[names.size() - 1], ", ".join(PackedStringArray(found["data"]["options"]))]
1103
+ return found
1104
+ var index := int(found["index"])
1105
+ names.append(str(found["name"]))
1106
+ if current.is_item_disabled(index):
1107
+ return {"code": ERR_INVALID_PARAMS, "message": "that item is disabled"}
1108
+ var last: bool = i == parts.size() - 1
1109
+ if _opens_submenu(current, index):
1110
+ var further := _submenu_of(current, index)
1111
+ if further == null:
1112
+ return {"code": ERR_INVALID_PARAMS, "message": "the menu that item opens could not be found"}
1113
+ chain.append([current, index, further])
1114
+ if last:
1115
+ return {"node": further, "kind": "submenu", "chain": chain, "opener": opener, "option": " > ".join(names)}
1116
+ current = further
1117
+ continue
1118
+ if not last:
1119
+ return {"code": ERR_INVALID_PARAMS, "message": "\"%s\" does not open a further menu; choose it on its own" % str(found["name"])}
1120
+ return {"node": current, "kind": "menu", "index": index, "option": " > ".join(names), "opener": opener, "chain": chain}
1121
+ return {"code": ERR_INVALID_PARAMS, "message": "no such option"}
1004
1122
 
1005
1123
 
1006
1124
  func _select_apply(plan: Dictionary) -> Dictionary:
@@ -1012,23 +1130,191 @@ func _select_apply(plan: Dictionary) -> Dictionary:
1012
1130
  if node is Slider:
1013
1131
  (node as Slider).drag_ended.emit(not is_equal_approx(before, range_node.value))
1014
1132
  return {"kind": "range", "value": range_node.value, "min": range_node.min_value, "max": range_node.max_value}
1133
+ if str(plan["kind"]) == "submenu":
1134
+ var shown := _open_menu_chain(plan.get("opener"), plan["chain"])
1135
+ return {"kind": "submenu", "option": str(plan["option"]), "opened": shown}
1015
1136
  var index := int(plan["index"])
1137
+ if str(plan["kind"]) == "menu":
1138
+ return _menu_pick(node as PopupMenu, index, plan.get("opener"), str(plan["option"]), plan.get("chain", []))
1139
+ var already := false
1016
1140
  if node is OptionButton:
1017
- (node as OptionButton).select(index)
1018
- (node as OptionButton).item_selected.emit(index)
1141
+ var dropdown := node as OptionButton
1142
+ # A pick of the option already in effect sends nothing, unless the game asked for it.
1143
+ already = dropdown.selected == index and not dropdown.allow_reselect
1144
+ if not already:
1145
+ dropdown.select(index)
1146
+ dropdown.item_selected.emit(index)
1147
+ # A pick closes the list, as a player's does.
1148
+ if dropdown.get_popup().visible:
1149
+ dropdown.get_popup().hide()
1019
1150
  elif node is ItemList:
1020
- (node as ItemList).select(index)
1021
- (node as ItemList).item_selected.emit(index)
1151
+ var list := node as ItemList
1152
+ already = list.is_selected(index) and not list.allow_reselect
1153
+ # A plain click: this item alone is selected, and the list says so the way
1154
+ # its select mode does.
1155
+ list.select(index, true)
1156
+ if not already:
1157
+ if list.select_mode == ItemList.SELECT_SINGLE:
1158
+ list.item_selected.emit(index)
1159
+ else:
1160
+ list.multi_selected.emit(index, true)
1022
1161
  elif node is TabBar:
1162
+ already = (node as TabBar).current_tab == index
1023
1163
  (node as TabBar).current_tab = index
1024
1164
  elif node is TabContainer:
1165
+ already = (node as TabContainer).current_tab == index
1025
1166
  (node as TabContainer).current_tab = index
1026
- return {"kind": "option", "index": index, "option": str(plan["option"])}
1167
+ var out := {"kind": "option", "index": index, "option": str(plan["option"])}
1168
+ if already:
1169
+ out["already"] = true
1170
+ return out
1171
+
1172
+
1173
+ ## An item of a menu chosen, as the engine does it for a click on the item: the
1174
+ ## id and the index are sent, then the menu closes unless the game keeps it open,
1175
+ ## and with it the menus that opened it (PopupMenu.activate_item does the same).
1176
+ ## A menu button's menu is opened first, as a player's first click does, and the
1177
+ ## further menus on the way are opened as a player's hover opens them.
1178
+ func _menu_pick(menu: PopupMenu, index: int, opener: Variant, option: String, chain: Array = []) -> Dictionary:
1179
+ var opened := _open_menu_chain(opener, chain)
1180
+ var keep_open := menu.is_item_checkable(index) and not menu.hide_on_checkable_item_selection
1181
+ menu.id_pressed.emit(menu.get_item_id(index))
1182
+ menu.index_pressed.emit(index)
1183
+ if menu.hide_on_item_selection and not keep_open:
1184
+ for link in chain:
1185
+ var parent: PopupMenu = link[0]
1186
+ if parent.visible and parent.hide_on_item_selection:
1187
+ parent.hide()
1188
+ if menu.visible:
1189
+ menu.hide()
1190
+ var out := {"kind": "menu", "index": index, "option": option}
1191
+ if opened:
1192
+ out["opened"] = true
1193
+ return out
1194
+
1195
+
1196
+ ## Opens a menu button's menu, then each further menu of the path, where the
1197
+ ## engine would put it: beside the item that opens it. True when anything opened.
1198
+ func _open_menu_chain(opener: Variant, chain: Array) -> bool:
1199
+ var opened := false
1200
+ if opener is MenuButton and not (opener as MenuButton).get_popup().visible:
1201
+ (opener as MenuButton).show_popup()
1202
+ opened = true
1203
+ for link in chain:
1204
+ var parent: PopupMenu = link[0]
1205
+ var further: PopupMenu = link[2]
1206
+ if further.visible:
1207
+ continue
1208
+ further.popup(Rect2i(_submenu_position(parent, int(link[1])), Vector2i.ZERO))
1209
+ opened = true
1210
+ return opened
1211
+
1212
+
1213
+ ## Where the engine opens a further menu: at the parent's right edge, level with
1214
+ ## the item. The item's own row is not exposed, so its height is the parent's
1215
+ ## height shared among its items; the outline then reports where it really is.
1216
+ func _submenu_position(parent: PopupMenu, index: int) -> Vector2i:
1217
+ var rows := maxi(parent.item_count, 1)
1218
+ var row := float(parent.size.y) / float(rows)
1219
+ return Vector2i(parent.position.x + parent.size.x, parent.position.y + int(row * index))
1220
+
1221
+
1222
+ ## The menu an item opens: a node since Godot 4.3, a child named by the item before.
1223
+ func _submenu_of(menu: PopupMenu, index: int) -> PopupMenu:
1224
+ if menu.has_method("get_item_submenu_node"):
1225
+ var node: Variant = menu.call("get_item_submenu_node", index)
1226
+ if node is PopupMenu:
1227
+ return node
1228
+ var child_name := str(menu.call("get_item_submenu", index)) if menu.has_method("get_item_submenu") else ""
1229
+ if child_name.is_empty():
1230
+ return null
1231
+ return menu.get_node_or_null(NodePath(child_name)) as PopupMenu
1232
+
1233
+
1234
+ ## A control whose options `select` chooses from.
1235
+ func _is_choice(node: Node) -> bool:
1236
+ return node is OptionButton or node is MenuButton or node is PopupMenu or node is ItemList or node is TabBar or node is TabContainer
1237
+
1238
+
1239
+ ## Whether a player is shown this option at all: a separator is a line, not an
1240
+ ## option, and a hidden tab is not drawn.
1241
+ func _is_offered(node: Node, index: int) -> bool:
1242
+ if node is OptionButton:
1243
+ return not (node as OptionButton).is_item_separator(index)
1244
+ if node is PopupMenu:
1245
+ return not (node as PopupMenu).is_item_separator(index)
1246
+ if node is TabBar:
1247
+ return not (node as TabBar).is_tab_hidden(index)
1248
+ if node is TabContainer:
1249
+ return not (node as TabContainer).is_tab_hidden(index)
1250
+ return true
1251
+
1252
+
1253
+ ## Whether this option is drawn locked: a disabled option, item or tab.
1254
+ func _is_disabled(node: Node, index: int) -> bool:
1255
+ if node is OptionButton:
1256
+ return (node as OptionButton).is_item_disabled(index)
1257
+ if node is PopupMenu:
1258
+ return (node as PopupMenu).is_item_disabled(index)
1259
+ if node is ItemList:
1260
+ return (node as ItemList).is_item_disabled(index)
1261
+ if node is TabBar:
1262
+ return (node as TabBar).is_tab_disabled(index)
1263
+ if node is TabContainer:
1264
+ return (node as TabContainer).is_tab_disabled(index)
1265
+ return false
1266
+
1267
+
1268
+ ## Why a player cannot pick this option, or "" when they can.
1269
+ func _locked_reason(node: Node, index: int) -> String:
1270
+ if _is_disabled(node, index):
1271
+ if node is TabBar or node is TabContainer:
1272
+ return "that tab is disabled"
1273
+ return "that option is disabled" if node is OptionButton else "that item is disabled"
1274
+ if node is ItemList and not (node as ItemList).is_item_selectable(index):
1275
+ return "that item cannot be selected"
1276
+ return ""
1027
1277
 
1028
1278
 
1029
- ## What a control offers to choose from, as the text a player reads.
1279
+ ## A menu item that opens another menu (the call changed name in Godot 4.3).
1280
+ func _opens_submenu(menu: PopupMenu, index: int) -> bool:
1281
+ if menu.has_method("get_item_submenu_node") and menu.call("get_item_submenu_node", index) != null:
1282
+ return true
1283
+ return menu.has_method("get_item_submenu") and not str(menu.call("get_item_submenu", index)).is_empty()
1284
+
1285
+
1286
+ ## What the outline shows a control offers: the options a player sees, a locked
1287
+ ## one marked disabled and a ticked menu item checked.
1288
+ func _option_view(node: Node) -> Array:
1289
+ var source: Node = (node as MenuButton).get_popup() if node is MenuButton else node
1290
+ var names := _option_names(source)
1291
+ var view: Array = []
1292
+ for i in names.size():
1293
+ if view.size() >= 20:
1294
+ break
1295
+ if not _is_offered(source, i):
1296
+ continue
1297
+ var shown := str(names[i])
1298
+ if _is_disabled(source, i):
1299
+ shown += " (disabled)"
1300
+ elif source is PopupMenu and (source as PopupMenu).is_item_checked(i):
1301
+ shown += " (checked)"
1302
+ elif source is PopupMenu and _opens_submenu(source as PopupMenu, i):
1303
+ shown += " (submenu)"
1304
+ view.append(shown)
1305
+ return view
1306
+
1307
+
1308
+ ## What a control offers to choose from, as the text a player reads, one entry
1309
+ ## per item in the engine's own order (a separator is an empty entry).
1030
1310
  func _option_names(node: Node) -> Array:
1031
1311
  var names: Array = []
1312
+ if node is MenuButton:
1313
+ return _option_names((node as MenuButton).get_popup())
1314
+ if node is PopupMenu:
1315
+ for i in mini((node as PopupMenu).item_count, MAX_MENU_ITEMS):
1316
+ names.append((node as PopupMenu).get_item_text(i))
1317
+ return names
1032
1318
  if node is OptionButton:
1033
1319
  for i in (node as OptionButton).item_count:
1034
1320
  names.append((node as OptionButton).get_item_text(i))
@@ -1086,7 +1372,7 @@ func _rpc_edge_layout(id: Variant) -> void:
1086
1372
  for child in node.get_children():
1087
1373
  if not _is_driver_node(child):
1088
1374
  stack.append(child)
1089
- if not (node is BaseButton or node is LineEdit or node is Range or node is ItemList):
1375
+ if not (node is BaseButton or node is LineEdit or node is Range or node is ItemList or node is TabBar):
1090
1376
  continue
1091
1377
  var control := node as Control
1092
1378
  if not control.is_visible_in_tree() or control.size.x <= 0 or control.size.y <= 0:
@@ -1229,6 +1515,109 @@ func _enter_lockstep(seed_text: String) -> void:
1229
1515
  # A window that never takes focus has nothing to lose. Input here is synthetic
1230
1516
  # anyway, and the run no longer takes the developer's keyboard.
1231
1517
  get_window().unfocusable = true
1518
+ # The desktop's own pointer is not the run's either: a mouse moved over the
1519
+ # window reached the game as motion and hovers, between and during steps, so
1520
+ # a replay of the same inputs came back with another state whenever someone
1521
+ # used the machine. A pass-through region of one pixel outside the window
1522
+ # sends every real mouse event to whatever is under it; the driver's own
1523
+ # events are parsed straight into the engine and are not touched.
1524
+ get_window().mouse_passthrough_polygon = PackedVector2Array([Vector2(0, 0), Vector2(1, 0), Vector2(0, 1)])
1525
+ # The desktop does not always honour that at once (a fast move still arrived
1526
+ # as a few motion events on macOS), so the engine also drops what gets in.
1527
+ _pointer_guard = PointerGuard.new()
1528
+ _pointer_guard.name = "RavensightPointerGuard"
1529
+ _pointer_guard.driver = self
1530
+ _pointer_guard.process_mode = Node.PROCESS_MODE_ALWAYS
1531
+ get_tree().root.add_child.call_deferred(_pointer_guard)
1532
+ # First in every physics tick as well as every frame (a property Godot
1533
+ # gained in 4.2, so it is set by name).
1534
+ if "process_physics_priority" in self:
1535
+ set("process_physics_priority", -2147483648)
1536
+
1537
+
1538
+ ## First in every physics tick in lockstep, so a game that reads the pointer in
1539
+ ## _physics_process reads the run's pointer too.
1540
+ func _physics_process(_delta: float) -> void:
1541
+ if _lockstep:
1542
+ _restore_pointer()
1543
+
1544
+
1545
+ ## A desktop mouse event the guard swallowed. Its motion and its buttons already
1546
+ ## reached Input, so they are kept to be undone.
1547
+ func _note_desktop_pointer(event: InputEvent) -> void:
1548
+ _desktop_pointer += 1
1549
+ _pointer_disturbed = true
1550
+ if event is InputEventMouseMotion:
1551
+ _desktop_relative += (event as InputEventMouseMotion).relative
1552
+ elif event is InputEventMouseButton:
1553
+ var button := event as InputEventMouseButton
1554
+ if button.button_index in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_RIGHT, MOUSE_BUTTON_MIDDLE]:
1555
+ _desktop_buttons[button.button_index] = button.pressed
1556
+
1557
+
1558
+ ## Puts the run's own pointer back where Input reads it: Input's pointer position
1559
+ ## (Input.get_mouse_position, and a viewport's in a window with no desktop mouse),
1560
+ ## its buttons (Input.is_mouse_button_pressed, get_mouse_button_mask) and its
1561
+ ## speed (get_last_mouse_velocity: the desktop's motion is sent back reversed, so
1562
+ ## it cancels). The events go through the guard, which stops them, so no node and
1563
+ ## no control sees them. The real pointer is never moved: a viewport's
1564
+ ## get_mouse_position and a node's get_global_mouse_position in the game's own
1565
+ ## window read the desktop's pointer inside the engine, which an addon cannot
1566
+ ## change without moving it, so those still read the desktop (see REPLAY.md).
1567
+ func _restore_pointer() -> void:
1568
+ if _pointer_guard == null or not _pointer_guard.is_inside_tree():
1569
+ return
1570
+ # Whatever the desktop still had queued is counted before it is undone.
1571
+ Input.flush_buffered_events()
1572
+ if not _pointer_disturbed:
1573
+ return
1574
+ var relative := _desktop_relative
1575
+ var buttons := _desktop_buttons
1576
+ _pointer_disturbed = false
1577
+ _desktop_relative = Vector2.ZERO
1578
+ _desktop_buttons = {}
1579
+ _restoring = true
1580
+ var motion := InputEventMouseMotion.new()
1581
+ motion.position = _mouse_pos
1582
+ motion.global_position = _mouse_pos
1583
+ motion.relative = -relative
1584
+ if "screen_relative" in motion:
1585
+ motion.set("screen_relative", -relative)
1586
+ motion.button_mask = _mouse_mask
1587
+ motion.set_meta(RESTORE_META, true)
1588
+ Input.parse_input_event(motion)
1589
+ for index in buttons:
1590
+ var button: MouseButton = int(index) as MouseButton
1591
+ var held := (_mouse_mask & _button_mask(button)) != 0
1592
+ if bool(buttons[index]) == held:
1593
+ continue
1594
+ var undo := InputEventMouseButton.new()
1595
+ undo.button_index = button
1596
+ undo.pressed = held
1597
+ undo.position = _mouse_pos
1598
+ undo.global_position = _mouse_pos
1599
+ undo.button_mask = _mouse_mask
1600
+ undo.set_meta(RESTORE_META, true)
1601
+ Input.parse_input_event(undo)
1602
+ Input.flush_buffered_events()
1603
+ _restoring = false
1604
+
1605
+
1606
+ ## A pointer event the driver sends. In lockstep it is dispatched at once, alone,
1607
+ ## past the guard, after whatever the desktop had queued was dispatched (and
1608
+ ## swallowed); otherwise it is parsed as any input is.
1609
+ func _parse_pointer(event: InputEvent) -> void:
1610
+ if _pointer_guard == null or not _pointer_guard.is_inside_tree():
1611
+ Input.parse_input_event(event)
1612
+ return
1613
+ var root := get_tree().root
1614
+ if _pointer_guard.get_index() != root.get_child_count() - 1:
1615
+ root.move_child(_pointer_guard, -1)
1616
+ Input.flush_buffered_events()
1617
+ _injecting = true
1618
+ Input.parse_input_event(event)
1619
+ Input.flush_buffered_events()
1620
+ _injecting = false
1232
1621
 
1233
1622
 
1234
1623
  ## A physics step with a delta of zero still moves things: a stack of rigid bodies
@@ -1440,7 +1829,7 @@ func _apply_step_event(event: Dictionary) -> void:
1440
1829
 
1441
1830
 
1442
1831
  func _lockstep_answer(with_digest: bool) -> Dictionary:
1443
- var out := {"tick": _sim_tick, "frame": Engine.get_process_frames(), "reasserted": _reasserted, "clicks": _step_clicks, "selects": _step_selects}
1832
+ var out := {"tick": _sim_tick, "frame": Engine.get_process_frames(), "reasserted": _reasserted, "desktop_pointer": _desktop_pointer, "clicks": _step_clicks, "selects": _step_selects}
1444
1833
  if with_digest:
1445
1834
  out["digest"] = _state_digest()
1446
1835
  return out
@@ -1590,8 +1979,18 @@ func _node_to_dict(node: Node, depth: int, max_depth: int, visible_only: bool, b
1590
1979
  out["visible"] = (node as CanvasItem).is_visible_in_tree()
1591
1980
  elif node is Node3D:
1592
1981
  out["visible"] = (node as Node3D).is_visible_in_tree()
1982
+ elif node is Window and node != get_tree().root:
1983
+ out["visible"] = (node as Window).visible
1984
+ # The menu a dropdown or a menu button opens is the engine's own child, with
1985
+ # a name like @PopupMenu@12 a player never reads; it is called what it is.
1986
+ if node is PopupMenu and _is_internal(node):
1987
+ out["name"] = "menu"
1593
1988
 
1594
1989
  var text := _text_of(node)
1990
+ # A dialog's title is what a player reads on its bar. Only the outline shows
1991
+ # it: _text_of is shared with the simulate addon's state digest.
1992
+ if text.is_empty() and node is Window and node != get_tree().root and not (node is PopupMenu):
1993
+ text = (node as Window).title
1595
1994
  if not text.is_empty():
1596
1995
  out["text"] = text.substr(0, MAX_TEXT_CHARS)
1597
1996
  else:
@@ -1618,13 +2017,24 @@ func _node_to_dict(node: Node, depth: int, max_depth: int, visible_only: bool, b
1618
2017
  var at := _window_position(node as Control)
1619
2018
  out["center"] = [at.x, at.y]
1620
2019
  out["focus"] = (node as Control).has_focus()
2020
+ elif node is Window and node != get_tree().root and (node as Window).visible:
2021
+ var shown := _window_rect(node as Window)
2022
+ if shown.size.x > 0.0:
2023
+ out["rect"] = [shown.position.x, shown.position.y, shown.size.x, shown.size.y]
2024
+ out["center"] = [shown.get_center().x, shown.get_center().y]
2025
+ if not (node as Window).is_embedded():
2026
+ # Drawn in a window of its own: not in a screenshot of the game's window.
2027
+ out["own_window"] = true
1621
2028
  if node is BaseButton:
1622
2029
  out["disabled"] = (node as BaseButton).disabled
1623
- # What a dropdown, a list or a tab bar offers and has chosen, and where a
1624
- # slider stands: what `select` needs, and what a player reads off them.
1625
- if node is OptionButton or node is ItemList or node is TabBar or node is TabContainer:
2030
+ # What a dropdown, a menu, a list or a tab bar offers and has chosen, and where
2031
+ # a slider stands: what `select` needs, and what a player reads off them. A
2032
+ # separator and a hidden tab are not offered; a locked or ticked item says so.
2033
+ if _is_choice(node):
1626
2034
  var offered := _option_names(node)
1627
- out["options"] = offered.slice(0, 20)
2035
+ out["options"] = _option_view(node)
2036
+ if node is PopupMenu:
2037
+ out["open"] = (node as PopupMenu).visible
1628
2038
  var chosen := -1
1629
2039
  if node is OptionButton:
1630
2040
  chosen = (node as OptionButton).selected
@@ -1633,7 +2043,7 @@ func _node_to_dict(node: Node, depth: int, max_depth: int, visible_only: bool, b
1633
2043
  chosen = picked[0] if picked.size() > 0 else -1
1634
2044
  elif node is TabBar:
1635
2045
  chosen = (node as TabBar).current_tab
1636
- else:
2046
+ elif node is TabContainer:
1637
2047
  chosen = (node as TabContainer).current_tab
1638
2048
  if chosen >= 0 and chosen < offered.size():
1639
2049
  out["selected"] = str(offered[chosen])
@@ -1650,7 +2060,7 @@ func _node_to_dict(node: Node, depth: int, max_depth: int, visible_only: bool, b
1650
2060
 
1651
2061
  var children: Array = []
1652
2062
  if depth < max_depth:
1653
- for child in node.get_children():
2063
+ for child in _shown_children(node):
1654
2064
  if budget["left"] <= 0:
1655
2065
  budget["truncated"] = true
1656
2066
  break
@@ -1684,9 +2094,43 @@ func _is_visible_candidate(node: Node) -> bool:
1684
2094
  return (node as CanvasItem).is_visible_in_tree()
1685
2095
  if node is Node3D:
1686
2096
  return (node as Node3D).is_visible_in_tree()
2097
+ # A closed dialog or menu is a Window that is not shown.
2098
+ if node is Window:
2099
+ return (node as Window).visible
1687
2100
  return true
1688
2101
 
1689
2102
 
2103
+ ## The children a player can be shown: the scene's own, plus the engine's own
2104
+ ## children where they are what a player reads and presses. That is a menu a
2105
+ ## control opened (a dropdown's list, a menu button's, a text field's right
2106
+ ## click menu) while it is open, and everything inside a dialog or popup
2107
+ ## window (its message, its OK and Cancel buttons). Any other engine child, a
2108
+ ## scroll bar or a spin box's text field, stays out, as before.
2109
+ func _shown_children(node: Node) -> Array:
2110
+ var own: Array = node.get_children()
2111
+ var every: Array = node.get_children(true)
2112
+ if every.size() == own.size():
2113
+ return own
2114
+ var inside_window := node is Window and node != get_tree().root
2115
+ var out: Array = []
2116
+ for child in every:
2117
+ if inside_window or not _is_internal(child) or (child is Window and (child as Window).visible):
2118
+ out.append(child)
2119
+ return out
2120
+
2121
+
2122
+ func _is_internal(node: Node) -> bool:
2123
+ var parent := node.get_parent()
2124
+ return parent != null and not parent.get_children().has(node)
2125
+
2126
+
2127
+ ## Where a popup or dialog window is drawn, in the game window's pixels.
2128
+ func _window_rect(window: Window) -> Rect2:
2129
+ if not window.is_embedded():
2130
+ return Rect2(Vector2(window.position - get_window().position), Vector2(window.size))
2131
+ return get_window().get_final_transform() * Rect2(Vector2(window.position), Vector2(window.size))
2132
+
2133
+
1690
2134
  func _text_of(node: Node) -> String:
1691
2135
  if node is RichTextLabel:
1692
2136
  return (node as RichTextLabel).get_parsed_text()