ravensight-playtest 0.9.0 → 0.10.1

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 (67) hide show
  1. package/README.md +266 -44
  2. package/addons/ravensight_driver/driver.gd +704 -21
  3. package/docs/ADAPTERS.md +11 -7
  4. package/docs/NATIVE_RUNNER.md +3 -1
  5. package/docs/godot-driver.md +136 -13
  6. package/package.json +8 -6
  7. package/src/api/client.js +4 -3
  8. package/src/cli.js +114 -13
  9. package/src/commands/check.js +30 -4
  10. package/src/commands/fakeCore.js +14 -2
  11. package/src/commands/hosted.js +18 -4
  12. package/src/commands/init.js +17 -1
  13. package/src/commands/run.js +209 -14
  14. package/src/commands/upload.js +6 -2
  15. package/src/commands/validate.js +1 -1
  16. package/src/commands/validateHosted.js +50 -5
  17. package/src/config.js +33 -2
  18. package/src/hosted/archivePreflight.js +7 -7
  19. package/src/hosted/buildUpload.js +89 -8
  20. package/src/hosted/recordedRun.js +40 -1
  21. package/src/run/actionSelector.js +14 -3
  22. package/src/run/aggregate.js +57 -3
  23. package/src/run/anygame/controlbook.js +179 -0
  24. package/src/run/anygame/genre.js +179 -0
  25. package/src/run/anygame/index.js +258 -0
  26. package/src/run/anygame/language.js +336 -0
  27. package/src/run/anygame/memory.js +330 -0
  28. package/src/run/anygame/shared-hashes.json +10 -0
  29. package/src/run/anygame/shared.js +24 -0
  30. package/src/run/anygame/sound.js +342 -0
  31. package/src/run/args.js +75 -8
  32. package/src/run/captureCheck.js +161 -0
  33. package/src/run/choiceCheck.js +312 -0
  34. package/src/run/claimGate.js +236 -0
  35. package/src/run/context.js +254 -13
  36. package/src/run/drivers/godot-observation.js +93 -6
  37. package/src/run/drivers/godot.js +769 -46
  38. package/src/run/drivers/recording.js +24 -4
  39. package/src/run/drivers/web.js +1242 -77
  40. package/src/run/edgePass.js +731 -0
  41. package/src/run/fixLoop.js +5 -4
  42. package/src/run/focus.js +65 -0
  43. package/src/run/gamepad.js +108 -0
  44. package/src/run/godotEdgePass.js +235 -0
  45. package/src/run/godotTesterProbes.js +192 -0
  46. package/src/run/headings.js +21 -0
  47. package/src/run/honesty.js +642 -0
  48. package/src/run/inputs.js +256 -0
  49. package/src/run/marks.js +142 -0
  50. package/src/run/personaLoop.js +1128 -120
  51. package/src/run/phone.js +7 -0
  52. package/src/run/pixels.js +215 -0
  53. package/src/run/playClock.js +162 -0
  54. package/src/run/readiness.js +585 -0
  55. package/src/run/refusal.js +67 -0
  56. package/src/run/regions.js +119 -0
  57. package/src/run/report.js +14 -2
  58. package/src/run/reportChecks.js +487 -0
  59. package/src/run/resume.js +3 -2
  60. package/src/run/screenshots.js +161 -0
  61. package/src/run/strip.js +114 -0
  62. package/src/run/testerLedger.js +312 -0
  63. package/src/run/testerProbes.js +584 -0
  64. package/src/run/thinRun.js +102 -0
  65. package/src/run/timeFreeze.js +79 -0
  66. package/src/run/tools.js +454 -29
  67. package/src/runDefaults.js +1 -0
@@ -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.2.0"
33
+ const DRIVER_VERSION := "1.5.1"
34
34
  const DEFAULT_PORT := 47800
35
35
  const FEATURE_TAG := "ravensight_driver"
36
36
  const ADDON_DIR := "ravensight_driver"
@@ -87,6 +87,28 @@ 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
+ ## How many frames the driver drew itself because the window could not (see
106
+ ## _await_post_draw): reported by ping and with every screenshot.
107
+ var _forced_draws := 0
108
+ const KEY_REPEAT_DELAY_MS := 500
109
+ const KEY_REPEAT_INTERVAL_MS := 33
110
+ const WHEEL_NOTCH := 120.0
111
+ const MAX_WHEEL_NOTCHES := 40
90
112
 
91
113
  ## --- Lifecycle ----------------------------------------------------------------
92
114
 
@@ -182,6 +204,8 @@ func _on_sdk_event(event_name: String, data: Dictionary) -> void:
182
204
  func _process(_delta: float) -> void:
183
205
  if _lockstep:
184
206
  _advance_lockstep()
207
+ else:
208
+ _echo_held_keys_by_clock()
185
209
  _accept_connections()
186
210
  _read_client()
187
211
  _drain_inbox()
@@ -314,11 +338,20 @@ func _handle_line(line: String) -> void:
314
338
  "press_action": _rpc_press_action(id, params)
315
339
  "key": _rpc_key(id, params)
316
340
  "click": _rpc_click(id, params)
341
+ "mouse": _rpc_mouse(id, params)
317
342
  "wait_frames": _rpc_wait_frames(id, params)
318
343
  "seed": _rpc_seed(id, params)
319
344
  "step": _rpc_step(id, params)
320
345
  "digest": _send_result(id, _lockstep_answer(true))
321
346
  "screenshot": _rpc_screenshot(id, params)
347
+ "strip_begin": _rpc_strip_begin(id)
348
+ "strip_frame": _rpc_strip_frame(id)
349
+ "strip_status": _rpc_strip_status(id, params)
350
+ "select": _rpc_select(id, params)
351
+ "edge_focus": _rpc_edge_focus(id, params)
352
+ "window_size": _rpc_window_size(id, params)
353
+ "edge_layout": _rpc_edge_layout(id)
354
+ "user_files": _rpc_user_files(id)
322
355
  "set_time_scale": _rpc_set_time_scale(id, params)
323
356
  "list_actions": _send_result(id, {"actions": _action_names()})
324
357
  "quit": _rpc_quit(id, params)
@@ -394,6 +427,7 @@ func _rpc_ping(id: Variant) -> void:
394
427
  "tick": _sim_tick,
395
428
  "seed": _seed_value,
396
429
  "ticks_per_second": Engine.physics_ticks_per_second,
