diff --git a/project/story/starting_stories/steven_dnd.gd b/project/story/starting_stories/steven_dnd.gd index 592dee5..b97316a 100644 --- a/project/story/starting_stories/steven_dnd.gd +++ b/project/story/starting_stories/steven_dnd.gd @@ -33,7 +33,7 @@ var options := { "curiosity": 1, } }, - "Er... No thanks.": { + "Er... No thanks. ": { "text": "\"Oh, Okay.\" \nSteven walks away dejectedly.", }, } diff --git a/project/test/integration/simple_story_validity_test.gd b/project/test/integration/simple_story_validity_test.gd index 27789b8..4e618cf 100644 --- a/project/test/integration/simple_story_validity_test.gd +++ b/project/test/integration/simple_story_validity_test.gd @@ -216,20 +216,12 @@ func _test_text_content(text, story_path: String): func _get_option_line_lengths(story: SimpleStory) -> Array[int]: var game_screen: Node = add_child_autofree(preload("res://ui/game_screen.tscn").instantiate()) - for option in story.options: - game_screen.create_option_button(option) + # Extract just the option names from the options dictionary + var options :Array = story.options.keys() + + game_screen.show_options(options) # Required to let the UI "settle" before checking the line count. await get_tree().process_frame - var option_buttons := game_screen.get_node("%OptionArea").get_children() - - var result: Array[int] = [] - - for button in option_buttons: - var label := button.get_node("%Label") - var text_lines = label.get_visible_line_count() - - result.append(text_lines) - - return result + return game_screen.get_visible_line_counts_in_options() diff --git a/project/ui/audible_button.gd b/project/ui/audible_button.gd index 0010681..d7373d3 100644 --- a/project/ui/audible_button.gd +++ b/project/ui/audible_button.gd @@ -18,6 +18,10 @@ signal pressed %Label.add_theme_color_override("font_color", text_color) +func get_visible_line_count() -> int: + return %Label.get_visible_line_count() + + func _on_pressed(): Sfx.play_click_sound() pressed.emit() diff --git a/project/ui/game_screen.gd b/project/ui/game_screen.gd index c44176a..77d7815 100644 --- a/project/ui/game_screen.gd +++ b/project/ui/game_screen.gd @@ -28,6 +28,17 @@ func _input(event): tapped_anywhere.emit() +## Return the respective line count of each option button text. +## +## This is used for integration testing and is not intended to be +## part of the presenter layer. +func get_visible_line_counts_in_options() -> Array[int]: + var result : Array[int] = [] + for button in _option_area.get_children(): + result.append(button.get_visible_line_count()) + return result + + ## Finish an interaction with the presenter. ## This gives the player a chance to confirm that they are done with the ## current story. @@ -106,7 +117,7 @@ func show_npc(npc:Npc, location:Texture) -> void: func show_options(options: Array) -> String: var buttons : Array[Control] = [] for option in options: - buttons.append(create_option_button(option)) + buttons.append(_create_option_button(option)) var selection = await _option_selected GameLog.made_choice(selection) @@ -117,7 +128,7 @@ func show_options(options: Array) -> String: return selection -func create_option_button(option: String) -> Node: +func _create_option_button(option: String) -> Node: var button := preload("res://ui/audible_button.tscn").instantiate() button.text = option button.pressed.connect(func(): _option_selected.emit(option))