33class_name EternalLoom
44extends Node2D
55
6+ signal retelling_started
7+ signal retelling_finished
8+ signal give_retelling_upgrade (type : InventoryItem .ItemType )
9+
610const ETERNAL_LOOM_INTERACTION : DialogueResource = preload ("uid://yafw7bf362gh" )
711
812## Scenes that are the first of three Sokoban puzzles. A random one will be used
@@ -24,7 +28,7 @@ var _have_threads := is_item_offering_possible()
2428
2529func _ready () -> void :
2630 talk_behavior .dialogue = ETERNAL_LOOM_INTERACTION
27- talk_behavior .title = "have_threads" if _have_threads else "no_threads"
31+ talk_behavior .before_dialogue = _before_dialogue
2832 interact_area .interaction_ended .connect (self ._on_interaction_ended )
2933
3034 if GameState .incorporating_threads :
@@ -46,6 +50,16 @@ func _ready() -> void:
4650 GameState .mark_quest_completed ()
4751
4852
53+ func _before_dialogue () -> void :
54+ if _have_threads :
55+ if GameState .current_quest and GameState .current_quest .retelling :
56+ talk_behavior .title = "start_retelling"
57+ else :
58+ talk_behavior .title = "have_threads"
59+ else :
60+ talk_behavior .title = "no_threads"
61+
62+
4963func _find_elder (quest : Quest ) -> Elder :
5064 for elder in elders :
5165 if quest .resource_path .begins_with (elder .quest_directory ):
@@ -56,6 +70,16 @@ func _find_elder(quest: Quest) -> Elder:
5670
5771func _on_interaction_ended () -> void :
5872 if _have_threads :
73+ if GameState .current_quest and GameState .current_quest .retelling :
74+ # Hide interact label during retelling
75+ interact_area .disabled = true
76+ DialogueManager .show_dialogue_balloon (GameState .current_quest .retelling , "" , [self ])
77+ retelling_started .emit ()
78+ await DialogueManager .dialogue_ended
79+ await on_offering_succeeded ()
80+ interact_area .disabled = false
81+ retelling_finished .emit ()
82+
5983 if not ProjectSettings .get_setting (ThreadbareProjectSettings .SKIP_SOKOBANS ):
6084 # Hide interact label during scene transition
6185 interact_area .disabled = true
@@ -65,6 +89,60 @@ func _on_interaction_ended() -> void:
6589 GameState .mark_quest_completed ()
6690
6791
92+ func _has_magical_thread_of_type (type : InventoryItem .ItemType ) -> bool :
93+ for item in GameState .items_collected ():
94+ if item .type == type :
95+ return true
96+ return false
97+
98+
99+ func has_memory () -> bool :
100+ return _has_magical_thread_of_type (InventoryItem .ItemType .MEMORY )
101+
102+
103+ func has_imagination () -> bool :
104+ return _has_magical_thread_of_type (InventoryItem .ItemType .IMAGINATION )
105+
106+
107+ func has_spirit () -> bool :
108+ return _has_magical_thread_of_type (InventoryItem .ItemType .SPIRIT )
109+
110+
111+ func memory_text () -> String :
112+ var has_it := _has_magical_thread_of_type (InventoryItem .ItemType .MEMORY )
113+ return "(Memory available!)" if has_it else ""
114+
115+
116+ func imagination_text () -> String :
117+ var has_it := _has_magical_thread_of_type (InventoryItem .ItemType .IMAGINATION )
118+ return "(Imagination available!)" if has_it else ""
119+
120+
121+ func spirit_text () -> String :
122+ var has_it := _has_magical_thread_of_type (InventoryItem .ItemType .SPIRIT )
123+ return "(Spirit available!)" if has_it else ""
124+
125+
126+ func _give_upgrade (type : InventoryItem .ItemType ) -> void :
127+ var has_it := _has_magical_thread_of_type (type )
128+ if not has_it :
129+ push_warning ("Trying to give an upgrade for missing item type" , type )
130+ return
131+ give_retelling_upgrade .emit (type )
132+
133+
134+ func give_memory_upgrade () -> void :
135+ _give_upgrade (InventoryItem .ItemType .MEMORY )
136+
137+
138+ func give_imagination_upgrade () -> void :
139+ _give_upgrade (InventoryItem .ItemType .IMAGINATION )
140+
141+
142+ func give_spirit_upgrade () -> void :
143+ _give_upgrade (InventoryItem .ItemType .SPIRIT )
144+
145+
68146func on_offering_succeeded () -> void :
69147 loom_offering_animation_player .play (& "loom_offering" )
70148 await loom_offering_animation_player .animation_finished
0 commit comments