430
+ "forced_draws": _forced_draws,
397
431
  })
398
432
 
399
433
 
@@ -490,6 +524,7 @@ func _rpc_key(id: Variant, params: Dictionary) -> void:
490
524
  _send_error(id, ERR_INVALID_PARAMS, "unknown keycode: %s" % str(params.get("keycode")))
491
525
  return
492
526
  var event := _send_key_event(keycode, params)
527
+ _track_repeat(keycode, params, Time.get_ticks_msec())
493
528
  _send_result(id, {"ok": true, "keycode": keycode, "pressed": event.pressed})
494
529
 
495
530
 
@@ -498,15 +533,83 @@ func _send_key_event(keycode: int, params: Dictionary) -> InputEventKey:
498
533
  event.keycode = keycode
499
534
  event.physical_keycode = keycode
500
535
  event.pressed = bool(params.get("pressed", true))
536
+ event.echo = event.pressed and bool(params.get("echo", false))
501
537
  var unicode := int(params.get("unicode", 0))
502
538
  if unicode == 0:
503
539
  unicode = _unicode_for(params.get("keycode"))
504
540
  if unicode != 0:
505
541
  event.unicode = unicode
542
+ # A chord is its modifier held and its key pressed: the key event says which
543
+ # modifiers are down, as a real one does, so Shift+Tab is heard as Shift+Tab.
544
+ _note_modifier(keycode, event.pressed)
545
+ _stamp_modifiers(event)
506
546
  Input.parse_input_event(event)
507
547
  return event
508
548
 
509
549
 
550
+ ## Which modifier keys the driver holds down right now.
551
+ var _mods := {KEY_SHIFT: false, KEY_CTRL: false, KEY_ALT: false, KEY_META: false}
552
+
553
+
554
+ func _note_modifier(keycode: int, pressed: bool) -> void:
555
+ if _mods.has(keycode):
556
+ _mods[keycode] = pressed
557
+
558
+
559
+ func _stamp_modifiers(event: InputEventWithModifiers) -> void:
560
+ event.shift_pressed = bool(_mods[KEY_SHIFT])
561
+ event.ctrl_pressed = bool(_mods[KEY_CTRL])
562
+ event.alt_pressed = bool(_mods[KEY_ALT])
563
+ event.meta_pressed = bool(_mods[KEY_META])
564
+
565
+
566
+ ## A key pressed with `repeat` echoes while it is held: after the delay a
567
+ ## keyboard has, the game hears it again at a keyboard's rate, as an echo.
568
+ ## `since` is a tick count in lockstep and milliseconds otherwise.
569
+ func _track_repeat(keycode: int, params: Dictionary, since: int) -> void:
570
+ if not bool(params.get("pressed", true)):
571
+ _repeat_keys.erase(keycode)
572
+ return
573
+ if bool(params.get("repeat", false)) and not bool(params.get("echo", false)):
574
+ _repeat_keys[keycode] = {"params": params, "since": since, "sent": 0}
575
+
576
+
577
+ func _send_echo(keycode: int, entry: Dictionary) -> void:
578
+ var echo_params: Dictionary = (entry["params"] as Dictionary).duplicate()
579
+ echo_params["echo"] = true
580
+ echo_params["pressed"] = true
581
+ _send_key_event(keycode, echo_params)
582
+ entry["sent"] = int(entry["sent"]) + 1
583
+
584
+
585
+ ## Outside lockstep the echoes follow the clock, as a keyboard's do.
586
+ func _echo_held_keys_by_clock() -> void:
587
+ if _repeat_keys.is_empty():
588
+ return
589
+ var now := Time.get_ticks_msec()
590
+ for keycode in _repeat_keys:
591
+ var entry: Dictionary = _repeat_keys[keycode]
592
+ var held := now - int(entry["since"])
593
+ var due := 0 if held < KEY_REPEAT_DELAY_MS else 1 + int((held - KEY_REPEAT_DELAY_MS) / KEY_REPEAT_INTERVAL_MS)
594
+ if due > int(entry["sent"]):
595
+ _send_echo(int(keycode), entry)
596
+
597
+
598
+ ## In lockstep they follow the ticks, so a replay hears the same echoes on the
599
+ ## same ticks. Called once for every tick that runs.
600
+ func _echo_held_keys_by_tick() -> void:
601
+ if _repeat_keys.is_empty():
602
+ return
603
+ var tps := maxi(Engine.physics_ticks_per_second, 1)
604
+ var delay_ticks := maxi(int(round(KEY_REPEAT_DELAY_MS * tps / 1000.0)), 1)
605
+ var every := maxi(int(round(KEY_REPEAT_INTERVAL_MS * tps / 1000.0)), 1)
606
+ for keycode in _repeat_keys:
607
+ var entry: Dictionary = _repeat_keys[keycode]
608
+ var held := _sim_tick - int(entry["since"])
609
+ if held >= delay_ticks and (held - delay_ticks) % every == 0:
610
+ _send_echo(int(keycode), entry)
611
+
612
+
510
613
  func _rpc_click(id: Variant, params: Dictionary) -> void:
