ravensight-playtest 0.8.3 → 0.10.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.
- package/README.md +280 -66
- package/addons/ravensight_driver/driver.gd +666 -21
- package/docs/ADAPTERS.md +11 -7
- package/docs/NATIVE_RUNNER.md +3 -1
- package/docs/godot-driver.md +127 -13
- package/package.json +8 -6
- package/src/api/client.js +4 -3
- package/src/cli.js +84 -25
- package/src/commands/check.js +30 -4
- package/src/commands/fakeCore.js +1 -0
- package/src/commands/hosted.js +41 -12
- package/src/commands/init.js +17 -1
- package/src/commands/run.js +209 -14
- package/src/commands/upload.js +6 -2
- package/src/commands/validate.js +1 -1
- package/src/commands/validateHosted.js +50 -5
- package/src/config.js +33 -2
- package/src/hosted/archivePreflight.js +7 -7
- package/src/hosted/buildUpload.js +89 -8
- package/src/hosted/recordedRun.js +141 -26
- package/src/hosted/status.js +19 -10
- package/src/run/actionSelector.js +14 -3
- package/src/run/aggregate.js +57 -3
- package/src/run/anygame/controlbook.js +179 -0
- package/src/run/anygame/genre.js +179 -0
- package/src/run/anygame/index.js +258 -0
- package/src/run/anygame/language.js +336 -0
- package/src/run/anygame/memory.js +330 -0
- package/src/run/anygame/shared-hashes.json +10 -0
- package/src/run/anygame/shared.js +24 -0
- package/src/run/anygame/sound.js +342 -0
- package/src/run/args.js +75 -8
- package/src/run/choiceCheck.js +312 -0
- package/src/run/context.js +254 -13
- package/src/run/drivers/godot-observation.js +93 -6
- package/src/run/drivers/godot.js +769 -46
- package/src/run/drivers/recording.js +24 -4
- package/src/run/drivers/web.js +1242 -77
- package/src/run/edgePass.js +731 -0
- package/src/run/fixLoop.js +5 -4
- package/src/run/focus.js +65 -0
- package/src/run/gamepad.js +108 -0
- package/src/run/godotEdgePass.js +235 -0
- package/src/run/godotTesterProbes.js +192 -0
- package/src/run/headings.js +21 -0
- package/src/run/honesty.js +544 -0
- package/src/run/inputs.js +256 -0
- package/src/run/marks.js +142 -0
- package/src/run/personaLoop.js +1000 -79
- package/src/run/phone.js +7 -0
- package/src/run/pixels.js +215 -0
- package/src/run/playClock.js +162 -0
- package/src/run/readiness.js +585 -0
- package/src/run/refusal.js +67 -0
- package/src/run/regions.js +119 -0
- package/src/run/report.js +14 -2
- package/src/run/reportChecks.js +472 -0
- package/src/run/resume.js +3 -2
- package/src/run/screenshots.js +161 -0
- package/src/run/strip.js +114 -0
- package/src/run/testerLedger.js +312 -0
- package/src/run/testerProbes.js +584 -0
- package/src/run/thinRun.js +102 -0
- package/src/run/timeFreeze.js +79 -0
- package/src/run/tools.js +454 -29
- package/src/runDefaults.js +24 -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.
|
|
33
|
+
const DRIVER_VERSION := "1.5.0"
|
|
34
34
|
const DEFAULT_PORT := 47800
|
|
35
35
|
const FEATURE_TAG := "ravensight_driver"
|
|
36
36
|
const ADDON_DIR := "ravensight_driver"
|
|
@@ -87,6 +87,25 @@ var _held_keys := {}
|
|
|
87
87
|
var _held_actions := {}
|
|
88
88
|
var _reasserted := 0
|
|
89
89
|
var _step_clicks: Array = []
|
|
90
|
+
var _step_selects: Array = []
|
|
91
|
+
## The pointer as the driver last left it, and the buttons it holds down: a
|
|
92
|
+
## drag is a press, moves that carry the held button, and a release.
|
|
93
|
+
var _mouse_pos := Vector2.ZERO
|
|
94
|
+
var _mouse_mask := 0
|
|
95
|
+
## Keys held with `repeat`, which echo while they are down as a keyboard's do.
|
|
96
|
+
var _repeat_keys := {}
|
|
97
|
+
# The frame strip (driver 1.5.0): small frames taken while an input plays, the
|
|
98
|
+
# screen as it was before it, and the step ticks they are due on.
|
|
99
|
+
const MAX_STRIP_FRAMES := 4
|
|
100
|
+
const STRIP_SCALE := 0.25
|
|
101
|
+
var _strip_frames: Array = []
|
|
102
|
+
var _strip_base: Image = null
|
|
103
|
+
var _strip_ticks: Array = []
|
|
104
|
+
var _step_total := 0
|
|
105
|
+
const KEY_REPEAT_DELAY_MS := 500
|
|
106
|
+
const KEY_REPEAT_INTERVAL_MS := 33
|
|
107
|
+
const WHEEL_NOTCH := 120.0
|
|
108
|
+
const MAX_WHEEL_NOTCHES := 40
|
|
90
109
|
|
|
91
110
|
## --- Lifecycle ----------------------------------------------------------------
|
|
92
111
|
|
|
@@ -182,6 +201,8 @@ func _on_sdk_event(event_name: String, data: Dictionary) -> void:
|
|
|
182
201
|
func _process(_delta: float) -> void:
|
|
183
202
|
if _lockstep:
|
|
184
203
|
_advance_lockstep()
|
|
204
|
+
else:
|
|
205
|
+
_echo_held_keys_by_clock()
|
|
185
206
|
_accept_connections()
|
|
186
207
|
_read_client()
|
|
187
208
|
_drain_inbox()
|
|
@@ -314,11 +335,20 @@ func _handle_line(line: String) -> void:
|
|
|
314
335
|
"press_action": _rpc_press_action(id, params)
|
|
315
336
|
"key": _rpc_key(id, params)
|
|
316
337
|
"click": _rpc_click(id, params)
|
|
338
|
+
"mouse": _rpc_mouse(id, params)
|
|
317
339
|
"wait_frames": _rpc_wait_frames(id, params)
|
|
318
340
|
"seed": _rpc_seed(id, params)
|
|
319
341
|
"step": _rpc_step(id, params)
|
|
320
342
|
"digest": _send_result(id, _lockstep_answer(true))
|
|
321
343
|
"screenshot": _rpc_screenshot(id, params)
|
|
344
|
+
"strip_begin": _rpc_strip_begin(id)
|
|
345
|
+
"strip_frame": _rpc_strip_frame(id)
|
|
346
|
+
"strip_status": _rpc_strip_status(id, params)
|
|
347
|
+
"select": _rpc_select(id, params)
|
|
348
|
+
"edge_focus": _rpc_edge_focus(id, params)
|
|
349
|
+
"window_size": _rpc_window_size(id, params)
|
|
350
|
+
"edge_layout": _rpc_edge_layout(id)
|
|
351
|
+
"user_files": _rpc_user_files(id)
|
|
322
352
|
"set_time_scale": _rpc_set_time_scale(id, params)
|
|
323
353
|
"list_actions": _send_result(id, {"actions": _action_names()})
|
|
324
354
|
"quit": _rpc_quit(id, params)
|
|
@@ -490,6 +520,7 @@ func _rpc_key(id: Variant, params: Dictionary) -> void:
|
|
|
490
520
|
_send_error(id, ERR_INVALID_PARAMS, "unknown keycode: %s" % str(params.get("keycode")))
|
|
491
521
|
return
|
|
492
522
|
var event := _send_key_event(keycode, params)
|
|
523
|
+
_track_repeat(keycode, params, Time.get_ticks_msec())
|
|
493
524
|
_send_result(id, {"ok": true, "keycode": keycode, "pressed": event.pressed})
|
|
494
525
|
|
|
495
526
|
|
|
@@ -498,15 +529,83 @@ func _send_key_event(keycode: int, params: Dictionary) -> InputEventKey:
|
|
|
498
529
|
event.keycode = keycode
|
|
499
530
|
event.physical_keycode = keycode
|
|
500
531
|
event.pressed = bool(params.get("pressed", true))
|
|
532
|
+
event.echo = event.pressed and bool(params.get("echo", false))
|
|
501
533
|
var unicode := int(params.get("unicode", 0))
|
|
502
534
|
if unicode == 0:
|
|
503
535
|
unicode = _unicode_for(params.get("keycode"))
|
|
504
536
|
if unicode != 0:
|
|
505
537
|
event.unicode = unicode
|
|
538
|
+
# A chord is its modifier held and its key pressed: the key event says which
|
|
539
|
+
# modifiers are down, as a real one does, so Shift+Tab is heard as Shift+Tab.
|
|
540
|
+
_note_modifier(keycode, event.pressed)
|
|
541
|
+
_stamp_modifiers(event)
|
|
506
542
|
Input.parse_input_event(event)
|
|
507
543
|
return event
|
|
508
544
|
|
|
509
545
|
|
|
546
|
+
## Which modifier keys the driver holds down right now.
|
|
547
|
+
var _mods := {KEY_SHIFT: false, KEY_CTRL: false, KEY_ALT: false, KEY_META: false}
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
func _note_modifier(keycode: int, pressed: bool) -> void:
|
|
551
|
+
if _mods.has(keycode):
|
|
552
|
+
_mods[keycode] = pressed
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
func _stamp_modifiers(event: InputEventWithModifiers) -> void:
|
|
556
|
+
event.shift_pressed = bool(_mods[KEY_SHIFT])
|
|
557
|
+
event.ctrl_pressed = bool(_mods[KEY_CTRL])
|
|
558
|
+
event.alt_pressed = bool(_mods[KEY_ALT])
|
|
559
|
+
event.meta_pressed = bool(_mods[KEY_META])
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
## A key pressed with `repeat` echoes while it is held: after the delay a
|
|
563
|
+
## keyboard has, the game hears it again at a keyboard's rate, as an echo.
|
|
564
|
+
## `since` is a tick count in lockstep and milliseconds otherwise.
|
|
565
|
+
func _track_repeat(keycode: int, params: Dictionary, since: int) -> void:
|
|
566
|
+
if not bool(params.get("pressed", true)):
|
|
567
|
+
_repeat_keys.erase(keycode)
|
|
568
|
+
return
|
|
569
|
+
if bool(params.get("repeat", false)) and not bool(params.get("echo", false)):
|
|
570
|
+
_repeat_keys[keycode] = {"params": params, "since": since, "sent": 0}
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
func _send_echo(keycode: int, entry: Dictionary) -> void:
|
|
574
|
+
var echo_params: Dictionary = (entry["params"] as Dictionary).duplicate()
|
|
575
|
+
echo_params["echo"] = true
|
|
576
|
+
echo_params["pressed"] = true
|
|
577
|
+
_send_key_event(keycode, echo_params)
|
|
578
|
+
entry["sent"] = int(entry["sent"]) + 1
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
## Outside lockstep the echoes follow the clock, as a keyboard's do.
|
|
582
|
+
func _echo_held_keys_by_clock() -> void:
|
|
583
|
+
if _repeat_keys.is_empty():
|
|
584
|
+
return
|
|
585
|
+
var now := Time.get_ticks_msec()
|
|
586
|
+
for keycode in _repeat_keys:
|
|
587
|
+
var entry: Dictionary = _repeat_keys[keycode]
|
|
588
|
+
var held := now - int(entry["since"])
|
|
589
|
+
var due := 0 if held < KEY_REPEAT_DELAY_MS else 1 + int((held - KEY_REPEAT_DELAY_MS) / KEY_REPEAT_INTERVAL_MS)
|
|
590
|
+
if due > int(entry["sent"]):
|
|
591
|
+
_send_echo(int(keycode), entry)
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
## In lockstep they follow the ticks, so a replay hears the same echoes on the
|
|
595
|
+
## same ticks. Called once for every tick that runs.
|
|
596
|
+
func _echo_held_keys_by_tick() -> void:
|
|
597
|
+
if _repeat_keys.is_empty():
|
|
598
|
+
return
|
|
599
|
+
var tps := maxi(Engine.physics_ticks_per_second, 1)
|
|
600
|
+
var delay_ticks := maxi(int(round(KEY_REPEAT_DELAY_MS * tps / 1000.0)), 1)
|
|
601
|
+
var every := maxi(int(round(KEY_REPEAT_INTERVAL_MS * tps / 1000.0)), 1)
|
|
602
|
+
for keycode in _repeat_keys:
|
|
603
|
+
var entry: Dictionary = _repeat_keys[keycode]
|
|
604
|
+
var held := _sim_tick - int(entry["since"])
|
|
605
|
+
if held >= delay_ticks and (held - delay_ticks) % every == 0:
|
|
606
|
+
_send_echo(int(keycode), entry)
|
|
607
|
+
|
|
608
|
+
|
|
510
609
|
func _rpc_click(id: Variant, params: Dictionary) -> void:
|
|
511
610
|
var problem := _check_params(params, {
|
|
512
611
|
"x": "number",
|
|
@@ -555,24 +654,122 @@ func _click_position(target: Node) -> Variant:
|
|
|
555
654
|
|
|
556
655
|
|
|
557
656
|
func _send_click_events(pos: Vector2, params: Dictionary) -> void:
|
|
558
|
-
|
|
657
|
+
_send_mouse_event("move", pos, params)
|
|
658
|
+
_send_mouse_event("down", pos, params)
|
|
659
|
+
_send_mouse_event("up", pos, params)
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
func _button_index(params: Dictionary) -> MouseButton:
|
|
559
663
|
match str(params.get("button", "left")):
|
|
560
|
-
"right":
|
|
561
|
-
"middle":
|
|
664
|
+
"right": return MOUSE_BUTTON_RIGHT
|
|
665
|
+
"middle": return MOUSE_BUTTON_MIDDLE
|
|
666
|
+
return MOUSE_BUTTON_LEFT
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
func _button_mask(button: MouseButton) -> int:
|
|
670
|
+
match button:
|
|
671
|
+
MOUSE_BUTTON_RIGHT: return MOUSE_BUTTON_MASK_RIGHT
|
|
672
|
+
MOUSE_BUTTON_MIDDLE: return MOUSE_BUTTON_MASK_MIDDLE
|
|
673
|
+
return MOUSE_BUTTON_MASK_LEFT
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
## One mouse event, as a hand makes it: `move` carries the buttons that are
|
|
677
|
+
## held, so a press, moves and a release are a drag; `wheel` is one press and
|
|
678
|
+
## release of a wheel button per notch, at the pointer.
|
|
679
|
+
func _send_mouse_event(kind: String, pos: Vector2, params: Dictionary) -> void:
|
|
680
|
+
match kind:
|
|
681
|
+
"move":
|
|
682
|
+
var motion := InputEventMouseMotion.new()
|
|
683
|
+
motion.position = pos
|
|
684
|
+
motion.global_position = pos
|
|
685
|
+
motion.relative = pos - _mouse_pos
|
|
686
|
+
# A property Godot gained after 4.2, so it is set by name.
|
|
687
|
+
if "screen_relative" in motion:
|
|
688
|
+
motion.set("screen_relative", motion.relative)
|
|
689
|
+
motion.button_mask = _mouse_mask
|
|
690
|
+
_stamp_modifiers(motion)
|
|
691
|
+
_mouse_pos = pos
|
|
692
|
+
Input.parse_input_event(motion)
|
|
693
|
+
"down", "up":
|
|
694
|
+
var pressed := kind == "down"
|
|
695
|
+
var button := _button_index(params)
|
|
696
|
+
if pressed:
|
|
697
|
+
_mouse_mask |= _button_mask(button)
|
|
698
|
+
else:
|
|
699
|
+
_mouse_mask &= ~_button_mask(button)
|
|
700
|
+
var click := InputEventMouseButton.new()
|
|
701
|
+
click.button_index = button
|
|
702
|
+
click.position = pos
|
|
703
|
+
click.global_position = pos
|
|
704
|
+
click.pressed = pressed
|
|
705
|
+
click.double_click = pressed and bool(params.get("double", false))
|
|
706
|
+
click.button_mask = _mouse_mask
|
|
707
|
+
_stamp_modifiers(click)
|
|
708
|
+
_mouse_pos = pos
|
|
709
|
+
Input.parse_input_event(click)
|
|
710
|
+
"wheel":
|
|
711
|
+
_send_mouse_event("move", pos, params)
|
|
712
|
+
var dy := float(params.get("dy", 0.0))
|
|
713
|
+
var dx := float(params.get("dx", 0.0))
|
|
714
|
+
_send_wheel(pos, MOUSE_BUTTON_WHEEL_DOWN if dy > 0.0 else MOUSE_BUTTON_WHEEL_UP, absf(dy), params)
|
|
715
|
+
_send_wheel(pos, MOUSE_BUTTON_WHEEL_RIGHT if dx > 0.0 else MOUSE_BUTTON_WHEEL_LEFT, absf(dx), params)
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
func _send_wheel(pos: Vector2, button: MouseButton, amount: float, params: Dictionary) -> void:
|
|
719
|
+
if amount <= 0.0:
|
|
720
|
+
return
|
|
721
|
+
var notches: int = clampi(int(ceil(amount / WHEEL_NOTCH)), 1, MAX_WHEEL_NOTCHES)
|
|
722
|
+
for i in notches:
|
|
723
|
+
for pressed in [true, false]:
|
|
724
|
+
var wheel := InputEventMouseButton.new()
|
|
725
|
+
wheel.button_index = button
|
|
726
|
+
wheel.position = pos
|
|
727
|
+
wheel.global_position = pos
|
|
728
|
+
wheel.pressed = pressed
|
|
729
|
+
wheel.factor = 1.0
|
|
730
|
+
wheel.button_mask = _mouse_mask
|
|
731
|
+
_stamp_modifiers(wheel)
|
|
732
|
+
if bool(params.get("ctrl", false)):
|
|
733
|
+
wheel.ctrl_pressed = true
|
|
734
|
+
if bool(params.get("shift", false)):
|
|
735
|
+
wheel.shift_pressed = true
|
|
736
|
+
if bool(params.get("alt", false)):
|
|
737
|
+
wheel.alt_pressed = true
|
|
738
|
+
Input.parse_input_event(wheel)
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
const MOUSE_KINDS := ["move", "down", "up", "wheel"]
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
## Where a mouse event lands: a node's centre, or the point given. Null when a
|
|
745
|
+
## named node cannot be pointed at.
|
|
746
|
+
func _mouse_target(params: Dictionary) -> Variant:
|
|
747
|
+
if params.has("node_path"):
|
|
748
|
+
return _click_position(get_node_or_null(NodePath(str(params.get("node_path")))))
|
|
749
|
+
return Vector2(float(params.get("x", 0.0)), float(params.get("y", 0.0)))
|
|
562
750
|
|
|
563
|
-
var motion := InputEventMouseMotion.new()
|
|
564
|
-
motion.position = pos
|
|
565
|
-
motion.global_position = pos
|
|
566
|
-
Input.parse_input_event(motion)
|
|
567
751
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
752
|
+
## `mouse{kind, x, y | node_path, button, double, dx, dy}`: one pointer event.
|
|
753
|
+
## A hover is a move; a held press is a down, time, and an up; a drag is a
|
|
754
|
+
## down, moves and an up; a scroll is a wheel.
|
|
755
|
+
func _rpc_mouse(id: Variant, params: Dictionary) -> void:
|
|
756
|
+
var problem := _check_params(params, {
|
|
757
|
+
"kind": "string", "x": "number", "y": "number", "node_path": "string", "button": "string",
|
|
758
|
+
"double": "boolean", "dx": "number", "dy": "number", "ctrl": "boolean", "shift": "boolean", "alt": "boolean",
|
|
759
|
+
})
|
|
760
|
+
if not problem.is_empty():
|
|
761
|
+
_send_error(id, ERR_INVALID_PARAMS, problem)
|
|
762
|
+
return
|
|
763
|
+
var kind := str(params.get("kind", ""))
|
|
764
|
+
if not (kind in MOUSE_KINDS):
|
|
765
|
+
_send_error(id, ERR_INVALID_PARAMS, "kind must be move, down, up or wheel")
|
|
766
|
+
return
|
|
767
|
+
var at: Variant = _mouse_target(params)
|
|
768
|
+
if at == null:
|
|
769
|
+
_send_error(id, ERR_NODE_NOT_FOUND, "clickable node not found: %s" % str(params.get("node_path")))
|
|
770
|
+
return
|
|
771
|
+
_send_mouse_event(kind, at, params)
|
|
772
|
+
_send_result(id, {"ok": true, "position": [(at as Vector2).x, (at as Vector2).y]})
|
|
576
773
|
|
|
577
774
|
|
|
578
775
|
func _rpc_wait_frames(id: Variant, params: Dictionary) -> void:
|
|
@@ -585,10 +782,14 @@ func _rpc_wait_frames(id: Variant, params: Dictionary) -> void:
|
|
|
585
782
|
|
|
586
783
|
|
|
587
784
|
func _rpc_screenshot(id: Variant, params: Dictionary) -> void:
|
|
588
|
-
var problem := _check_params(params, {"max_width": "number", "region": "array"})
|
|
785
|
+
var problem := _check_params(params, {"max_width": "number", "region": "array", "format": "string", "quality": "number", "strip": "boolean"})
|
|
589
786
|
if not problem.is_empty():
|
|
590
787
|
_send_error(id, ERR_INVALID_PARAMS, problem)
|
|
591
788
|
return
|
|
789
|
+
var format := str(params.get("format", "png"))
|
|
790
|
+
if format != "png" and format != "jpeg":
|
|
791
|
+
_send_error(id, ERR_INVALID_PARAMS, "format must be png or jpeg")
|
|
792
|
+
return
|
|
592
793
|
if params.has("region") and not _is_number_quad(params.get("region")):
|
|
593
794
|
_send_error(id, ERR_INVALID_PARAMS, "region must be four numbers: [x, y, width, height]")
|
|
594
795
|
return
|
|
@@ -603,18 +804,326 @@ func _rpc_screenshot(id: Variant, params: Dictionary) -> void:
|
|
|
603
804
|
if params.has("region"):
|
|
604
805
|
var region: Array = params.get("region")
|
|
605
806
|
image = image.get_region(Rect2i(int(region[0]), int(region[1]), int(region[2]), int(region[3])))
|
|
807
|
+
# The size before any scaling is the size click coordinates are in.
|
|
808
|
+
var window_size := [image.get_width(), image.get_height()]
|
|
606
809
|
var max_width: int = maxi(int(params.get("max_width", 1280)), 1)
|
|
607
810
|
if image.get_width() > max_width:
|
|
608
811
|
var height := maxi(1, int(round(image.get_height() * float(max_width) / image.get_width())))
|
|
609
812
|
image.resize(max_width, height, Image.INTERPOLATE_BILINEAR)
|
|
813
|
+
# The frames taken while the last input played go in a row under the picture,
|
|
814
|
+
# in the same image; the picture itself keeps its place, so a point on it is
|
|
815
|
+
# still the point a click lands on.
|
|
816
|
+
var strip_count := 0
|
|
817
|
+
if bool(params.get("strip", false)) and not _strip_frames.is_empty():
|
|
818
|
+
strip_count = _strip_frames.size()
|
|
819
|
+
image = _with_strip(image)
|
|
820
|
+
_strip_frames = []
|
|
821
|
+
_strip_base = null
|
|
822
|
+
# A JPEG is for a model to look at: the same picture in a fraction of the
|
|
823
|
+
# bytes. Evidence is saved as PNG, which is the default.
|
|
824
|
+
var bytes: PackedByteArray
|
|
825
|
+
if format == "jpeg":
|
|
826
|
+
bytes = image.save_jpg_to_buffer(clampf(float(params.get("quality", 0.7)), 0.1, 1.0))
|
|
827
|
+
else:
|
|
828
|
+
bytes = image.save_png_to_buffer()
|
|
610
829
|
_send_result(id, {
|
|
611
|
-
"format":
|
|
830
|
+
"format": format,
|
|
831
|
+
"window": window_size,
|
|
612
832
|
"width": image.get_width(),
|
|
613
833
|
"height": image.get_height(),
|
|
614
|
-
"
|
|
834
|
+
"strip": strip_count,
|
|
835
|
+
"data": Marshalls.raw_to_base64(bytes),
|
|
615
836
|
})
|
|
616
837
|
|
|
617
838
|
|
|
839
|
+
## --- The frame strip ----------------------------------------------------------
|
|
840
|
+
|
|
841
|
+
## The screen as a small image, or null with no viewport to read.
|
|
842
|
+
func _strip_thumb() -> Image:
|
|
843
|
+
if _is_headless():
|
|
844
|
+
return null
|
|
845
|
+
var image := get_viewport().get_texture().get_image()
|
|
846
|
+
if image == null or image.is_empty():
|
|
847
|
+
return null
|
|
848
|
+
image.convert(Image.FORMAT_RGB8)
|
|
849
|
+
image.resize(maxi(1, int(round(image.get_width() * STRIP_SCALE))), maxi(1, int(round(image.get_height() * STRIP_SCALE))), Image.INTERPOLATE_BILINEAR)
|
|
850
|
+
return image
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
func _grab_strip_frame() -> void:
|
|
854
|
+
if _strip_frames.size() >= MAX_STRIP_FRAMES:
|
|
855
|
+
return
|
|
856
|
+
var thumb := _strip_thumb()
|
|
857
|
+
if thumb != null:
|
|
858
|
+
_strip_frames.append(thumb)
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
## Whether two small frames differ by more than a blinking cursor: more than one
|
|
862
|
+
## cell in a hundred of a coarse grid changed by more than a tenth of full scale.
|
|
863
|
+
func _strip_differs(a: Image, b: Image) -> bool:
|
|
864
|
+
if a == null or b == null:
|
|
865
|
+
return false
|
|
866
|
+
var x: Image = a.duplicate()
|
|
867
|
+
var y: Image = b.duplicate()
|
|
868
|
+
x.resize(48, 27, Image.INTERPOLATE_BILINEAR)
|
|
869
|
+
y.resize(48, 27, Image.INTERPOLATE_BILINEAR)
|
|
870
|
+
var xs := x.get_data()
|
|
871
|
+
var ys := y.get_data()
|
|
872
|
+
if xs.size() != ys.size():
|
|
873
|
+
return true
|
|
874
|
+
var changed := 0
|
|
875
|
+
var cells := xs.size() / 3
|
|
876
|
+
for i in cells:
|
|
877
|
+
var d := absi(xs[i * 3] - ys[i * 3]) + absi(xs[i * 3 + 1] - ys[i * 3 + 1]) + absi(xs[i * 3 + 2] - ys[i * 3 + 2])
|
|
878
|
+
if d > 76:
|
|
879
|
+
changed += 1
|
|
880
|
+
return changed * 100 > cells
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
## The picture with the strip's frames in a row under it.
|
|
884
|
+
func _with_strip(image: Image) -> Image:
|
|
885
|
+
var main: Image = image.duplicate()
|
|
886
|
+
main.convert(Image.FORMAT_RGB8)
|
|
887
|
+
var w := main.get_width()
|
|
888
|
+
var h := main.get_height()
|
|
889
|
+
var cell_w := maxi(1, int(round(w * STRIP_SCALE)))
|
|
890
|
+
var cell_h := maxi(1, int(round(h * STRIP_SCALE)))
|
|
891
|
+
var out := Image.create(w, h + cell_h, false, Image.FORMAT_RGB8)
|
|
892
|
+
out.fill(Color(0.07, 0.07, 0.07))
|
|
893
|
+
out.blit_rect(main, Rect2i(0, 0, w, h), Vector2i(0, 0))
|
|
894
|
+
for i in _strip_frames.size():
|
|
895
|
+
var frame: Image = (_strip_frames[i] as Image).duplicate()
|
|
896
|
+
frame.resize(cell_w, cell_h, Image.INTERPOLATE_BILINEAR)
|
|
897
|
+
out.blit_rect(frame, Rect2i(0, 0, cell_w, cell_h), Vector2i(i * cell_w, h))
|
|
898
|
+
# A bar between the frames, so four of them never read as one picture.
|
|
899
|
+
out.fill_rect(Rect2i(i * cell_w, h, 3, cell_h), Color(0.96, 0.77, 0.26))
|
|
900
|
+
return out
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
## `strip_begin`: forget any frames, and keep the screen as it is now to compare
|
|
904
|
+
## the frames with. For an input played on the wall clock; a lockstep step takes
|
|
905
|
+
## `strip_at` instead.
|
|
906
|
+
func _rpc_strip_begin(id: Variant) -> void:
|
|
907
|
+
_strip_frames = []
|
|
908
|
+
_strip_base = _strip_thumb()
|
|
909
|
+
_send_result(id, {"ok": _strip_base != null})
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
## `strip_frame`: take one frame now.
|
|
913
|
+
func _rpc_strip_frame(id: Variant) -> void:
|
|
914
|
+
if _is_headless():
|
|
915
|
+
_send_result(id, {"frames": 0})
|
|
916
|
+
return
|
|
917
|
+
await _await_post_draw()
|
|
918
|
+
_grab_strip_frame()
|
|
919
|
+
_send_result(id, {"frames": _strip_frames.size()})
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
## `strip_status{clear}`: how many frames were taken and whether the game moved
|
|
923
|
+
## in them: some frame differs from the one before it, the first from the screen
|
|
924
|
+
## before the input. `ended_as_began` compares the screen now with that one.
|
|
925
|
+
func _rpc_strip_status(id: Variant, params: Dictionary) -> void:
|
|
926
|
+
var moved := false
|
|
927
|
+
var previous: Image = _strip_base
|
|
928
|
+
for frame in _strip_frames:
|
|
929
|
+
if _strip_differs(previous, frame):
|
|
930
|
+
moved = true
|
|
931
|
+
previous = frame
|
|
932
|
+
var ended := false
|
|
933
|
+
if not _is_headless() and _strip_base != null:
|
|
934
|
+
await _await_post_draw()
|
|
935
|
+
ended = not _strip_differs(_strip_base, _strip_thumb())
|
|
936
|
+
var count := _strip_frames.size()
|
|
937
|
+
if bool(params.get("clear", false)) or not moved:
|
|
938
|
+
_strip_frames = []
|
|
939
|
+
_strip_base = null
|
|
940
|
+
_send_result(id, {"frames": count, "moved": moved, "ended_as_began": ended})
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
## --- Dropdowns, sliders and lists ---------------------------------------------
|
|
944
|
+
|
|
945
|
+
## `select{node_path, option | index | value}`: choose an option of an
|
|
946
|
+
## OptionButton, an ItemList or a tab bar by its text or its place, or set a
|
|
947
|
+
## slider or a spin box to a value. The control answers as it does to a player:
|
|
948
|
+
## it shows the choice and sends the signal a pick or a drag would.
|
|
949
|
+
func _rpc_select(id: Variant, params: Dictionary) -> void:
|
|
950
|
+
var problem := _check_params(params, {"node_path": "string", "option": "string", "index": "number", "value": "number"})
|
|
951
|
+
if not problem.is_empty():
|
|
952
|
+
_send_error(id, ERR_INVALID_PARAMS, problem)
|
|
953
|
+
return
|
|
954
|
+
var plan := _select_plan(params)
|
|
955
|
+
if plan.has("code"):
|
|
956
|
+
_send_error(id, int(plan["code"]), str(plan["message"]), plan.get("data"))
|
|
957
|
+
return
|
|
958
|
+
_send_result(id, _select_apply(plan))
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
## What a select would do, checked and not yet done: the node and the option's
|
|
962
|
+
## place or the value, or the error that refuses it.
|
|
963
|
+
func _select_plan(params: Dictionary) -> Dictionary:
|
|
964
|
+
var node := get_node_or_null(NodePath(str(params.get("node_path", ""))))
|
|
965
|
+
if node == null:
|
|
966
|
+
return {"code": ERR_NODE_NOT_FOUND, "message": "clickable node not found: %s" % str(params.get("node_path", ""))}
|
|
967
|
+
if node is Range:
|
|
968
|
+
var range_node := node as Range
|
|
969
|
+
if not params.has("value"):
|
|
970
|
+
return {"code": ERR_INVALID_PARAMS, "message": "a slider or a spin box takes value: a number from %s to %s" % [str(range_node.min_value), str(range_node.max_value)]}
|
|
971
|
+
if node is Slider and not (node as Slider).editable:
|
|
972
|
+
return {"code": ERR_INVALID_PARAMS, "message": "that slider is not editable"}
|
|
973
|
+
return {"node": node, "kind": "range", "value": clampf(float(params.get("value")), range_node.min_value, range_node.max_value)}
|
|
974
|
+
if not (node is OptionButton or node is ItemList or node is TabBar or node is TabContainer):
|
|
975
|
+
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()]}
|
|
976
|
+
var names: Array = _option_names(node)
|
|
977
|
+
var index := -1
|
|
978
|
+
if params.has("index"):
|
|
979
|
+
index = int(params.get("index"))
|
|
980
|
+
elif params.has("option"):
|
|
981
|
+
var wanted := str(params.get("option")).strip_edges().to_lower()
|
|
982
|
+
for i in names.size():
|
|
983
|
+
if str(names[i]).strip_edges().to_lower() == wanted:
|
|
984
|
+
index = i
|
|
985
|
+
break
|
|
986
|
+
if index < 0:
|
|
987
|
+
for i in names.size():
|
|
988
|
+
if str(names[i]).to_lower().contains(wanted):
|
|
989
|
+
index = i
|
|
990
|
+
break
|
|
991
|
+
if index < 0 or index >= names.size():
|
|
992
|
+
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)}}
|
|
993
|
+
if node is OptionButton and ((node as OptionButton).disabled or (node as OptionButton).is_item_disabled(index)):
|
|
994
|
+
return {"code": ERR_INVALID_PARAMS, "message": "that option is disabled"}
|
|
995
|
+
return {"node": node, "kind": "option", "index": index, "option": str(names[index])}
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
func _select_apply(plan: Dictionary) -> Dictionary:
|
|
999
|
+
var node: Node = plan["node"]
|
|
1000
|
+
if str(plan["kind"]) == "range":
|
|
1001
|
+
var range_node := node as Range
|
|
1002
|
+
var before := range_node.value
|
|
1003
|
+
range_node.value = float(plan["value"])
|
|
1004
|
+
if node is Slider:
|
|
1005
|
+
(node as Slider).drag_ended.emit(not is_equal_approx(before, range_node.value))
|
|
1006
|
+
return {"kind": "range", "value": range_node.value, "min": range_node.min_value, "max": range_node.max_value}
|
|
1007
|
+
var index := int(plan["index"])
|
|
1008
|
+
if node is OptionButton:
|
|
1009
|
+
(node as OptionButton).select(index)
|
|
1010
|
+
(node as OptionButton).item_selected.emit(index)
|
|
1011
|
+
elif node is ItemList:
|
|
1012
|
+
(node as ItemList).select(index)
|
|
1013
|
+
(node as ItemList).item_selected.emit(index)
|
|
1014
|
+
elif node is TabBar:
|
|
1015
|
+
(node as TabBar).current_tab = index
|
|
1016
|
+
elif node is TabContainer:
|
|
1017
|
+
(node as TabContainer).current_tab = index
|
|
1018
|
+
return {"kind": "option", "index": index, "option": str(plan["option"])}
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
## What a control offers to choose from, as the text a player reads.
|
|
1022
|
+
func _option_names(node: Node) -> Array:
|
|
1023
|
+
var names: Array = []
|
|
1024
|
+
if node is OptionButton:
|
|
1025
|
+
for i in (node as OptionButton).item_count:
|
|
1026
|
+
names.append((node as OptionButton).get_item_text(i))
|
|
1027
|
+
elif node is ItemList:
|
|
1028
|
+
for i in (node as ItemList).item_count:
|
|
1029
|
+
names.append((node as ItemList).get_item_text(i))
|
|
1030
|
+
elif node is TabBar:
|
|
1031
|
+
for i in (node as TabBar).tab_count:
|
|
1032
|
+
names.append((node as TabBar).get_tab_title(i))
|
|
1033
|
+
elif node is TabContainer:
|
|
1034
|
+
for i in (node as TabContainer).get_tab_count():
|
|
1035
|
+
names.append((node as TabContainer).get_tab_title(i))
|
|
1036
|
+
return names
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
## --- Edge behaviour checks ----------------------------------------------------
|
|
1040
|
+
|
|
1041
|
+
## `edge_focus{focused}`: tell the game its window lost focus, or has it back,
|
|
1042
|
+
## the way the engine does: the application and window focus notifications,
|
|
1043
|
+
## sent to every node. The window's real focus is left alone (a lockstep window
|
|
1044
|
+
## never takes it), so this is what the game is told, not what the desktop did.
|
|
1045
|
+
func _rpc_edge_focus(id: Variant, params: Dictionary) -> void:
|
|
1046
|
+
var focused := bool(params.get("focused", true))
|
|
1047
|
+
var root := get_tree().root
|
|
1048
|
+
if focused:
|
|
1049
|
+
root.propagate_notification(NOTIFICATION_APPLICATION_FOCUS_IN)
|
|
1050
|
+
root.propagate_notification(NOTIFICATION_WM_WINDOW_FOCUS_IN)
|
|
1051
|
+
else:
|
|
1052
|
+
root.propagate_notification(NOTIFICATION_APPLICATION_FOCUS_OUT)
|
|
1053
|
+
root.propagate_notification(NOTIFICATION_WM_WINDOW_FOCUS_OUT)
|
|
1054
|
+
_send_result(id, {"focused": focused, "paused": get_tree().paused})
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
## `window_size{width, height}`: resize the game's window; with neither, only
|
|
1058
|
+
## read it. Answers with the size before and after.
|
|
1059
|
+
func _rpc_window_size(id: Variant, params: Dictionary) -> void:
|
|
1060
|
+
var window := get_window()
|
|
1061
|
+
var before := window.size
|
|
1062
|
+
if params.has("width") and params.has("height"):
|
|
1063
|
+
window.size = Vector2i(clampi(int(params.get("width")), 160, 7680), clampi(int(params.get("height")), 120, 4320))
|
|
1064
|
+
_send_result(id, {"before": [before.x, before.y], "size": [window.size.x, window.size.y]})
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
## `edge_layout`: the visible controls a player can press that lie partly or
|
|
1068
|
+
## wholly outside what the window shows, which is what a resize can do to a
|
|
1069
|
+
## game that does not scale with its window.
|
|
1070
|
+
func _rpc_edge_layout(id: Variant) -> void:
|
|
1071
|
+
var window := get_window()
|
|
1072
|
+
var shown := Rect2(Vector2.ZERO, Vector2(window.size))
|
|
1073
|
+
var cut: Array = []
|
|
1074
|
+
var pressable := 0
|
|
1075
|
+
var stack: Array = [get_tree().root]
|
|
1076
|
+
while not stack.is_empty() and pressable < MAX_NODES:
|
|
1077
|
+
var node: Node = stack.pop_back()
|
|
1078
|
+
for child in node.get_children():
|
|
1079
|
+
if not _is_driver_node(child):
|
|
1080
|
+
stack.append(child)
|
|
1081
|
+
if not (node is BaseButton or node is LineEdit or node is Range or node is ItemList):
|
|
1082
|
+
continue
|
|
1083
|
+
var control := node as Control
|
|
1084
|
+
if not control.is_visible_in_tree() or control.size.x <= 0 or control.size.y <= 0:
|
|
1085
|
+
continue
|
|
1086
|
+
pressable += 1
|
|
1087
|
+
# Where the control is drawn, in window pixels.
|
|
1088
|
+
var xform := control.get_viewport().get_screen_transform() * control.get_global_transform_with_canvas() if control.get_viewport() != null else control.get_global_transform_with_canvas()
|
|
1089
|
+
var rect := Rect2(xform * Vector2.ZERO, Vector2.ZERO).expand(xform * control.size)
|
|
1090
|
+
var inside := rect.intersection(shown)
|
|
1091
|
+
if inside.get_area() < rect.get_area() * 0.75 and cut.size() < 12:
|
|
1092
|
+
var said := _text_of(control)
|
|
1093
|
+
cut.append({"name": str(control.name), "text": said.substr(0, 60), "rect": [rect.position.x, rect.position.y, rect.size.x, rect.size.y]})
|
|
1094
|
+
_send_result(id, {"window": [window.size.x, window.size.y], "pressable": pressable, "cut": cut, "paused": get_tree().paused})
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
## `user_files`: what the game has written under user://, without the engine's
|
|
1098
|
+
## own folders: each file's path, size and time, at most 200.
|
|
1099
|
+
func _rpc_user_files(id: Variant) -> void:
|
|
1100
|
+
var files: Array = []
|
|
1101
|
+
_list_user_files("user://", files)
|
|
1102
|
+
_send_result(id, {"dir": OS.get_user_data_dir(), "files": files})
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
func _list_user_files(dir_path: String, files: Array) -> void:
|
|
1106
|
+
if files.size() >= 200:
|
|
1107
|
+
return
|
|
1108
|
+
var dir := DirAccess.open(dir_path)
|
|
1109
|
+
if dir == null:
|
|
1110
|
+
return
|
|
1111
|
+
dir.list_dir_begin()
|
|
1112
|
+
var entry := dir.get_next()
|
|
1113
|
+
while not entry.is_empty():
|
|
1114
|
+
var full := dir_path.path_join(entry)
|
|
1115
|
+
if dir.current_is_dir():
|
|
1116
|
+
# The engine's own: logs, shader and pipeline caches.
|
|
1117
|
+
if not (entry in ["logs", "shader_cache", "vulkan", "pipelines"]) and not entry.begins_with("."):
|
|
1118
|
+
_list_user_files(full, files)
|
|
1119
|
+
elif files.size() < 200:
|
|
1120
|
+
var file := FileAccess.open(full, FileAccess.READ)
|
|
1121
|
+
var size := file.get_length() if file != null else -1
|
|
1122
|
+
files.append({"path": full.trim_prefix("user://"), "size": size, "modified": FileAccess.get_modified_time(full)})
|
|
1123
|
+
entry = dir.get_next()
|
|
1124
|
+
dir.list_dir_end()
|
|
1125
|
+
|
|
1126
|
+
|
|
618
1127
|
## The next drawn frame, or the last one. A window the desktop has covered or
|
|
619
1128
|
## moved to another space stops drawing, frame_post_draw never fires, and an
|
|
620
1129
|
## unbounded wait here hung the RPC until the client gave up on the run.
|
|
@@ -709,8 +1218,12 @@ func _advance_lockstep() -> void:
|
|
|
709
1218
|
return
|
|
710
1219
|
if _step_left > 0:
|
|
711
1220
|
_reassert_held()
|
|
1221
|
+
_echo_held_keys_by_tick()
|
|
712
1222
|
_sim_tick += 1
|
|
713
1223
|
_step_left -= 1
|
|
1224
|
+
if (_step_total - _step_left) in _strip_ticks:
|
|
1225
|
+
# After this frame is drawn: the picture of the tick that just ran.
|
|
1226
|
+
RenderingServer.frame_post_draw.connect(_grab_strip_frame, CONNECT_ONE_SHOT)
|
|
714
1227
|
if _step_left == 0:
|
|
715
1228
|
# A rate the game set during the step is the game's own (a hit stop,
|
|
716
1229
|
# a slow motion), so the next step resumes at it.
|
|
@@ -750,7 +1263,7 @@ func _rpc_step(id: Variant, params: Dictionary) -> void:
|
|
|
750
1263
|
if not _lockstep:
|
|
751
1264
|
_send_error(id, ERR_NOT_LOCKSTEP, "step needs lockstep mode")
|
|
752
1265
|
return
|
|
753
|
-
var problem := _check_params(params, {"ticks": "number", "events": "array", "digest": "boolean"})
|
|
1266
|
+
var problem := _check_params(params, {"ticks": "number", "events": "array", "digest": "boolean", "strip_at": "array"})
|
|
754
1267
|
if not problem.is_empty():
|
|
755
1268
|
_send_error(id, ERR_INVALID_PARAMS, problem)
|
|
756
1269
|
return
|
|
@@ -775,11 +1288,23 @@ func _rpc_step(id: Variant, params: Dictionary) -> void:
|
|
|
775
1288
|
return
|
|
776
1289
|
resolved.append(checked)
|
|
777
1290
|
_step_clicks = []
|
|
1291
|
+
_step_selects = []
|
|
778
1292
|
for checked in resolved:
|
|
779
1293
|
_apply_step_event(checked)
|
|
780
1294
|
_step_digest = bool(params.get("digest", true))
|
|
781
1295
|
_step_id = id
|
|
782
1296
|
_step_left = ticks
|
|
1297
|
+
_step_total = ticks
|
|
1298
|
+
# Frames for the strip are taken on these ticks of the step, counted from
|
|
1299
|
+
# one. They read the screen and change nothing the game can see. A step
|
|
1300
|
+
# that asks for them and `strip_new` starts a new strip.
|
|
1301
|
+
_strip_ticks = []
|
|
1302
|
+
if params.has("strip_at"):
|
|
1303
|
+
for at in params.get("strip_at"):
|
|
1304
|
+
_strip_ticks.append(int(at))
|
|
1305
|
+
if bool(params.get("strip_new", false)):
|
|
1306
|
+
_strip_frames = []
|
|
1307
|
+
_strip_base = _strip_thumb()
|
|
783
1308
|
# A game that draws randf() in _process whatever its delta (a screen shake)
|
|
784
1309
|
# spends the generator on every parked frame, and how many there were is the
|
|
785
1310
|
# wall clock's choice. Reseeding from the tick puts the generator back on the
|
|
@@ -827,6 +1352,18 @@ func _check_step_event(raw: Variant) -> Dictionary:
|
|
|
827
1352
|
return {"code": ERR_NODE_NOT_FOUND, "message": "clickable node not found: %s" % str(event.get("node_path"))}
|
|
828
1353
|
pos = at
|
|
829
1354
|
return {"type": "click", "position": pos, "params": event}
|
|
1355
|
+
"mouse":
|
|
1356
|
+
if not (str(event.get("kind", "")) in MOUSE_KINDS):
|
|
1357
|
+
return {"code": ERR_INVALID_PARAMS, "message": "a mouse event's kind is move, down, up or wheel"}
|
|
1358
|
+
var where: Variant = _mouse_target(event)
|
|
1359
|
+
if where == null:
|
|
1360
|
+
return {"code": ERR_NODE_NOT_FOUND, "message": "clickable node not found: %s" % str(event.get("node_path"))}
|
|
1361
|
+
return {"type": "mouse", "position": where, "params": event}
|
|
1362
|
+
"select":
|
|
1363
|
+
var plan := _select_plan(event)
|
|
1364
|
+
if plan.has("code"):
|
|
1365
|
+
return plan
|
|
1366
|
+
return {"type": "select", "plan": plan}
|
|
830
1367
|
return {"code": ERR_INVALID_PARAMS, "message": "unknown event type: %s" % str(event.get("type", ""))}
|
|
831
1368
|
|
|
832
1369
|
|
|
@@ -835,10 +1372,16 @@ func _apply_step_event(event: Dictionary) -> void:
|
|
|
835
1372
|
"key":
|
|
836
1373
|
var key_params: Dictionary = event["params"]
|
|
837
1374
|
_send_key_event(int(event["keycode"]), key_params)
|
|
1375
|
+
_track_repeat(int(event["keycode"]), key_params, _sim_tick)
|
|
838
1376
|
if bool(key_params.get("pressed", true)):
|
|
839
1377
|
_held_keys[int(event["keycode"])] = key_params
|
|
840
1378
|
else:
|
|
841
1379
|
_held_keys.erase(int(event["keycode"]))
|
|
1380
|
+
"mouse":
|
|
1381
|
+
var where: Vector2 = event["position"]
|
|
1382
|
+
_send_mouse_event(str((event["params"] as Dictionary).get("kind", "move")), where, event["params"])
|
|
1383
|
+
"select":
|
|
1384
|
+
_step_selects.append(_select_apply(event["plan"]))
|
|
842
1385
|
"click":
|
|
843
1386
|
var at: Vector2 = event["position"]
|
|
844
1387
|
_step_clicks.append([at.x, at.y])
|
|
@@ -859,7 +1402,7 @@ func _apply_step_event(event: Dictionary) -> void:
|
|
|
859
1402
|
|
|
860
1403
|
|
|
861
1404
|
func _lockstep_answer(with_digest: bool) -> Dictionary:
|
|
862
|
-
var out := {"tick": _sim_tick, "frame": Engine.get_process_frames(), "reasserted": _reasserted, "clicks": _step_clicks}
|
|
1405
|
+
var out := {"tick": _sim_tick, "frame": Engine.get_process_frames(), "reasserted": _reasserted, "clicks": _step_clicks, "selects": _step_selects}
|
|
863
1406
|
if with_digest:
|
|
864
1407
|
out["digest"] = _state_digest()
|
|
865
1408
|
return out
|
|
@@ -1013,6 +1556,14 @@ func _node_to_dict(node: Node, depth: int, max_depth: int, visible_only: bool, b
|
|
|
1013
1556
|
var text := _text_of(node)
|
|
1014
1557
|
if not text.is_empty():
|
|
1015
1558
|
out["text"] = text.substr(0, MAX_TEXT_CHARS)
|
|
1559
|
+
else:
|
|
1560
|
+
# A control that shows no text of its own (an icon button, a coloured
|
|
1561
|
+
# region) is still named when its author gave it a tooltip or an
|
|
1562
|
+
# accessible name. It is sent apart from `text`, which is only ever what
|
|
1563
|
+
# the screen shows.
|
|
1564
|
+
var label := _label_of(node)
|
|
1565
|
+
if not label.is_empty():
|
|
1566
|
+
out["label"] = label.substr(0, MAX_TEXT_CHARS)
|
|
1016
1567
|
|
|
1017
1568
|
if node is Node2D:
|
|
1018
1569
|
var p2: Vector2 = (node as Node2D).global_position
|
|
@@ -1024,9 +1575,33 @@ func _node_to_dict(node: Node, depth: int, max_depth: int, visible_only: bool, b
|
|
|
1024
1575
|
var rect: Rect2 = (node as Control).get_global_rect()
|
|
1025
1576
|
out["position"] = [rect.position.x, rect.position.y]
|
|
1026
1577
|
out["rect"] = [rect.position.x, rect.position.y, rect.size.x, rect.size.y]
|
|
1578
|
+
# Where a click on this Control lands, in the window pixels click takes:
|
|
1579
|
+
# the rect is in canvas units, which a stretched project draws at another size.
|
|
1580
|
+
var at := _window_position(node as Control)
|
|
1581
|
+
out["center"] = [at.x, at.y]
|
|
1027
1582
|
out["focus"] = (node as Control).has_focus()
|
|
1028
1583
|
if node is BaseButton:
|
|
1029
1584
|
out["disabled"] = (node as BaseButton).disabled
|
|
1585
|
+
# What a dropdown, a list or a tab bar offers and has chosen, and where a
|
|
1586
|
+
# slider stands: what `select` needs, and what a player reads off them.
|
|
1587
|
+
if node is OptionButton or node is ItemList or node is TabBar or node is TabContainer:
|
|
1588
|
+
var offered := _option_names(node)
|
|
1589
|
+
out["options"] = offered.slice(0, 20)
|
|
1590
|
+
var chosen := -1
|
|
1591
|
+
if node is OptionButton:
|
|
1592
|
+
chosen = (node as OptionButton).selected
|
|
1593
|
+
elif node is ItemList:
|
|
1594
|
+
var picked := (node as ItemList).get_selected_items()
|
|
1595
|
+
chosen = picked[0] if picked.size() > 0 else -1
|
|
1596
|
+
elif node is TabBar:
|
|
1597
|
+
chosen = (node as TabBar).current_tab
|
|
1598
|
+
else:
|
|
1599
|
+
chosen = (node as TabContainer).current_tab
|
|
1600
|
+
if chosen >= 0 and chosen < offered.size():
|
|
1601
|
+
out["selected"] = str(offered[chosen])
|
|
1602
|
+
elif node is Range and not (node is ProgressBar) and not (node is ScrollBar):
|
|
1603
|
+
out["value"] = (node as Range).value
|
|
1604
|
+
out["range"] = [(node as Range).min_value, (node as Range).max_value, (node as Range).step]
|
|
1030
1605
|
|
|
1031
1606
|
var groups: Array = []
|
|
1032
1607
|
for group in node.get_groups():
|
|
@@ -1088,6 +1663,19 @@ func _text_of(node: Node) -> String:
|
|
|
1088
1663
|
return ""
|
|
1089
1664
|
|
|
1090
1665
|
|
|
1666
|
+
## What a Control with no text is called: its tooltip, else its accessible
|
|
1667
|
+
## name (a property Godot gained after 4.2, so it is read by name).
|
|
1668
|
+
func _label_of(node: Node) -> String:
|
|
1669
|
+
if not (node is Control):
|
|
1670
|
+
return ""
|
|
1671
|
+
var tip := (node as Control).tooltip_text.strip_edges()
|
|
1672
|
+
if not tip.is_empty():
|
|
1673
|
+
return tip
|
|
1674
|
+
if "accessibility_name" in node:
|
|
1675
|
+
return str(node.get("accessibility_name")).strip_edges()
|
|
1676
|
+
return ""
|
|
1677
|
+
|
|
1678
|
+
|
|
1091
1679
|
## --- Author hook serialization ------------------------------------------------
|
|
1092
1680
|
|
|
1093
1681
|
## Converts a _ravensight_state() result into JSON-safe values: vectors become
|
|
@@ -1155,7 +1743,64 @@ func _resolve_keycode(raw: Variant) -> int:
|
|
|
1155
1743
|
"arrowdown": KEY_DOWN,
|
|
1156
1744
|
"arrowleft": KEY_LEFT,
|
|
1157
1745
|
"arrowright": KEY_RIGHT,
|
|
1746
|
+
"up": KEY_UP,
|
|
1747
|
+
"down": KEY_DOWN,
|
|
1748
|
+
"left": KEY_LEFT,
|
|
1749
|
+
"right": KEY_RIGHT,
|
|
1750
|
+
"del": KEY_DELETE,
|
|
1751
|
+
"delete": KEY_DELETE,
|
|
1752
|
+
"ins": KEY_INSERT,
|
|
1753
|
+
"insert": KEY_INSERT,
|
|
1754
|
+
"home": KEY_HOME,
|
|
1755
|
+
"end": KEY_END,
|
|
1756
|
+
"pageup": KEY_PAGEUP,
|
|
1757
|
+
"pgup": KEY_PAGEUP,
|
|
1758
|
+
"pagedown": KEY_PAGEDOWN,
|
|
1759
|
+
"pgdn": KEY_PAGEDOWN,
|
|
1760
|
+
"shift": KEY_SHIFT,
|
|
1761
|
+
"control": KEY_CTRL,
|
|
1762
|
+
"ctrl": KEY_CTRL,
|
|
1763
|
+
"alt": KEY_ALT,
|
|
1764
|
+
"option": KEY_ALT,
|
|
1765
|
+
"meta": KEY_META,
|
|
1766
|
+
"cmd": KEY_META,
|
|
1767
|
+
"command": KEY_META,
|
|
1768
|
+
"capslock": KEY_CAPSLOCK,
|
|
1769
|
+
"spacebar": KEY_SPACE,
|
|
1770
|
+
"comma": KEY_COMMA,
|
|
1771
|
+
"period": KEY_PERIOD,
|
|
1772
|
+
"slash": KEY_SLASH,
|
|
1773
|
+
"backslash": KEY_BACKSLASH,
|
|
1774
|
+
"semicolon": KEY_SEMICOLON,
|
|
1775
|
+
"apostrophe": KEY_APOSTROPHE,
|
|
1776
|
+
"quote": KEY_APOSTROPHE,
|
|
1777
|
+
"backquote": KEY_QUOTELEFT,
|
|
1778
|
+
"backtick": KEY_QUOTELEFT,
|
|
1779
|
+
"minus": KEY_MINUS,
|
|
1780
|
+
"equal": KEY_EQUAL,
|
|
1781
|
+
"plus": KEY_PLUS,
|
|
1782
|
+
"bracketleft": KEY_BRACKETLEFT,
|
|
1783
|
+
"bracketright": KEY_BRACKETRIGHT,
|
|
1784
|
+
"numpadenter": KEY_KP_ENTER,
|
|
1785
|
+
"numpadadd": KEY_KP_ADD,
|
|
1786
|
+
"numpadsubtract": KEY_KP_SUBTRACT,
|
|
1787
|
+
"numpadmultiply": KEY_KP_MULTIPLY,
|
|
1788
|
+
"numpaddivide": KEY_KP_DIVIDE,
|
|
1789
|
+
"numpaddecimal": KEY_KP_PERIOD,
|
|
1158
1790
|
}
|
|
1791
|
+
var compact := key_name.to_lower().replace(" ", "").replace("_", "")
|
|
1792
|
+
if aliases.has(compact):
|
|
1793
|
+
return int(aliases[compact])
|
|
1794
|
+
# F1 to F24 and the numpad digits, however they are capitalised.
|
|
1795
|
+
if compact.length() >= 2 and compact.begins_with("f") and compact.substr(1).is_valid_int():
|
|
1796
|
+
var n := int(compact.substr(1))
|
|
1797
|
+
if n >= 1 and n <= 24:
|
|
1798
|
+
return KEY_F1 + n - 1
|
|
1799
|
+
for prefix in ["numpad", "num", "kp"]:
|
|
1800
|
+
if compact.begins_with(prefix) and compact.substr(prefix.length()).is_valid_int():
|
|
1801
|
+
var digit := int(compact.substr(prefix.length()))
|
|
1802
|
+
if digit >= 0 and digit <= 9 and compact.length() == prefix.length() + 1:
|
|
1803
|
+
return KEY_KP_0 + digit
|
|
1159
1804
|
var lowered := key_name.to_lower()
|
|
1160
1805
|
if aliases.has(lowered):
|
|
1161
1806
|
return int(aliases[lowered])
|