chore: Dialog Manager addon clean up

This commit is contained in:
2025-10-04 03:39:18 +02:00
parent 02ebbe4c03
commit 41b21daec0
15 changed files with 29 additions and 145 deletions

View File

@@ -1,31 +0,0 @@
"""
Base interface for all states: it doesn't do anything in itself
but forces us to pass the right arguments to the methods below
and makes sure every State object had all of these methods.
"""
extends Node
signal finished(next_state_name)
# Initialize the state. E.g. change the animation
func enter():
return
# Clean up the state. Reinitialize values like a timer
func exit():
return
func handle_input(_event):
return
func update(_delta):
return
func _on_animation_finished(_anim_name):
return

View File

@@ -1,92 +0,0 @@
"""
Base interface for a generic state machine
It handles initializing, setting the machine active or not
delegating _physics_process, _input calls to the State nodes,
and changing the current/active state.
"""
extends Node
signal state_changed(current_state)
"""
You must set a starting node from the inspector or on
the node that inherits from this state machine interface
If you don't the game will crash (on purpose, so you won't
forget to initialize the state machine)
"""
@export var START_STATE: Node
var states_map = {}
var states_stack = [] # can also be used as a pushdown automaton
var current_state = null
var current_state_name = ""
var _active = false: set = set_active
func initialize(start_state):
for child in get_children():
child.finished.connect(_change_state)
set_active(true)
states_stack.push_front(start_state)
current_state = states_stack[0]
current_state.enter()
func set_active(value):
_active = value
set_physics_process(value)
set_process_input(value)
if not _active:
states_stack = []
current_state = null
func _input(event):
current_state.handle_input(event)
func _physics_process(delta):
current_state.update(delta)
func _on_animation_finished(anim_name):
if not _active:
return
current_state._on_animation_finished(anim_name)
func _change_state(state_name):
if not _active:
return
escoria.logger.trace(
self,
"Dialog State Machine: Changing state from '%s' to '%s'." % [current_state_name, state_name]
)
current_state.exit()
if state_name == "previous":
states_stack.pop_front()
else:
states_stack[0] = states_map[state_name]
current_state = states_stack[0]
state_changed.emit(current_state)
#if state_name != "previous":
current_state.enter()
current_state_name = state_name
func get_current_state_name():
for key in states_map.keys():
if states_map[key] == current_state:
return key
return null

View File

@@ -142,7 +142,8 @@ func _on_say_finished():
hide_dialop_tip()
_is_saying = false
_dialog_player.say_finished.emit()
#_dialog_player.say_finished.emit()
say_finished.emit()

View File

@@ -1,13 +1,12 @@
extends "res://addons/escoria-ui-return-monkey-island-dialog-simple/patterns/state_machine/state_machine.gd"
extends StateMachine
func _init():
_create_states()
_add_states_to_machine()
current_state_name = "idle"
START_STATE = states_map[current_state_name]
initialize(START_STATE)
initialize(states_map[current_state_name])
# Creates the states for this state machine.

View File

@@ -1,4 +1,4 @@
extends "res://addons/escoria-ui-return-monkey-island-dialog-simple/patterns/state_machine/state.gd"
extends State
# The owning dialog player.

View File

@@ -1,4 +1,4 @@
extends "res://addons/escoria-ui-return-monkey-island-dialog-simple/patterns/state_machine/state.gd"
extends State
# Owning dialog player

View File

@@ -1,4 +1,4 @@
extends "res://addons/escoria-ui-return-monkey-island-dialog-simple/patterns/state_machine/state.gd"
extends State
func enter():
escoria.logger.trace(self, "Dialog State Machine: Entered 'idle'.")

View File

@@ -1,4 +1,4 @@
extends "res://addons/escoria-ui-return-monkey-island-dialog-simple/patterns/state_machine/state.gd"
extends State
# Reference to the currently playing dialog manager

View File

@@ -1,4 +1,4 @@
extends "res://addons/escoria-ui-return-monkey-island-dialog-simple/patterns/state_machine/state.gd"
extends State
# Reference to the currently playing dialog manager

View File

@@ -1,4 +1,4 @@
extends "res://addons/escoria-ui-return-monkey-island-dialog-simple/patterns/state_machine/state.gd"
extends State
# Reference to the currently playing dialog manager

View File

@@ -1,4 +1,4 @@
extends "res://addons/escoria-ui-return-monkey-island-dialog-simple/patterns/state_machine/state.gd"
extends State
# Reference to the currently playing dialog manager

View File

@@ -1,4 +1,4 @@
extends "res://addons/escoria-ui-return-monkey-island-dialog-simple/patterns/state_machine/state.gd"
extends State
# Reference to the currently playing dialog manager
@@ -17,15 +17,21 @@ func enter():
func handle_input(_event):
if _event is InputEventMouseButton and _event.pressed:
if escoria.inputs_manager.input_mode != \
escoria.inputs_manager.INPUT_NONE:
if _event is not InputEventMouseButton:
return
if _dialog_manager.say_finished.is_connected(_on_say_finished):
_dialog_manager.say_finished.disconnect(_on_say_finished)
if !_event.pressed:
return
finished.emit("interrupt")
get_viewport().set_input_as_handled()
if escoria.inputs_manager.input_mode == \
escoria.inputs_manager.INPUT_NONE:
return
if _dialog_manager.say_finished.is_connected(_on_say_finished):
_dialog_manager.say_finished.disconnect(_on_say_finished)
finished.emit("interrupt")
get_viewport().set_input_as_handled()
# Handles the end of a say function after it has emitted say_finished.

View File

@@ -110,7 +110,7 @@ func _ready():
# Show inventory when video player finishes playing a video (inventory is hidden when a video starts)
get_video_player().connect("finished", Callable(self, "show_ui"))
escoria.dialog_player.connect("say_finished", func say_finished(): show_tooltips())
escoria.dialog_player.connect("say_finished", _on_say_finished)
func _enter_tree():
@@ -564,3 +564,6 @@ func _on_MusicButton_pressed():
func _on_translation_button_pressed() -> void:
$menu_layer/language_selector.show()
func _on_say_finished() -> void:
show_tooltips()