511
614
  var problem := _check_params(params, {
512
615
  "x": "number",
@@ -555,24 +658,122 @@ func _click_position(target: Node) -> Variant:
555
658
 
556
659
 
557
660
  func _send_click_events(pos: Vector2, params: Dictionary) -> void:
558
- var button := MOUSE_BUTTON_LEFT
661
+ _send_mouse_event("move", pos, params)
662
+ _send_mouse_event("down", pos, params)
663
+ _send_mouse_event("up", pos, params)
664
+
665
+
666
+ func _button_index(params: Dictionary) -> MouseButton:
559
667
  match str(params.get("button", "left")):
560
- "right": button = MOUSE_BUTTON_RIGHT
561
- "middle": button = MOUSE_BUTTON_MIDDLE
668
+ "right": return MOUSE_BUTTON_RIGHT
669
+ "middle": return MOUSE_BUTTON_MIDDLE
670
+ return MOUSE_BUTTON_LEFT
671
+
672
+
673
+ func _button_mask(button: MouseButton) -> int:
674
+ match button:
675
+ MOUSE_BUTTON_RIGHT: return MOUSE_BUTTON_MASK_RIGHT
676
+ MOUSE_BUTTON_MIDDLE: return MOUSE_BUTTON_MASK_MIDDLE
677
+ return MOUSE_BUTTON_MASK_LEFT
678
+
679
+
680
+ ## One mouse event, as a hand makes it: `move` carries the buttons that are
681
+ ## held, so a press, moves and a release are a drag; `wheel` is one press and
682
+ ## release of a wheel button per notch, at the pointer.
683
+ func _send_mouse_event(kind: String, pos: Vector2, params: Dictionary) -> void:
684
+ match kind:
685
+ "move":
686
+ var motion := InputEventMouseMotion.new()
687
+ motion.position = pos
688
+ motion.global_position = pos
689
+ motion.relative = pos - _mouse_pos
690
+ # A property Godot gained after 4.2, so it is set by name.
691
+ if "screen_relative" in motion:
692
+ motion.set("screen_relative", motion.relative)
693
+ motion.button_mask = _mouse_mask
694
+ _stamp_modifiers(motion)
695
+ _mouse_pos = pos
696
+ Input.parse_input_event(motion)
697
+ "down", "up":
698
+ var pressed := kind == "down"
699
+ var button := _button_index(params)
700
+ if pressed:
701
+ _mouse_mask |= _button_mask(button)
702
+ else:
703
+ _mouse_mask &= ~_button_mask(button)
704
+ var click := InputEventMouseButton.new()
705
+ click.button_index = button
706
+ click.position = pos
707
+ click.global_position = pos
708
+ click.pressed = pressed
709
+ click.double_click = pressed and bool(params.get("double", false))
710
+ click.button_mask = _mouse_mask
711
+ _stamp_modifiers(click)
712
+ _mouse_pos = pos
713
+ Input.parse_input_event(click)
714
+ "wheel":
715
+ _send_mouse_event("move", pos, params)
716
+ var dy := float(params.get("dy", 0.0))
717
+ var dx := float(params.get("dx", 0.0))
718
+ _send_wheel(pos, MOUSE_BUTTON_WHEEL_DOWN if dy > 0.0 else MOUSE_BUTTON_WHEEL_UP, absf(dy), params)
719
+ _send_wheel(pos, MOUSE_BUTTON_WHEEL_RIGHT if dx > 0.0 else MOUSE_BUTTON_WHEEL_LEFT, absf(dx), params)
720
+
721
+
722
+ func _send_wheel(pos: Vector2, button: MouseButton, amount: float, params: Dictionary) -> void:
723
+ if amount <= 0.0:
724
+ return
725
+ var notches: int = clampi(int(ceil(amount / WHEEL_NOTCH)), 1, MAX_WHEEL_NOTCHES)
726
+ for i in notches:
727
+ for pressed in [true, false]:
728
+ var wheel := InputEventMouseButton.new()
729
+ wheel.button_index = button
730
+ wheel.position = pos
731
+ wheel.global_position = pos
732
+ wheel.pressed = pressed
733
+ wheel.factor = 1.0
734
+ wheel.button_mask = _mouse_mask
735
+ _stamp_modifiers(wheel)
736
+ if bool(params.get("ctrl", false)):
737
+ wheel.ctrl_pressed = true
738
+ if bool(params.get("shift", false)):
739
+ wheel.shift_pressed = true
740
+ if bool(params.get("alt", false)):
741
+ wheel.alt_pressed = true
742
+ Input.parse_input_event(wheel)
743
+
744
+
745
+ const MOUSE_KINDS := ["move", "down", "up", "wheel"]
746
+
747
+
748
+ ## Where a mouse event lands: a node's centre, or the point given. Null when a
749
+ ## named node cannot be pointed at.
750
+ func _mouse_target(params: Dictionary) -> Variant:
751
+ if params.has("node_path"):
752
+ return _click_position(get_node_or_null(NodePath(str(params.get("node_path")))))
753
+ return Vector2(float(params.get("x", 0.0)), float(params.get("y", 0.0)))
562
754
 
563
- var motion := InputEventMouseMotion.new()
564
- motion.position = pos
565
- motion.global_position = pos
566
- Input.parse_input_event(motion)
567
755
 
568
- for pressed in [true, false]:
569
- var click := InputEventMouseButton.new()
570
- click.button_index = button
571
- click.position = pos
572
- click.global_position = pos
573
- click.pressed = pressed
574
- click.double_click = pressed and bool(params.get("double", false))
575
- Input.parse_input_event(click)
756
+ ## `mouse{kind, x, y | node_path, button, double, dx, dy}`: one pointer event.
757
+ ## A hover is a move; a held press is a down, time, and an up; a drag is a
758
+ ## down, moves and an up; a scroll is a wheel.
759
+ func _rpc_mouse(id: Variant, params: Dictionary) -> void:
760
+ var problem := _check_params(params, {
761
+ "kind": "string", "x": "number", "y": "number", "node_path": "string", "button": "string",
762
+ "double": "boolean", "dx": "number", "dy": "number", "ctrl": "boolean", "shift": "boolean", "alt": "boolean",
763
+ })
764
+ if not problem.is_empty():
765
+ _send_error(id, ERR_INVALID_PARAMS, problem)
766
+ return
767
+ var kind := str(params.get("kind", ""))
768
+ if not (kind in MOUSE_KINDS):
769
+ _send_error(id, ERR_INVALID_PARAMS, "kind must be move, down, up or wheel")
770
+ return
771
+ var at: Variant = _mouse_target(params)
772
+ if at == null:
773
+ _send_error(id, ERR_NODE_NOT_FOUND, "clickable node not found: %s" % str(params.get("node_path")))
774
+ return
775
+ _send_mouse_event(kind, at, params)
776
+ _send_result(id, {"ok": true, "position": [(at as Vector2).x, (at as Vector2).y]})
576
777
 
577
778
 
578
779
  func _rpc_wait_frames(id: Variant, params: Dictionary) -> void:
@@ -585,10 +786,14 @@ func _rpc_wait_frames(id: Variant, params: Dictionary) -> void:
585
786
 
586
787
 
587
788
  func _rpc_screenshot(id: Variant, params: Dictionary) -> void:
588
- var problem := _check_params(params, {"max_width": "number", "region": "array"})
789
+ var problem := _check_params(params, {"max_width": "number", "region": "array", "format": "string", "quality": "number", "strip": "boolean"})
589
790
  if not problem.is_empty():
590
791
  _send_error(id, ERR_INVALID_PARAMS, problem)
591
792
  return
793
+ var format := str(params.get("format", "png"))
794
+ if format != "png" and format != "jpeg":
795
+ _send_error(id, ERR_INVALID_PARAMS, "format must be png or jpeg")
796
+ return
592
797
  if params.has("region") and not _is_number_quad(params.get("region")):
593
798
  _send_error(id, ERR_INVALID_PARAMS, "region must be four numbers: [x, y, width, height]")
594
799
  return
@@ -603,22 +808,345 @@ func _rpc_screenshot(id: Variant, params: Dictionary) -> void:
603
808
  if params.has("region"):
604
809
  var region: Array = params.get("region")
605
810
  image = image.get_region(Rect2i(int(region[0]), int(region[1]), int(region[2]), int(region[3])))
811
+ # The size before any scaling is the size click coordinates are in.
812
+ var window_size := [image.get_width(), image.get_height()]
606
813
  var max_width: int = maxi(int(params.get("max_width", 1280)), 1)
607
814
  if image.get_width() > max_width:
608
815
  var height := maxi(1, int(round(image.get_height() * float(max_width) / image.get_width())))
609
816
  image.resize(max_width, height, Image.INTERPOLATE_BILINEAR)
817
+ # The frames taken while the last input played go in a row under the picture,
818
+ # in the same image; the picture itself keeps its place, so a point on it is
819
+ # still the point a click lands on.
820
+ var strip_count := 0
821
+ if bool(params.get("strip", false)) and not _strip_frames.is_empty():
822
+ strip_count = _strip_frames.size()
823
+ image = _with_strip(image)
824
+ _strip_frames = []
825
+ _strip_base = null
826
+ # A JPEG is for a model to look at: the same picture in a fraction of the
827
+ # bytes. Evidence is saved as PNG, which is the default.
828
+ var bytes: PackedByteArray
829
+ if format == "jpeg":
830
+ bytes = image.save_jpg_to_buffer(clampf(float(params.get("quality", 0.7)), 0.1, 1.0))
831
+ else:
832
+ bytes = image.save_png_to_buffer()
610
833
  _send_result(id, {
611
- "format": "png",
834
+ "format": format,
835
+ "window": window_size,
612
836
  "width": image.get_width(),
613
837
  "height": image.get_height(),
614
- "data": Marshalls.raw_to_base64(image.save_png_to_buffer()),
838
+ "strip": strip_count,
839
+ "forced_draws": _forced_draws,
840
+ "data": Marshalls.raw_to_base64(bytes),
615
841
  })
616
842
 
617
843
 
844
+ ## --- The frame strip ----------------------------------------------------------
845
+
846
+ ## The screen as a small image, or null with no viewport to read.
847
+ func _strip_thumb() -> Image:
848
+ if _is_headless():
849
+ return null
850
+ # A window that cannot draw holds an old frame: draw the one the game is on.
851
+ if not _window_can_draw():
852
+ _draw_now()
853
+ var image := get_viewport().get_texture().get_image()
854
+ if image == null or image.is_empty():
855
+ return null
856
+ image.convert(Image.FORMAT_RGB8)
857
+ image.resize(maxi(1, int(round(image.get_width() * STRIP_SCALE))), maxi(1, int(round(image.get_height() * STRIP_SCALE))), Image.INTERPOLATE_BILINEAR)
858
+ return image
859
+
860
+
861
+ func _grab_strip_frame() -> void:
862
+ if _strip_frames.size() >= MAX_STRIP_FRAMES:
863
+ return
864
+ var thumb := _strip_thumb()
865
+ if thumb != null:
866
+ _strip_frames.append(thumb)
867
+
868
+
869
+ ## Whether two small frames differ by more than a blinking cursor: more than one
870
+ ## cell in a hundred of a coarse grid changed by more than a tenth of full scale.
871
+ func _strip_differs(a: Image, b: Image) -> bool:
872
+ if a == null or b == null:
873
+ return false
874
+ var x: Image = a.duplicate()
875
+ var y: Image = b.duplicate()
876
+ x.resize(48, 27, Image.INTERPOLATE_BILINEAR)
877
+ y.resize(48, 27, Image.INTERPOLATE_BILINEAR)
878
+ var xs := x.get_data()
879
+ var ys := y.get_data()
880
+ if xs.size() != ys.size():
881
+ return true
882
+ var changed := 0
883
+ var cells := xs.size() / 3
884
+ for i in cells:
885
+ 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])
886
+ if d > 76:
887
+ changed += 1
888
+ return changed * 100 > cells
889
+
890
+
891
+ ## The picture with the strip's frames in a row under it.
892
+ func _with_strip(image: Image) -> Image:
893
+ var main: Image = image.duplicate()
894
+ main.convert(Image.FORMAT_RGB8)
895
+ var w := main.get_width()
896
+ var h := main.get_height()
897
+ var cell_w := maxi(1, int(round(w * STRIP_SCALE)))
898
+ var cell_h := maxi(1, int(round(h * STRIP_SCALE)))
899
+ var out := Image.create(w, h + cell_h, false, Image.FORMAT_RGB8)
900
+ out.fill(Color(0.07, 0.07, 0.07))
901
+ out.blit_rect(main, Rect2i(0, 0, w, h), Vector2i(0, 0))
902
+ for i in _strip_frames.size():
903
+ var frame: Image = (_strip_frames[i] as Image).duplicate()
904
+ frame.resize(cell_w, cell_h, Image.INTERPOLATE_BILINEAR)
905
+ out.blit_rect(frame, Rect2i(0, 0, cell_w, cell_h), Vector2i(i * cell_w, h))
906
+ # A bar between the frames, so four of them never read as one picture.
907
+ out.fill_rect(Rect2i(i * cell_w, h, 3, cell_h), Color(0.96, 0.77, 0.26))
908
+ return out
909
+
910
+
911
+ ## `strip_begin`: forget any frames, and keep the screen as it is now to compare
912
+ ## the frames with. For an input played on the wall clock; a lockstep step takes
913
+ ## `strip_at` instead.
914
+ func _rpc_strip_begin(id: Variant) -> void:
915
+ _strip_frames = []
916
+ _strip_base = _strip_thumb()
917
+ _send_result(id, {"ok": _strip_base != null})
918
+
919
+
920
+ ## `strip_frame`: take one frame now.
921
+ func _rpc_strip_frame(id: Variant) -> void:
922
+ if _is_headless():
923
+ _send_result(id, {"frames": 0})
924
+ return
925
+ await _await_post_draw()
926
+ _grab_strip_frame()
927
+ _send_result(id, {"frames": _strip_frames.size()})
928
+
929
+
930
+ ## `strip_status{clear}`: how many frames were taken and whether the game moved
931
+ ## in them: some frame differs from the one before it, the first from the screen
932
+ ## before the input. `ended_as_began` compares the screen now with that one.
933
+ func _rpc_strip_status(id: Variant, params: Dictionary) -> void:
934
+ var moved := false
935
+ var previous: Image = _strip_base
936
+ for frame in _strip_frames:
937
+ if _strip_differs(previous, frame):
938
+ moved = true
939
+ previous = frame
940
+ var ended := false
941
+ if not _is_headless() and _strip_base != null:
942
+ await _await_post_draw()
943
+ ended = not _strip_differs(_strip_base, _strip_thumb())
944
+ var count := _strip_frames.size()
945
+ if bool(params.get("clear", false)) or not moved:
946
+ _strip_frames = []
947
+ _strip_base = null
948
+ _send_result(id, {"frames": count, "moved": moved, "ended_as_began": ended})
949
+
950
+
951
+ ## --- Dropdowns, sliders and lists ---------------------------------------------
952
+
953
+ ## `select{node_path, option | index | value}`: choose an option of an
954
+ ## OptionButton, an ItemList or a tab bar by its text or its place, or set a
955
+ ## slider or a spin box to a value. The control answers as it does to a player:
956
+ ## it shows the choice and sends the signal a pick or a drag would.
957
+ func _rpc_select(id: Variant, params: Dictionary) -> void:
958
+ var problem := _check_params(params, {"node_path": "string", "option": "string", "index": "number", "value": "number"})
959
+ if not problem.is_empty():
960
+ _send_error(id, ERR_INVALID_PARAMS, problem)
961
+ return
962
+ var plan := _select_plan(params)
963
+ if plan.has("code"):
964
+ _send_error(id, int(plan["code"]), str(plan["message"]), plan.get("data"))
965
+ return
966
+ _send_result(id, _select_apply(plan))
967
+
968
+
969
+ ## What a select would do, checked and not yet done: the node and the option's
970
+ ## place or the value, or the error that refuses it.
971
+ func _select_plan(params: Dictionary) -> Dictionary:
972
+ var node := get_node_or_null(NodePath(str(params.get("node_path", ""))))
973
+ if node == null:
974
+ return {"code": ERR_NODE_NOT_FOUND, "message": "clickable node not found: %s" % str(params.get("node_path", ""))}
975
+ if node is Range:
976
+ var range_node := node as Range
977
+ if not params.has("value"):
978
+ 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)]}
979
+ if node is Slider and not (node as Slider).editable:
980
+ return {"code": ERR_INVALID_PARAMS, "message": "that slider is not editable"}
981
+ 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()]}
984
+ var names: Array = _option_names(node)
985
+ var index := -1
986
+ if params.has("index"):
987
+ index = int(params.get("index"))
988
+ elif params.has("option"):
989
+ var wanted := str(params.get("option")).strip_edges().to_lower()
990
+ for i in names.size():
991
+ if str(names[i]).strip_edges().to_lower() == wanted:
992
+ index = i
993
+ break
994
+ if index < 0:
995
+ for i in names.size():
996
+ if str(names[i]).to_lower().contains(wanted):
997
+ index = i
998
+ 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])}
1004
+
1005
+
1006
+ func _select_apply(plan: Dictionary) -> Dictionary:
1007
+ var node: Node = plan["node"]
1008
+ if str(plan["kind"]) == "range":
1009
+ var range_node := node as Range
1010
+ var before := range_node.value
1011
+ range_node.value = float(plan["value"])
1012
+ if node is Slider:
1013
+ (node as Slider).drag_ended.emit(not is_equal_approx(before, range_node.value))
1014
+ return {"kind": "range", "value": range_node.value, "min": range_node.min_value, "max": range_node.max_value}
1015
+ var index := int(plan["index"])
1016
+ if node is OptionButton:
1017
+ (node as OptionButton).select(index)
1018
+ (node as OptionButton).item_selected.emit(index)
1019
+ elif node is ItemList:
1020
+ (node as ItemList).select(index)
1021
+ (node as ItemList).item_selected.emit(index)
1022
+ elif node is TabBar:
1023
+ (node as TabBar).current_tab = index
1024
+ elif node is TabContainer:
1025
+ (node as TabContainer).current_tab = index
1026
+ return {"kind": "option", "index": index, "option": str(plan["option"])}
1027
+
1028
+
1029
+ ## What a control offers to choose from, as the text a player reads.
1030
+ func _option_names(node: Node) -> Array:
1031
+ var names: Array = []
1032
+ if node is OptionButton:
1033
+ for i in (node as OptionButton).item_count:
1034
+ names.append((node as OptionButton).get_item_text(i))
1035
+ elif node is ItemList:
1036
+ for i in (node as ItemList).item_count:
1037
+ names.append((node as ItemList).get_item_text(i))
1038
+ elif node is TabBar:
1039
+ for i in (node as TabBar).tab_count:
1040
+ names.append((node as TabBar).get_tab_title(i))
1041
+ elif node is TabContainer:
1042
+ for i in (node as TabContainer).get_tab_count():
1043
+ names.append((node as TabContainer).get_tab_title(i))
1044
+ return names
1045
+
1046
+
1047
+ ## --- Edge behaviour checks ----------------------------------------------------
1048
+
1049
+ ## `edge_focus{focused}`: tell the game its window lost focus, or has it back,
1050
+ ## the way the engine does: the application and window focus notifications,
1051
+ ## sent to every node. The window's real focus is left alone (a lockstep window
1052
+ ## never takes it), so this is what the game is told, not what the desktop did.
1053
+ func _rpc_edge_focus(id: Variant, params: Dictionary) -> void:
1054
+ var focused := bool(params.get("focused", true))
1055
+ var root := get_tree().root
1056
+ if focused:
1057
+ root.propagate_notification(NOTIFICATION_APPLICATION_FOCUS_IN)
1058
+ root.propagate_notification(NOTIFICATION_WM_WINDOW_FOCUS_IN)
1059
+ else:
1060
+ root.propagate_notification(NOTIFICATION_APPLICATION_FOCUS_OUT)
1061
+ root.propagate_notification(NOTIFICATION_WM_WINDOW_FOCUS_OUT)
1062
+ _send_result(id, {"focused": focused, "paused": get_tree().paused})
1063
+
1064
+
1065
+ ## `window_size{width, height}`: resize the game's window; with neither, only
1066
+ ## read it. Answers with the size before and after.
1067
+ func _rpc_window_size(id: Variant, params: Dictionary) -> void:
1068
+ var window := get_window()
1069
+ var before := window.size
1070
+ if params.has("width") and params.has("height"):
1071
+ window.size = Vector2i(clampi(int(params.get("width")), 160, 7680), clampi(int(params.get("height")), 120, 4320))
1072
+ _send_result(id, {"before": [before.x, before.y], "size": [window.size.x, window.size.y]})
1073
+
1074
+
1075
+ ## `edge_layout`: the visible controls a player can press that lie partly or
1076
+ ## wholly outside what the window shows, which is what a resize can do to a
1077
+ ## game that does not scale with its window.
1078
+ func _rpc_edge_layout(id: Variant) -> void:
1079
+ var window := get_window()
1080
+ var shown := Rect2(Vector2.ZERO, Vector2(window.size))
1081
+ var cut: Array = []
1082
+ var pressable := 0
1083
+ var stack: Array = [get_tree().root]
1084
+ while not stack.is_empty() and pressable < MAX_NODES:
1085
+ var node: Node = stack.pop_back()
1086
+ for child in node.get_children():
1087
+ if not _is_driver_node(child):
1088
+ stack.append(child)
1089
+ if not (node is BaseButton or node is LineEdit or node is Range or node is ItemList):
1090
+ continue
1091
+ var control := node as Control
1092
+ if not control.is_visible_in_tree() or control.size.x <= 0 or control.size.y <= 0:
1093
+ continue
1094
+ pressable += 1
1095
+ # Where the control is drawn, in window pixels.
1096
+ 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()
1097
+ var rect := Rect2(xform * Vector2.ZERO, Vector2.ZERO).expand(xform * control.size)
1098
+ var inside := rect.intersection(shown)
1099
+ if inside.get_area() < rect.get_area() * 0.75 and cut.size() < 12:
1100
+ var said := _text_of(control)
1101
+ cut.append({"name": str(control.name), "text": said.substr(0, 60), "rect": [rect.position.x, rect.position.y, rect.size.x, rect.size.y]})
1102
+ _send_result(id, {"window": [window.size.x, window.size.y], "pressable": pressable, "cut": cut, "paused": get_tree().paused})
1103
+
1104
+
1105
+ ## `user_files`: what the game has written under user://, without the engine's
1106
+ ## own folders: each file's path, size and time, at most 200.
1107
+ func _rpc_user_files(id: Variant) -> void:
1108
+ var files: Array = []
1109
+ _list_user_files("user://", files)
1110
+ _send_result(id, {"dir": OS.get_user_data_dir(), "files": files})
1111
+
1112
+
1113
+ func _list_user_files(dir_path: String, files: Array) -> void:
1114
+ if files.size() >= 200:
1115
+ return
1116
+ var dir := DirAccess.open(dir_path)
1117
+ if dir == null:
1118
+ return
1119
+ dir.list_dir_begin()
1120
+ var entry := dir.get_next()
1121
+ while not entry.is_empty():
1122
+ var full := dir_path.path_join(entry)
1123
+ if dir.current_is_dir():
1124
+ # The engine's own: logs, shader and pipeline caches.
1125
+ if not (entry in ["logs", "shader_cache", "vulkan", "pipelines"]) and not entry.begins_with("."):
1126
+ _list_user_files(full, files)
1127
+ elif files.size() < 200:
1128
+ var file := FileAccess.open(full, FileAccess.READ)
1129
+ var size := file.get_length() if file != null else -1
1130
+ files.append({"path": full.trim_prefix("user://"), "size": size, "modified": FileAccess.get_modified_time(full)})
1131
+ entry = dir.get_next()
1132
+ dir.list_dir_end()
1133
+
1134
+
618
1135
  ## The next drawn frame, or the last one. A window the desktop has covered or
