gdharness 1.1.12 → 1.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cli.js +724 -360
- package/build/godot/addons/gdharness_runtime/runtime_input.gd +77 -134
- package/build/godot/addons/gdharness_runtime/runtime_menus.gd +81 -0
- package/build/godot/addons/gdharness_runtime/runtime_menus.gd.uid +1 -0
- package/build/godot/addons/gdharness_runtime/runtime_queries.gd +24 -57
- package/build/godot/addons/gdharness_runtime/runtime_says.gd +97 -0
- package/build/godot/addons/gdharness_runtime/runtime_says.gd.uid +1 -0
- package/build/godot/addons/gdharness_runtime/runtime_screen.gd +50 -0
- package/build/godot/addons/gdharness_runtime/runtime_screen.gd.uid +1 -0
- package/build/godot/addons/gdharness_runtime/runtime_targets.gd +82 -16
- package/build/godot/addons/gdharness_runtime/runtime_waits.gd +4 -4
- package/build/index.js +605 -244
- package/build/keeper.js +111 -10
- package/package.json +1 -1
|
@@ -10,6 +10,8 @@ const Values = preload("runtime_values.gd")
|
|
|
10
10
|
## reports are the same place by construction rather than by agreement.
|
|
11
11
|
const Queries = preload("runtime_queries.gd")
|
|
12
12
|
const Read = preload("reading.gd")
|
|
13
|
+
const Menus = preload("runtime_menus.gd")
|
|
14
|
+
const Screen = preload("runtime_screen.gd")
|
|
13
15
|
const Targets = preload("runtime_targets.gd")
|
|
14
16
|
const Words = preload("runtime_words.gd")
|
|
15
17
|
|
|
@@ -410,36 +412,6 @@ func inject_mouse_motion(params: Dictionary) -> Dictionary:
|
|
|
410
412
|
}
|
|
411
413
|
|
|
412
414
|
|
|
413
|
-
## The viewport a click aimed at [param control] has to be pushed into.
|
|
414
|
-
##
|
|
415
|
-
## Its own, unless that is an embedded [Window]. A ConfirmationDialog is a Window, and under
|
|
416
|
-
## `gui_embed_subwindows` a Window is drawn inside its parent rather than given one by the
|
|
417
|
-
## desktop: pushing into its own viewport delivers nothing, measured, with the pointer reading as
|
|
418
|
-
## over no control at all. What reaches it is the parent, which is what the engine does with a
|
|
419
|
-
## real pointer. Walked rather than stepped once, because a dialog can open a dialog.
|
|
420
|
-
static func _clicking_viewport(control: Control) -> Viewport:
|
|
421
|
-
var viewport: Viewport = control.get_viewport()
|
|
422
|
-
var window: Window = viewport as Window
|
|
423
|
-
while window != null and window.is_embedded() and window.get_parent() != null:
|
|
424
|
-
viewport = window.get_parent().get_viewport()
|
|
425
|
-
window = viewport as Window
|
|
426
|
-
return viewport
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
## Where [param control]'s centre is in the viewport [method _clicking_viewport] names.
|
|
430
|
-
##
|
|
431
|
-
## The transform is against the control's own viewport, so every embedded window between it and
|
|
432
|
-
## that one contributes its offset. The same walk, because the two answers have to agree about
|
|
433
|
-
## which viewport they are describing.
|
|
434
|
-
static func _centre_of(control: Control) -> Vector2:
|
|
435
|
-
var centre: Vector2 = control.get_global_transform_with_canvas() * (control.size * 0.5)
|
|
436
|
-
var window: Window = control.get_viewport() as Window
|
|
437
|
-
while window != null and window.is_embedded() and window.get_parent() != null:
|
|
438
|
-
centre += Vector2(window.position)
|
|
439
|
-
window = window.get_parent().get_viewport() as Window
|
|
440
|
-
return centre
|
|
441
|
-
|
|
442
|
-
|
|
443
415
|
## Scrolls whatever is holding [param control] until it is on screen, and answers whether
|
|
444
416
|
## anything moved.
|
|
445
417
|
##
|
|
@@ -521,8 +493,9 @@ func click(params: Dictionary) -> Dictionary:
|
|
|
521
493
|
if not control.is_visible_in_tree():
|
|
522
494
|
return {"type": "error", "message": "%s is not visible, so nothing can click it" % node_path}
|
|
523
495
|
|
|
524
|
-
|
|
525
|
-
var
|
|
496
|
+
# In the control's own viewport first, which is the space its scrolling happens in.
|
|
497
|
+
var own: Viewport = control.get_viewport()
|
|
498
|
+
var local: Vector2 = control.get_global_transform_with_canvas() * (control.size * 0.5)
|
|
526
499
|
|
|
527
500
|
# A control out of sight inside a ScrollContainer is not out of reach, it is one scroll away,
|
|
528
501
|
# which is what a person does without thinking about it before they click. Refusing it
|
|
@@ -534,19 +507,23 @@ func click(params: Dictionary) -> Dictionary:
|
|
|
534
507
|
# the click went to that instead and said so. Measured on a hall whose staff panel had been
|
|
535
508
|
# scrolled past: the button was at y 69 and its container started at y 166.
|
|
536
509
|
var scrolled: bool = false
|
|
537
|
-
if not _in_sight(control,
|
|
510
|
+
if not _in_sight(control, own, local):
|
|
538
511
|
scrolled = _scroll_into_view(control)
|
|
539
512
|
if scrolled:
|
|
540
513
|
# A container moves its child on the next layout pass rather than inside the call.
|
|
541
514
|
await _host.get_tree().process_frame
|
|
542
|
-
|
|
515
|
+
local = control.get_global_transform_with_canvas() * (control.size * 0.5)
|
|
543
516
|
|
|
517
|
+
var reached: Dictionary = Screen.reach(own, local)
|
|
518
|
+
var viewport: Viewport = reached["viewport"]
|
|
519
|
+
var centre: Vector2 = reached["point"]
|
|
544
520
|
var position: Vector2 = viewport.get_final_transform() * centre
|
|
545
521
|
# The GUI only delivers to what is inside the viewport, so a centre outside it would be a
|
|
546
522
|
# click that silently reached nothing. A game with no window has a 64 by 64 viewport
|
|
547
523
|
# whatever the project settings say, which is the usual reason to be here and is not
|
|
548
|
-
# something the caller can read off the rect on its own.
|
|
549
|
-
|
|
524
|
+
# something the caller can read off the rect on its own. Its own viewport as well, since a
|
|
525
|
+
# control outside its SubViewport is drawn nowhere.
|
|
526
|
+
if not viewport.get_visible_rect().has_point(centre) or not own.get_visible_rect().has_point(local):
|
|
550
527
|
var why: String = _no_window_note(viewport)
|
|
551
528
|
if scrolled:
|
|
552
529
|
why = ". It was scrolled as far as what holds it goes and is still out there"
|
|
@@ -583,20 +560,17 @@ func click(params: Dictionary) -> Dictionary:
|
|
|
583
560
|
hovered_path = str(hovered.get_path())
|
|
584
561
|
var landed: bool = hovered == control or (hovered != null and control.is_ancestor_of(hovered))
|
|
585
562
|
|
|
586
|
-
viewport
|
|
563
|
+
_press_button(viewport, _button(position, button, true, double))
|
|
587
564
|
await _host.get_tree().process_frame
|
|
588
|
-
viewport
|
|
565
|
+
_press_button(viewport, _button(position, button, false, false))
|
|
589
566
|
# The release is what a button acts on, and a queue_free it causes lands at the end of
|
|
590
567
|
# this frame; the frame passes so the answer describes the control as the click left it.
|
|
591
568
|
await _host.get_tree().process_frame
|
|
592
569
|
|
|
593
570
|
# What became of the control: still in the tree, taken out of it, or freed. A button that
|
|
594
571
|
# opened another screen is the second or the third, and the caller wants to hear that
|
|
595
|
-
# rather than guess it from a tree that has changed shape.
|
|
596
|
-
|
|
597
|
-
var afterwards: String = "freed"
|
|
598
|
-
if is_instance_valid(control):
|
|
599
|
-
afterwards = "in_tree" if control.is_inside_tree() else "removed"
|
|
572
|
+
# rather than guess it from a tree that has changed shape.
|
|
573
|
+
var afterwards: String = _afterwards(control)
|
|
600
574
|
|
|
601
575
|
var answer: Dictionary = {
|
|
602
576
|
"type": "clicked",
|
|
@@ -655,7 +629,7 @@ func choose(params: Dictionary) -> Dictionary:
|
|
|
655
629
|
return standing
|
|
656
630
|
var node: Node = standing["node"]
|
|
657
631
|
|
|
658
|
-
var menu: PopupMenu =
|
|
632
|
+
var menu: PopupMenu = Menus.menu_of(node)
|
|
659
633
|
if menu == null:
|
|
660
634
|
return {
|
|
661
635
|
"type": "error",
|
|
@@ -672,15 +646,15 @@ func choose(params: Dictionary) -> Dictionary:
|
|
|
672
646
|
"message":
|
|
673
647
|
(
|
|
674
648
|
"%s needs the item named, by text or index. It holds: %s"
|
|
675
|
-
% [node_path, ", ".join(
|
|
649
|
+
% [node_path, ", ".join(Menus.items_of(menu))]
|
|
676
650
|
)
|
|
677
651
|
}
|
|
678
652
|
|
|
679
|
-
var index: int =
|
|
653
|
+
var index: int = Menus.wanted_item(menu, params)
|
|
680
654
|
if index < 0:
|
|
681
655
|
return {
|
|
682
656
|
"type": "error",
|
|
683
|
-
"message": "%s has no such item. It holds: %s" % [node_path, ", ".join(
|
|
657
|
+
"message": "%s has no such item. It holds: %s" % [node_path, ", ".join(Menus.items_of(menu))]
|
|
684
658
|
}
|
|
685
659
|
if menu.is_item_separator(index):
|
|
686
660
|
var heading: String = Words.item_says(menu, index).strip_edges()
|
|
@@ -705,9 +679,22 @@ func choose(params: Dictionary) -> Dictionary:
|
|
|
705
679
|
# Shown first, because a menu nobody has opened has no focus to move and Enter would go to
|
|
706
680
|
# whatever is behind it. An OptionButton opens its own; a bare PopupMenu is popped where it
|
|
707
681
|
# already sits, which leaves a menu that was already open where it is.
|
|
708
|
-
var opened: bool =
|
|
682
|
+
var opened: bool = Menus.open_the_menu(node, menu)
|
|
709
683
|
await _host.get_tree().process_frame
|
|
710
684
|
|
|
685
|
+
# Read before the press, because the press can take the menu away: a game that rebuilds its
|
|
686
|
+
# settings screen on item_selected frees the button and its menu inside the pick, and reading
|
|
687
|
+
# the item afterwards was an engine error in the game's log and an empty answer to a pick that
|
|
688
|
+
# had taken.
|
|
689
|
+
var answer: Dictionary = {
|
|
690
|
+
"type": "chosen",
|
|
691
|
+
"path": node_path,
|
|
692
|
+
"index": index,
|
|
693
|
+
"text": Words.item_says(menu, index),
|
|
694
|
+
"id": menu.get_item_id(index),
|
|
695
|
+
"opened": opened,
|
|
696
|
+
"menu": str(menu.get_path()),
|
|
697
|
+
}
|
|
711
698
|
menu.scroll_to_item(index)
|
|
712
699
|
menu.set_focused_item(index)
|
|
713
700
|
# Through Input rather than pushed at the menu, which is how a keyboard reaches an open one: a
|
|
@@ -718,96 +705,49 @@ func choose(params: Dictionary) -> Dictionary:
|
|
|
718
705
|
Input.parse_input_event(_accept(false))
|
|
719
706
|
await _host.get_tree().process_frame
|
|
720
707
|
|
|
721
|
-
|
|
722
|
-
"type": "chosen",
|
|
723
|
-
"path": node_path,
|
|
724
|
-
"index": index,
|
|
725
|
-
"text": Words.item_says(menu, index),
|
|
726
|
-
"id": menu.get_item_id(index),
|
|
727
|
-
"opened": opened,
|
|
728
|
-
"menu": str(menu.get_path()),
|
|
729
|
-
}
|
|
708
|
+
answer["control_afterwards"] = _afterwards(node)
|
|
730
709
|
# What the button in front of the menu reads now, which is the answer to "did it take": a menu
|
|
731
|
-
# item that fired changes the thing holding it, and nothing else about the press says so.
|
|
732
|
-
|
|
733
|
-
if
|
|
710
|
+
# item that fired changes the thing holding it, and nothing else about the press says so. A
|
|
711
|
+
# button the pick took away has nothing to read, and that it went is the answer.
|
|
712
|
+
if answer["control_afterwards"] == "in_tree" and node is OptionButton:
|
|
713
|
+
var chooser: OptionButton = node
|
|
734
714
|
answer["selected"] = chooser.get_selected()
|
|
735
715
|
answer["shows"] = Words.said_by(chooser)
|
|
736
716
|
return answer
|
|
737
717
|
|
|
738
718
|
|
|
739
|
-
##
|
|
740
|
-
##
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
719
|
+
## Sends a click's press or release into [param viewport], through Input when that is the game's
|
|
720
|
+
## own window.
|
|
721
|
+
##
|
|
722
|
+
## Through Input so that Input knows a button is held, which is what a real mouse tells it. A
|
|
723
|
+
## PopupMenu opened by a press asks Input whether a button is down, and when one is, it lets the
|
|
724
|
+
## release that ends that press go by rather than choosing the item under it. Pushed straight into
|
|
725
|
+
## the viewport, the press left Input thinking nothing was held, so a dropdown near the bottom of
|
|
726
|
+
## the screen, whose menu opens over it and under the pointer, had its first item chosen by the
|
|
727
|
+
## click meant to open it. Games read that state too, through Input.is_mouse_button_pressed.
|
|
728
|
+
##
|
|
729
|
+
## Any other viewport is pushed into directly: Input reaches only the game's window. That is a
|
|
730
|
+
## viewport with no place on the screen, since `Screen.reach` carries every other one there.
|
|
731
|
+
func _press_button(viewport: Viewport, event: InputEventMouseButton) -> void:
|
|
732
|
+
if viewport == _host.get_tree().root:
|
|
733
|
+
Input.parse_input_event(event)
|
|
734
|
+
# Delivered now, as a push is, rather than at the next frame: the answer is read a frame
|
|
735
|
+
# after the release, and a button that frees itself on it has to be gone by then.
|
|
736
|
+
Input.flush_buffered_events()
|
|
737
|
+
else:
|
|
738
|
+
viewport.push_input(event)
|
|
750
739
|
|
|
751
740
|
|
|
752
|
-
##
|
|
753
|
-
##
|
|
754
|
-
##
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
return asked if asked >= 0 and asked < menu.get_item_count() else -1
|
|
763
|
-
var wanted: String = str(params.get("text", ""))
|
|
764
|
-
if wanted.is_empty():
|
|
765
|
-
return -1
|
|
766
|
-
# The items before the separators, because a heading can carry the same words as an item under
|
|
767
|
-
# it, and finding the heading first refused the choice the caller meant. A separator is still
|
|
768
|
-
# looked for after, so a heading asked for by name is refused as one rather than as missing.
|
|
769
|
-
var order: Array[int] = []
|
|
770
|
-
for separators: bool in [false, true]:
|
|
771
|
-
for index: int in menu.get_item_count():
|
|
772
|
-
if menu.is_item_separator(index) == separators:
|
|
773
|
-
order.append(index)
|
|
774
|
-
var shown: Array[String] = []
|
|
775
|
-
var held: Array[String] = []
|
|
776
|
-
for index: int in order:
|
|
777
|
-
shown.append(Words.item_says(menu, index))
|
|
778
|
-
held.append(menu.get_item_text(index))
|
|
779
|
-
for words: Array[String] in [shown, held]:
|
|
780
|
-
for at: int in words.size():
|
|
781
|
-
if words[at] == wanted:
|
|
782
|
-
return order[at]
|
|
783
|
-
for at: int in words.size():
|
|
784
|
-
if words[at].nocasecmp_to(wanted) == 0:
|
|
785
|
-
return order[at]
|
|
786
|
-
return -1
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
## What the menu shows, for a refusal that names the choices rather than the miss: a titled
|
|
790
|
-
## separator marked as the heading it is, and one with no title left out, since it shows nothing.
|
|
791
|
-
static func _items_of(menu: PopupMenu) -> Array[String]:
|
|
792
|
-
var said: Array[String] = []
|
|
793
|
-
for index: int in menu.get_item_count():
|
|
794
|
-
var words: String = Words.item_says(menu, index)
|
|
795
|
-
if not menu.is_item_separator(index):
|
|
796
|
-
said.append("%d: %s" % [index, words])
|
|
797
|
-
elif not words.strip_edges().is_empty():
|
|
798
|
-
said.append("%d: %s (a heading)" % [index, words])
|
|
799
|
-
return said
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
## Opens the menu if it is not already, and answers whether anything opened.
|
|
803
|
-
static func _open_the_menu(node: Node, menu: PopupMenu) -> bool:
|
|
804
|
-
if menu.visible:
|
|
805
|
-
return false
|
|
806
|
-
if node.has_method("show_popup"):
|
|
807
|
-
node.call("show_popup")
|
|
808
|
-
return true
|
|
809
|
-
menu.popup()
|
|
810
|
-
return true
|
|
741
|
+
## What became of [param node] once an input it was given has run: still in the tree, taken out
|
|
742
|
+
## of it, or freed. Untyped, because a freed reference handed to a typed parameter is itself the
|
|
743
|
+
## engine error this is here to avoid.
|
|
744
|
+
static func _afterwards(node: Variant) -> String:
|
|
745
|
+
if not is_instance_valid(node):
|
|
746
|
+
return "freed"
|
|
747
|
+
if not node is Node:
|
|
748
|
+
return "removed"
|
|
749
|
+
var placed: Node = node
|
|
750
|
+
return "in_tree" if placed.is_inside_tree() else "removed"
|
|
811
751
|
|
|
812
752
|
|
|
813
753
|
func _accept(pressed: bool) -> InputEventKey:
|
|
@@ -859,13 +799,16 @@ func _click_in_the_world(node_path: String, item: Node3D, params: Dictionary) ->
|
|
|
859
799
|
)
|
|
860
800
|
}
|
|
861
801
|
|
|
862
|
-
var
|
|
802
|
+
var reached: Dictionary = Screen.reach(viewport, aim)
|
|
803
|
+
var arriving: Viewport = reached["viewport"]
|
|
804
|
+
var reached_point: Vector2 = reached["point"]
|
|
805
|
+
var position: Vector2 = arriving.get_final_transform() * reached_point
|
|
863
806
|
var button: int = _resolve_mouse_button(params.get("button", MOUSE_BUTTON_LEFT))
|
|
864
807
|
if button < 0:
|
|
865
808
|
return _no_such_button(params.get("button"))
|
|
866
809
|
var double: bool = Read.as_bool(params.get("double", false))
|
|
867
810
|
|
|
868
|
-
|
|
811
|
+
arriving.push_input(_motion(position, _arrive(position)))
|
|
869
812
|
# Read before the press, for the reason the Control click reads it: what the caller needs to
|
|
870
813
|
# know is whether a panel is sitting over the room, and the press is what would change it.
|
|
871
814
|
var hovered: Control = viewport.gui_get_hovered_control()
|
|
@@ -873,9 +816,9 @@ func _click_in_the_world(node_path: String, item: Node3D, params: Dictionary) ->
|
|
|
873
816
|
if hovered != null:
|
|
874
817
|
hovered_path = str(hovered.get_path())
|
|
875
818
|
|
|
876
|
-
|
|
819
|
+
_press_button(arriving, _button(position, button, true, double))
|
|
877
820
|
await _host.get_tree().process_frame
|
|
878
|
-
|
|
821
|
+
_press_button(arriving, _button(position, button, false, false))
|
|
879
822
|
await _host.get_tree().process_frame
|
|
880
823
|
|
|
881
824
|
return {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
extends RefCounted
|
|
2
|
+
|
|
3
|
+
## The menu a choice is made from and the item in it, for a choice made by what an item says or by
|
|
4
|
+
## where it is in the list.
|
|
5
|
+
|
|
6
|
+
const Read = preload("reading.gd")
|
|
7
|
+
const Words = preload("runtime_words.gd")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## The menu [param node] is, or the one it holds. An [OptionButton] and a [MenuButton] both keep
|
|
11
|
+
## theirs as an internal child, which is a node a caller cannot name and should not have to.
|
|
12
|
+
static func menu_of(node: Node) -> PopupMenu:
|
|
13
|
+
var menu: PopupMenu = node as PopupMenu
|
|
14
|
+
if menu != null:
|
|
15
|
+
return menu
|
|
16
|
+
if node.has_method("get_popup"):
|
|
17
|
+
var held: Variant = node.call("get_popup")
|
|
18
|
+
if held is PopupMenu:
|
|
19
|
+
return held
|
|
20
|
+
return null
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Which item was asked for: `text`, matched exactly and then case-insensitively, or `index`.
|
|
24
|
+
## Minus one when neither names one that is there.
|
|
25
|
+
##
|
|
26
|
+
## `text` is matched against the words the item shows before the ones it holds. In a game with
|
|
27
|
+
## translations they differ, and the shown ones are what a caller has read off the screen: an item
|
|
28
|
+
## held as `ACT_ENGAGE` and shown as "Hire" refused "Hire" and listed the keys. The held words
|
|
29
|
+
## still count after them, for a caller that has the key from the source.
|
|
30
|
+
static func wanted_item(menu: PopupMenu, params: Dictionary) -> int:
|
|
31
|
+
if params.has("index"):
|
|
32
|
+
var asked: int = Read.as_int(params.get("index", -1), -1)
|
|
33
|
+
return asked if asked >= 0 and asked < menu.get_item_count() else -1
|
|
34
|
+
var wanted: String = str(params.get("text", ""))
|
|
35
|
+
if wanted.is_empty():
|
|
36
|
+
return -1
|
|
37
|
+
# The items before the separators, because a heading can carry the same words as an item under
|
|
38
|
+
# it, and finding the heading first refused the choice the caller meant. A separator is still
|
|
39
|
+
# looked for after, so a heading asked for by name is refused as one rather than as missing.
|
|
40
|
+
var order: Array[int] = []
|
|
41
|
+
for separators: bool in [false, true]:
|
|
42
|
+
for index: int in menu.get_item_count():
|
|
43
|
+
if menu.is_item_separator(index) == separators:
|
|
44
|
+
order.append(index)
|
|
45
|
+
var shown: Array[String] = []
|
|
46
|
+
var held: Array[String] = []
|
|
47
|
+
for index: int in order:
|
|
48
|
+
shown.append(Words.item_says(menu, index))
|
|
49
|
+
held.append(menu.get_item_text(index))
|
|
50
|
+
for words: Array[String] in [shown, held]:
|
|
51
|
+
for at: int in words.size():
|
|
52
|
+
if words[at] == wanted:
|
|
53
|
+
return order[at]
|
|
54
|
+
for at: int in words.size():
|
|
55
|
+
if words[at].nocasecmp_to(wanted) == 0:
|
|
56
|
+
return order[at]
|
|
57
|
+
return -1
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## What the menu shows, for a refusal that names the choices rather than the miss: a titled
|
|
61
|
+
## separator marked as the heading it is, and one with no title left out, since it shows nothing.
|
|
62
|
+
static func items_of(menu: PopupMenu) -> Array[String]:
|
|
63
|
+
var said: Array[String] = []
|
|
64
|
+
for index: int in menu.get_item_count():
|
|
65
|
+
var words: String = Words.item_says(menu, index)
|
|
66
|
+
if not menu.is_item_separator(index):
|
|
67
|
+
said.append("%d: %s" % [index, words])
|
|
68
|
+
elif not words.strip_edges().is_empty():
|
|
69
|
+
said.append("%d: %s (a heading)" % [index, words])
|
|
70
|
+
return said
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## Opens the menu if it is not already, and answers whether anything opened.
|
|
74
|
+
static func open_the_menu(node: Node, menu: PopupMenu) -> bool:
|
|
75
|
+
if menu.visible:
|
|
76
|
+
return false
|
|
77
|
+
if node.has_method("show_popup"):
|
|
78
|
+
node.call("show_popup")
|
|
79
|
+
return true
|
|
80
|
+
menu.popup()
|
|
81
|
+
return true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
uid://iv31ebsnrf1i
|
|
@@ -5,6 +5,8 @@ extends RefCounted
|
|
|
5
5
|
|
|
6
6
|
const Paths = preload("runtime_paths.gd")
|
|
7
7
|
const Read = preload("reading.gd")
|
|
8
|
+
const Says = preload("runtime_says.gd")
|
|
9
|
+
const Screen = preload("runtime_screen.gd")
|
|
8
10
|
const Values = preload("runtime_values.gd")
|
|
9
11
|
const Words = preload("runtime_words.gd")
|
|
10
12
|
|
|
@@ -102,13 +104,13 @@ func find_nodes(params: Dictionary) -> Dictionary:
|
|
|
102
104
|
var truncated: bool = false
|
|
103
105
|
# Counted while the tree is already being walked, for the answer below: how many nodes this
|
|
104
106
|
# find would have matched if the name had been read the way it was probably meant.
|
|
105
|
-
var literal: bool =
|
|
107
|
+
var literal: bool = Says.is_plain(wanted["name"])
|
|
106
108
|
var nearly: int = 0
|
|
107
109
|
# The same for the words: a glob is matched against the whole text, and one written as a prefix
|
|
108
110
|
# by habit, "Taken together*", missed the label whose sentence those words are in the middle of.
|
|
109
111
|
# Nothing found then read as the words not being on screen, which is the wrong conclusion when
|
|
110
112
|
# checking that a change to the text landed.
|
|
111
|
-
var widened_says: String =
|
|
113
|
+
var widened_says: String = Says.widened(wanted["says"])
|
|
112
114
|
var widened: Dictionary[String, String] = {}
|
|
113
115
|
for filter: String in wanted:
|
|
114
116
|
widened[filter] = widened_says if filter == "says" else wanted[filter]
|
|
@@ -240,50 +242,6 @@ static func _named(node: Node, pattern: String) -> bool:
|
|
|
240
242
|
return pattern.is_empty() or str(node.name).matchn(pattern)
|
|
241
243
|
|
|
242
244
|
|
|
243
|
-
## Whether [param pattern] is a name written as a whole word rather than as a glob, which is how a
|
|
244
|
-
## caller writes one when they mean "contains". [method String.matchn] answers nothing to it, and
|
|
245
|
-
## nothing is also what a name that is simply not there answers.
|
|
246
|
-
static func _is_literal(pattern: String) -> bool:
|
|
247
|
-
return not pattern.is_empty() and not pattern.contains("*") and not pattern.contains("?")
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
## Whether [param said] is what a find asked for in [param wanted].
|
|
251
|
-
##
|
|
252
|
-
## A plain word is a contains, which is what somebody looking for the row about a person means. A
|
|
253
|
-
## pattern is a glob, because [code]namePattern[/code] beside it is one and nobody writes `*Still*`
|
|
254
|
-
## in one field meaning a glob and in the other meaning those characters. Written as a contains
|
|
255
|
-
## only, a glob matched nothing at all and an empty answer reads as a control that is not on the
|
|
256
|
-
## screen: twice in one session here, over a button that was.
|
|
257
|
-
static func _says(said: String, wanted: String) -> bool:
|
|
258
|
-
var words: String = as_said(wanted)
|
|
259
|
-
return said.containsn(words) if _is_literal(words) else said.matchn(words)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
## Whether [param node]'s own words are what [param wanted] asks for, by the rules a find uses, so a
|
|
263
|
-
## click that names its control by its words finds the one a find would have answered with.
|
|
264
|
-
static func says(node: Node, wanted: String) -> bool:
|
|
265
|
-
return _says(Words.said_by(node), wanted)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
## [param wanted], a glob, open at both ends so it matches its words anywhere in a text; "" when
|
|
269
|
-
## it is not a glob, or already open at both ends, and so has nothing to suggest.
|
|
270
|
-
static func _widened(wanted: String) -> String:
|
|
271
|
-
if wanted.is_empty() or _is_literal(wanted):
|
|
272
|
-
return ""
|
|
273
|
-
var open: String = "*" + wanted.lstrip("*").rstrip("*") + "*"
|
|
274
|
-
return "" if open == wanted else open
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
## [param wanted] as words on a screen: a backslash followed by n is a line break.
|
|
278
|
-
##
|
|
279
|
-
## A button with two lines on it was asked for with the break written as the two characters, the
|
|
280
|
-
## way it is typed into a JSON string one escape short, and was answered as not there: 0 found,
|
|
281
|
-
## which reads as a control that is not on the screen. Nothing on a screen says a backslash and
|
|
282
|
-
## an n, so the two characters mean the break to everybody who writes them.
|
|
283
|
-
static func as_said(wanted: String) -> String:
|
|
284
|
-
return wanted.replace("\\n", "\n")
|
|
285
|
-
|
|
286
|
-
|
|
287
245
|
## Every filter but the name, so a find that came back empty can say how many nodes the name was
|
|
288
246
|
## the only thing standing between it and.
|
|
289
247
|
func _matches_apart_from_name(node: Node, wanted: Dictionary[String, String]) -> bool:
|
|
@@ -292,7 +250,7 @@ func _matches_apart_from_name(node: Node, wanted: Dictionary[String, String]) ->
|
|
|
292
250
|
# What this node says, rather than everything said underneath it. A row is then found by the
|
|
293
251
|
# label in it, and the path answered is that label's, which is where the words a caller is
|
|
294
252
|
# looking at actually are: matching every container above it would answer with the screen.
|
|
295
|
-
if not wanted["says"].is_empty() and not
|
|
253
|
+
if not wanted["says"].is_empty() and not Says.says(node, wanted["says"]):
|
|
296
254
|
return false
|
|
297
255
|
var script: Variant = node.get_script()
|
|
298
256
|
if not wanted["script"].is_empty():
|
|
@@ -326,10 +284,6 @@ static func _script_is(attached: Script, wanted: String) -> bool:
|
|
|
326
284
|
return false
|
|
327
285
|
|
|
328
286
|
|
|
329
|
-
## Where a node is on screen: a Control's rectangle, a Node2D's position, or the place a 3D node
|
|
330
|
-
## is drawn in, in both the canvas coordinates the node reports and the window pixels input
|
|
331
|
-
## arrives in. The two differ whenever the project stretches its viewport, which is what made a
|
|
332
|
-
## rect unusable for a click.
|
|
333
287
|
## Every line of text under a node, in the order somebody reads the screen.
|
|
334
288
|
##
|
|
335
289
|
## The question a caller asks most often, and the one that cost the most to answer: reading a panel
|
|
@@ -413,6 +367,10 @@ static func _drawn(node: Node) -> bool:
|
|
|
413
367
|
return window == null or window.visible
|
|
414
368
|
|
|
415
369
|
|
|
370
|
+
## Where a node is on screen: a Control's rectangle, a Node2D's position, or the place a 3D node
|
|
371
|
+
## is drawn in, in both the canvas coordinates the node reports and the window pixels input
|
|
372
|
+
## arrives in. The two differ whenever the project stretches its viewport, which is what made a
|
|
373
|
+
## rect unusable for a click.
|
|
416
374
|
func get_rect(params: Dictionary) -> Dictionary:
|
|
417
375
|
var node_path: String = str(params.get("path", ""))
|
|
418
376
|
if node_path.is_empty():
|
|
@@ -423,21 +381,30 @@ func get_rect(params: Dictionary) -> Dictionary:
|
|
|
423
381
|
return standing
|
|
424
382
|
var node: Node = standing["node"]
|
|
425
383
|
|
|
384
|
+
# In the window's pixels, which is what a mouse event names, through every embedded window and
|
|
385
|
+
# SubViewport between the node and the window: multiplied by its own viewport's transform alone,
|
|
386
|
+
# a control in a dialog lost the dialog's offset and one in a SubViewport was given its place in
|
|
387
|
+
# the SubViewport, and a mouse event sent there missed it.
|
|
426
388
|
if node is Control:
|
|
427
389
|
var control: Control = node
|
|
428
|
-
var to_window: Transform2D = control.get_viewport().get_final_transform()
|
|
429
390
|
var canvas_rect: Rect2 = control.get_global_rect()
|
|
430
391
|
return {
|
|
431
392
|
"type": "rect",
|
|
432
393
|
"path": node_path,
|
|
433
394
|
"visible": control.is_visible_in_tree(),
|
|
434
395
|
"canvas": _values.serialize(canvas_rect),
|
|
435
|
-
"window":
|
|
396
|
+
"window":
|
|
397
|
+
_values.serialize(
|
|
398
|
+
Screen.rect_in_window(
|
|
399
|
+
control.get_viewport(),
|
|
400
|
+
control.get_global_transform_with_canvas() * Rect2(Vector2.ZERO, control.size)
|
|
401
|
+
)
|
|
402
|
+
),
|
|
436
403
|
}
|
|
437
404
|
if node is Node2D:
|
|
438
405
|
var item: Node2D = node
|
|
439
406
|
var canvas_position: Vector2 = item.get_global_transform_with_canvas().origin
|
|
440
|
-
var window_position: Vector2 = item.get_viewport()
|
|
407
|
+
var window_position: Vector2 = Screen.in_window(item.get_viewport(), canvas_position)
|
|
441
408
|
return {
|
|
442
409
|
"type": "point",
|
|
443
410
|
"path": node_path,
|
|
@@ -470,7 +437,7 @@ func _in_the_frame(node_path: String, item: Node3D) -> Dictionary:
|
|
|
470
437
|
"message": "%s is not in a viewport with a current Camera3D, so nothing is drawing it" % node_path
|
|
471
438
|
}
|
|
472
439
|
|
|
473
|
-
var
|
|
440
|
+
var drawn_in: Viewport = item.get_viewport()
|
|
474
441
|
var answer: Dictionary = {
|
|
475
442
|
"type": "point",
|
|
476
443
|
"path": node_path,
|
|
@@ -481,12 +448,12 @@ func _in_the_frame(node_path: String, item: Node3D) -> Dictionary:
|
|
|
481
448
|
if found.has("aim"):
|
|
482
449
|
var aim: Vector2 = found["aim"]
|
|
483
450
|
answer["canvas"] = _values.serialize(aim)
|
|
484
|
-
answer["window"] = _values.serialize(
|
|
451
|
+
answer["window"] = _values.serialize(Screen.in_window(drawn_in, aim))
|
|
485
452
|
if found.has("rect"):
|
|
486
453
|
var covered: Rect2 = found["rect"]
|
|
487
454
|
answer["covers"] = {
|
|
488
455
|
"canvas": _values.serialize(covered),
|
|
489
|
-
"window": _values.serialize(
|
|
456
|
+
"window": _values.serialize(Screen.rect_in_window(drawn_in, covered)),
|
|
490
457
|
}
|
|
491
458
|
return answer
|
|
492
459
|
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
extends RefCounted
|
|
2
|
+
|
|
3
|
+
## Whether a node says what a caller asked for in `says`: the one set of rules a find, a click and a
|
|
4
|
+
## wait all match words by, so the three never disagree about which control a word names.
|
|
5
|
+
|
|
6
|
+
const Words = preload("runtime_words.gd")
|
|
7
|
+
|
|
8
|
+
## Stands in for a bar written as `\|` while `says` is split into its alternatives: a character from
|
|
9
|
+
## the private use area, which no game's text uses.
|
|
10
|
+
const ESCAPED_BAR: String = ""
|
|
11
|
+
|
|
12
|
+
## How many splits [method alternatives] keeps. A find asks about two at once, the words it was given
|
|
13
|
+
## and the same words widened, and anything past a handful is a caller that has moved on.
|
|
14
|
+
const SPLITS_KEPT: int = 8
|
|
15
|
+
|
|
16
|
+
## Each `says` split into alternatives, by what was written; see [method alternatives].
|
|
17
|
+
static var _splits: Dictionary[String, Array] = {}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Whether [param node]'s own words are what [param wanted] asks for.
|
|
21
|
+
static func says(node: Node, wanted: String) -> bool:
|
|
22
|
+
return matches(Words.said_by(node), wanted)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Whether [param said] is what [param wanted] asks for.
|
|
26
|
+
##
|
|
27
|
+
## A plain word is a contains, which is what somebody looking for the row about a person means. A
|
|
28
|
+
## pattern is a glob, because [code]namePattern[/code] beside it is one and nobody writes `*Still*`
|
|
29
|
+
## in one field meaning a glob and in the other meaning those characters. Written as a contains
|
|
30
|
+
## only, a glob matched nothing at all and an empty answer reads as a control that is not on the
|
|
31
|
+
## screen: twice in one session here, over a button that was.
|
|
32
|
+
##
|
|
33
|
+
## Several alternatives separated by `|` match when any one of them does, each by those rules: a
|
|
34
|
+
## wait for the end of a turn is a wait for whichever of "won", "lost" or the next turn's words comes
|
|
35
|
+
## first, and read as one glob with the bars in it, it waited out its whole timeout for words no
|
|
36
|
+
## screen says.
|
|
37
|
+
static func matches(said: String, wanted: String) -> bool:
|
|
38
|
+
for words: String in alternatives(wanted):
|
|
39
|
+
if said.containsn(words) if is_plain(words) else said.matchn(words):
|
|
40
|
+
return true
|
|
41
|
+
return false
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## The alternatives [param wanted] names, each as words on a screen: split at every `|` not written
|
|
45
|
+
## as `\|`, which stays a bar in the words. An empty alternative, a stray bar at either end, is
|
|
46
|
+
## dropped: it names no words, and a find that came back empty widened it to `**` and suggested a
|
|
47
|
+
## pattern that matches every node there is.
|
|
48
|
+
##
|
|
49
|
+
## Kept once split, since a find, a click or a wait asks about the same words for every node on the
|
|
50
|
+
## screen: split afresh for each of them, one look over a hall of twenty thousand nodes took 210ms
|
|
51
|
+
## rather than 155ms. The array handed back is shared and not to be changed.
|
|
52
|
+
static func alternatives(wanted: String) -> Array[String]:
|
|
53
|
+
var kept: Variant = _splits.get(wanted)
|
|
54
|
+
if kept != null:
|
|
55
|
+
var split: Array[String] = kept
|
|
56
|
+
return split
|
|
57
|
+
var held: String = as_said(wanted).replace("\\|", ESCAPED_BAR)
|
|
58
|
+
var found: Array[String] = []
|
|
59
|
+
for part: String in held.split("|"):
|
|
60
|
+
var words: String = part.replace(ESCAPED_BAR, "|")
|
|
61
|
+
if not words.is_empty():
|
|
62
|
+
found.append(words)
|
|
63
|
+
if _splits.size() >= SPLITS_KEPT:
|
|
64
|
+
_splits.clear()
|
|
65
|
+
_splits[wanted] = found
|
|
66
|
+
return found
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Whether [param pattern] is words written whole rather than as a glob, which is how a caller
|
|
70
|
+
## writes them when they mean "contains". [method String.matchn] answers nothing to it, and nothing
|
|
71
|
+
## is also what words that are simply not there answer.
|
|
72
|
+
static func is_plain(pattern: String) -> bool:
|
|
73
|
+
return not pattern.is_empty() and not pattern.contains("*") and not pattern.contains("?")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## [param wanted], a glob, open at both ends so it matches its words anywhere in a text; "" when
|
|
77
|
+
## it is not a glob, or already open at both ends, and so has nothing to suggest.
|
|
78
|
+
static func widened(wanted: String) -> String:
|
|
79
|
+
var open_ended: Array[String] = []
|
|
80
|
+
var changed: bool = false
|
|
81
|
+
for words: String in alternatives(wanted):
|
|
82
|
+
var open: String = words
|
|
83
|
+
if not is_plain(words):
|
|
84
|
+
open = "*" + words.lstrip("*").rstrip("*") + "*"
|
|
85
|
+
changed = changed or open != words
|
|
86
|
+
open_ended.append(open.replace("|", "\\|"))
|
|
87
|
+
return "|".join(open_ended) if changed else ""
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
## [param wanted] as words on a screen: a backslash followed by n is a line break.
|
|
91
|
+
##
|
|
92
|
+
## A button with two lines on it was asked for with the break written as the two characters, the
|
|
93
|
+
## way it is typed into a JSON string one escape short, and was answered as not there: 0 found,
|
|
94
|
+
## which reads as a control that is not on the screen. Nothing on a screen says a backslash and
|
|
95
|
+
## an n, so the two characters mean the break to everybody who writes them.
|
|
96
|
+
static func as_said(wanted: String) -> String:
|
|
97
|
+
return wanted.replace("\\n", "\n")
|