619
1136
  ## moved to another space stops drawing, frame_post_draw never fires, and an
620
1137
  ## unbounded wait here hung the RPC until the client gave up on the run.
1138
+ ##
1139
+ ## Reading the viewport then gave the last frame the window drew, which on a
1140
+ ## minimized, covered or parked window was a frame from many inputs ago: a run
1141
+ ## played to the end of a game while every screenshot and the whole video stayed
1142
+ ## on its first screen. So a window that cannot draw, or a wait that saw no frame
1143
+ ## drawn, draws one here: the viewports are rendered without presenting them, so
1144
+ ## the picture read next is the game as it is now. Drawing runs no game code and
1145
+ ## advances no game time, so a lockstep run stays where it was.
621
1146
  func _await_post_draw() -> void:
1147
+ if not _window_can_draw():
1148
+ _draw_now()
1149
+ return
622
1150
  var drawn := [false]
623
1151
  var mark := func() -> void: drawn[0] = true
624
1152
  RenderingServer.frame_post_draw.connect(mark, CONNECT_ONE_SHOT)
@@ -628,6 +1156,21 @@ func _await_post_draw() -> void:
628
1156
  return
629
1157
  if RenderingServer.frame_post_draw.is_connected(mark):
630
1158
  RenderingServer.frame_post_draw.disconnect(mark)
1159
+ _draw_now()
1160
+
1161
+
1162
+ ## Whether the desktop lets the game's window draw a frame: false while it is
1163
+ ## minimized, and on some desktops while it is covered or on another space.
1164
+ func _window_can_draw() -> bool:
1165
+ if _is_headless():
1166
+ return false
1167
+ return DisplayServer.window_can_draw(get_window().get_window_id())
1168
+
1169
+
1170
+ ## Render every viewport once, without presenting it to the screen.
1171
+ func _draw_now() -> void:
1172
+ _forced_draws += 1
1173
+ RenderingServer.force_draw(false, 0.0)
631
1174
 
632
1175
 
633
1176
  func _rpc_set_time_scale(id: Variant, params: Dictionary) -> void:
@@ -709,8 +1252,16 @@ func _advance_lockstep() -> void:
709
1252
  return
710
1253
  if _step_left > 0:
711
1254
  _reassert_held()
1255
+ _echo_held_keys_by_tick()
712
1256
  _sim_tick += 1
713
1257
  _step_left -= 1
1258
+ if (_step_total - _step_left) in _strip_ticks:
1259
+ # After this frame is drawn: the picture of the tick that just ran. A
1260
+ # window that cannot draw gets the frame drawn at the end of this one.
1261
+ if _window_can_draw():
1262
+ RenderingServer.frame_post_draw.connect(_grab_strip_frame, CONNECT_ONE_SHOT)
1263
+ else:
1264
+ _grab_strip_frame.call_deferred()
714
1265
  if _step_left == 0:
715
1266
  # A rate the game set during the step is the game's own (a hit stop,
716
1267
  # a slow motion), so the next step resumes at it.
@@ -750,7 +1301,7 @@ func _rpc_step(id: Variant, params: Dictionary) -> void:
750
1301
  if not _lockstep:
751
1302
  _send_error(id, ERR_NOT_LOCKSTEP, "step needs lockstep mode")
752
1303
  return
753
- var problem := _check_params(params, {"ticks": "number", "events": "array", "digest": "boolean"})
1304
+ var problem := _check_params(params, {"ticks": "number", "events": "array", "digest": "boolean", "strip_at": "array"})
754
1305
  if not problem.is_empty():
755
1306
  _send_error(id, ERR_INVALID_PARAMS, problem)
756
1307
  return
@@ -775,11 +1326,23 @@ func _rpc_step(id: Variant, params: Dictionary) -> void:
775
1326
  return
776
1327
  resolved.append(checked)
777
1328
  _step_clicks = []
1329
+ _step_selects = []
778
1330
  for checked in resolved:
779
1331
  _apply_step_event(checked)
780
1332
  _step_digest = bool(params.get("digest", true))
781
1333
  _step_id = id
782
1334
  _step_left = ticks
1335
+ _step_total = ticks
1336
+ # Frames for the strip are taken on these ticks of the step, counted from
1337
+ # one. They read the screen and change nothing the game can see. A step
1338
+ # that asks for them and `strip_new` starts a new strip.
1339
+ _strip_ticks = []
1340
+ if params.has("strip_at"):
1341
+ for at in params.get("strip_at"):
1342
+ _strip_ticks.append(int(at))
1343
+ if bool(params.get("strip_new", false)):
1344
+ _strip_frames = []
1345
+ _strip_base = _strip_thumb()
783
1346
  # A game that draws randf() in _process whatever its delta (a screen shake)
784
1347
  # spends the generator on every parked frame, and how many there were is the
785
1348
  # wall clock's choice. Reseeding from the tick puts the generator back on the
@@ -827,6 +1390,18 @@ func _check_step_event(raw: Variant) -> Dictionary:
827
1390
  return {"code": ERR_NODE_NOT_FOUND, "message": "clickable node not found: %s" % str(event.get("node_path"))}
828
1391
  pos = at
829
1392
  return {"type": "click", "position": pos, "params": event}
1393
+ "mouse":
1394
+ if not (str(event.get("kind", "")) in MOUSE_KINDS):
1395
+ return {"code": ERR_INVALID_PARAMS, "message": "a mouse event's kind is move, down, up or wheel"}
1396
+ var where: Variant = _mouse_target(event)
1397
+ if where == null:
1398
+ return {"code": ERR_NODE_NOT_FOUND, "message": "clickable node not found: %s" % str(event.get("node_path"))}
1399
+ return {"type": "mouse", "position": where, "params": event}
1400
+ "select":
1401
+ var plan := _select_plan(event)
1402
+ if plan.has("code"):
1403
+ return plan
1404
+ return {"type": "select", "plan": plan}
830
1405
  return {"code": ERR_INVALID_PARAMS, "message": "unknown event type: %s" % str(event.get("type", ""))}
831
1406
 
832
1407
 
@@ -835,10 +1410,16 @@ func _apply_step_event(event: Dictionary) -> void:
835
1410
  "key":
836
1411
  var key_params: Dictionary = event["params"]
837
1412
  _send_key_event(int(event["keycode"]), key_params)
1413
+ _track_repeat(int(event["keycode"]), key_params, _sim_tick)
838
1414
  if bool(key_params.get("pressed", true)):
839
1415
  _held_keys[int(event["keycode"])] = key_params
840
1416
  else:
841
1417
  _held_keys.erase(int(event["keycode"]))
1418
+ "mouse":
1419
+ var where: Vector2 = event["position"]
1420
+ _send_mouse_event(str((event["params"] as Dictionary).get("kind", "move")), where, event["params"])
1421
+ "select":
1422
+ _step_selects.append(_select_apply(event["plan"]))
842
1423
  "click":
843
1424
  var at: Vector2 = event["position"]
844
1425
  _step_clicks.append([at.x, at.y])
@@ -859,7 +1440,7 @@ func _apply_step_event(event: Dictionary) -> void:
859
1440
 
860
1441
 
861
1442
  func _lockstep_answer(with_digest: bool) -> Dictionary:
862
- var out := {"tick": _sim_tick, "frame": Engine.get_process_frames(), "reasserted": _reasserted, "clicks": _step_clicks}
1443
+ var out := {"tick": _sim_tick, "frame": Engine.get_process_frames(), "reasserted": _reasserted, "clicks": _step_clicks, "selects": _step_selects}
863
1444
  if with_digest:
864
1445
  out["digest"] = _state_digest()
865
1446
  return out
@@ -1013,6 +1594,14 @@ func _node_to_dict(node: Node, depth: int, max_depth: int, visible_only: bool, b
1013
1594
  var text := _text_of(node)
1014
1595
  if not text.is_empty():
1015
1596
  out["text"] = text.substr(0, MAX_TEXT_CHARS)
1597
+ else:
1598
+ # A control that shows no text of its own (an icon button, a coloured
1599
+ # region) is still named when its author gave it a tooltip or an
1600
+ # accessible name. It is sent apart from `text`, which is only ever what
1601
+ # the screen shows.
1602
+ var label := _label_of(node)
1603
+ if not label.is_empty():
1604
+ out["label"] = label.substr(0, MAX_TEXT_CHARS)
1016
1605
 
1017
1606
  if node is Node2D:
1018
1607
  var p2: Vector2 = (node as Node2D).global_position
@@ -1024,9 +1613,33 @@ func _node_to_dict(node: Node, depth: int, max_depth: int, visible_only: bool, b
1024
1613
  var rect: Rect2 = (node as Control).get_global_rect()
1025
1614
  out["position"] = [rect.position.x, rect.position.y]
1026
1615
  out["rect"] = [rect.position.x, rect.position.y, rect.size.x, rect.size.y]
1616
+ # Where a click on this Control lands, in the window pixels click takes:
1617
+ # the rect is in canvas units, which a stretched project draws at another size.
1618
+ var at := _window_position(node as Control)
1619
+ out["center"] = [at.x, at.y]
1027
1620
  out["focus"] = (node as Control).has_focus()
1028
1621
  if node is BaseButton:
1029
1622
  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:
1626
+ var offered := _option_names(node)
1627
+ out["options"] = offered.slice(0, 20)
1628
+ var chosen := -1
1629
+ if node is OptionButton:
1630
+ chosen = (node as OptionButton).selected
1631
+ elif node is ItemList:
1632
+ var picked := (node as ItemList).get_selected_items()
1633
+ chosen = picked[0] if picked.size() > 0 else -1
1634
+ elif node is TabBar:
1635
+ chosen = (node as TabBar).current_tab
1636
+ else:
1637
+ chosen = (node as TabContainer).current_tab
1638
+ if chosen >= 0 and chosen < offered.size():
1639
+ out["selected"] = str(offered[chosen])
1640
+ elif node is Range and not (node is ProgressBar) and not (node is ScrollBar):
1641
+ out["value"] = (node as Range).value
1642
+ out["range"] = [(node as Range).min_value, (node as Range).max_value, (node as Range).step]
1030
1643
 
1031
1644
  var groups: Array = []
1032
1645
  for group in node.get_groups():
@@ -1088,6 +1701,19 @@ func _text_of(node: Node) -> String:
1088
1701
  return ""
1089
1702
 
1090
1703
 
1704
+ ## What a Control with no text is called: its tooltip, else its accessible
1705
+ ## name (a property Godot gained after 4.2, so it is read by name).
1706
+ func _label_of(node: Node) -> String:
1707
+ if not (node is Control):
1708
+ return ""
1709
+ var tip := (node as Control).tooltip_text.strip_edges()
1710
+ if not tip.is_empty():
1711
+ return tip
1712
+ if "accessibility_name" in node:
1713
+ return str(node.get("accessibility_name")).strip_edges()
1714
+ return ""
1715
+
1716
+
1091
1717
  ## --- Author hook serialization ------------------------------------------------
1092
1718
 
1093
1719
  ## Converts a _ravensight_state() result into JSON-safe values: vectors become
@@ -1155,7 +1781,64 @@ func _resolve_keycode(raw: Variant) -> int:
1155
1781
  "arrowdown": KEY_DOWN,
1156
1782
  "arrowleft": KEY_LEFT,
1157
1783
  "arrowright": KEY_RIGHT,
1784
+ "up": KEY_UP,
1785
+ "down": KEY_DOWN,
1786
+ "left": KEY_LEFT,
1787
+ "right": KEY_RIGHT,
1788
+ "del": KEY_DELETE,
1789
+ "delete": KEY_DELETE,
1790
+ "ins": KEY_INSERT,
1791
+ "insert": KEY_INSERT,
1792
+ "home": KEY_HOME,
1793
+ "end": KEY_END,
1794
+ "pageup": KEY_PAGEUP,
1795
+ "pgup": KEY_PAGEUP,
1796
+ "pagedown": KEY_PAGEDOWN,
1797
+ "pgdn": KEY_PAGEDOWN,
1798
+ "shift": KEY_SHIFT,
1799
+ "control": KEY_CTRL,
1800
+ "ctrl": KEY_CTRL,
1801
+ "alt": KEY_ALT,
1802
+ "option": KEY_ALT,
1803
+ "meta": KEY_META,
1804
+ "cmd": KEY_META,
1805
+ "command": KEY_META,
1806
+ "capslock": KEY_CAPSLOCK,
1807
+ "spacebar": KEY_SPACE,
1808
+ "comma": KEY_COMMA,
1809
+ "period": KEY_PERIOD,
1810
+ "slash": KEY_SLASH,
1811
+ "backslash": KEY_BACKSLASH,
1812
+ "semicolon": KEY_SEMICOLON,
1813
+ "apostrophe": KEY_APOSTROPHE,
1814
+ "quote": KEY_APOSTROPHE,
1815
+ "backquote": KEY_QUOTELEFT,
1816
+ "backtick": KEY_QUOTELEFT,
1817
+ "minus": KEY_MINUS,
1818
+ "equal": KEY_EQUAL,
1819
+ "plus": KEY_PLUS,
1820
+ "bracketleft": KEY_BRACKETLEFT,
1821
+ "bracketright": KEY_BRACKETRIGHT,
1822
+ "numpadenter": KEY_KP_ENTER,
1823
+ "numpadadd": KEY_KP_ADD,
1824
+ "numpadsubtract": KEY_KP_SUBTRACT,
1825
+ "numpadmultiply": KEY_KP_MULTIPLY,
1826
+ "numpaddivide": KEY_KP_DIVIDE,
1827
+ "numpaddecimal": KEY_KP_PERIOD,
1158
1828
  }
1829
+ var compact := key_name.to_lower().replace(" ", "").replace("_", "")
1830
+ if aliases.has(compact):
1831
+ return int(aliases[compact])
1832
+ # F1 to F24 and the numpad digits, however they are capitalised.
1833
+ if compact.length() >= 2 and compact.begins_with("f") and compact.substr(1).is_valid_int():
1834
+ var n := int(compact.substr(1))
1835
+ if n >= 1 and n <= 24:
1836
+ return KEY_F1 + n - 1
1837
+ for prefix in ["numpad", "num", "kp"]:
1838
+ if compact.begins_with(prefix) and compact.substr(prefix.length()).is_valid_int():
1839
+ var digit := int(compact.substr(prefix.length()))
1840
+ if digit >= 0 and digit <= 9 and compact.length() == prefix.length() + 1:
1841
+ return KEY_KP_0 + digit
1159
1842
  var lowered := key_name.to_lower()
1160
1843
  if aliases.has(lowered):
1161
1844
  return int(aliases[lowered])