Untitled
Anonymous
plain_text
02/24/2026 12:28 AM
11.9 KB
9
Indexable
# Foxpost.gd (Aurora-style dialogue + choice_selected, NO SFX)
# Node tree expected (minimal):
# Foxpost (Node2D) [this script]
# ├─ Player (instance)
# ├─ Background (Sprite2D)
# ├─ Box (Area2D) [Interactable.gd]
# │ └─ CollisionShape2D
# ├─ ExitToHub (Area2D) [Interactable.gd]
# │ └─ CollisionShape2D
# └─ (optional) Box/EIcon, ExitToHub/EIcon, SpawnLeft/SpawnRight markers
extends Node2D
@export var foxpost_portrait: Texture2D
@export var package_icon: Texture2D # reward icon shown in overlay (like Aurora token)
var dialogue_ui
var note_ui
var fade_rect
var item_get_overlay
var main_ref
@onready var player = $Player
@onready var box_eicon: CanvasItem = get_node_or_null("Box/EIcon")
@onready var exit_eicon: CanvasItem = get_node_or_null("ExitToHub/EIcon")
@onready var box = _get_interactable("Box")
@onready var exit_to_hub = _get_interactable("ExitToHub")
var has_reward := false
var interaction_locked := false
# Optional per-scene spawn markers (only if you add them)
var _spawn_from := "left"
@onready var spawn_left: Marker2D = get_node_or_null("SpawnLeft")
@onready var spawn_right: Marker2D = get_node_or_null("SpawnRight")
func set_spawn_from(side: String) -> void:
_spawn_from = side
func bind_ui(d, n, f, i, m) -> void:
dialogue_ui = d
note_ui = n
fade_rect = f
item_get_overlay = i
main_ref = m
func _ready() -> void:
await _apply_spawn_if_present()
# Persist state if revisiting
has_reward = GameState.unlock_home
if has_reward:
if exit_eicon: exit_eicon.visible = true
if box_eicon: box_eicon.visible = false
else:
if exit_eicon: exit_eicon.visible = false
if box != null and box.has_signal("interacted"):
box.interacted.connect(_on_box_interacted)
else:
push_error("Foxpost: Box interactable not found. Name the node 'Box' and attach Interactable.gd (or add a child named 'Interactable').")
if exit_to_hub != null and exit_to_hub.has_signal("interacted"):
exit_to_hub.interacted.connect(_on_exit_to_hub)
else:
push_error("Foxpost: ExitToHub interactable not found. Name the node 'ExitToHub' and attach Interactable.gd (or add a child named 'Interactable').")
func _get_interactable(node_name: String) -> Node:
var n := get_node_or_null(node_name)
if n == null:
return null
if n.has_signal("interacted"):
return n
var child := n.get_node_or_null("Interactable")
if child != null and child.has_signal("interacted"):
return child
return null
func _apply_spawn_if_present() -> void:
if spawn_left == null or spawn_right == null:
return
var target: Marker2D = spawn_left if _spawn_from == "left" else spawn_right
if target == null:
return
player.set_can_move(false)
var offset := Vector2(-32, 0) if _spawn_from == "left" else Vector2(32, 0)
player.global_position = target.global_position + offset
var t := create_tween()
t.tween_property(player, "global_position", target.global_position, 0.35)\
.set_trans(Tween.TRANS_SINE)\
.set_ease(Tween.EASE_OUT)
await t.finished
player.set_can_move(true)
# -------------------------------------------------
# Choice connection helper (exactly like Aurora)
# -------------------------------------------------
func _connect_choice_once(handler: Callable) -> void:
if dialogue_ui == null:
push_error("Foxpost: dialogue_ui is null (bind_ui not called?)")
return
if dialogue_ui.choice_selected.is_connected(handler):
dialogue_ui.choice_selected.disconnect(handler)
dialogue_ui.choice_selected.connect(handler, CONNECT_ONE_SHOT)
# -------------------------------------------------
# Post-reward reinteraction line (debounced) — same as Aurora
# -------------------------------------------------
func _show_reinteraction_line(speaker: String, text: String, portrait: Texture2D) -> void:
if interaction_locked:
return
interaction_locked = true
player.set_can_move(false)
await get_tree().process_frame
while Input.is_action_pressed("interact"):
await get_tree().process_frame
dialogue_ui.show_dialogue(speaker, text, portrait, [])
while dialogue_ui != null and dialogue_ui.is_typing():
await get_tree().process_frame
while true:
await get_tree().process_frame
if Input.is_action_just_pressed("interact"):
if dialogue_ui != null:
dialogue_ui.hide_dialogue()
break
while Input.is_action_pressed("interact"):
await get_tree().process_frame
await get_tree().create_timer(0.05).timeout
player.set_can_move(true)
interaction_locked = false
# -------------------------------------------------
# Exit back to hub (only after reward)
# -------------------------------------------------
func _on_exit_to_hub() -> void:
if not has_reward:
return
if exit_eicon:
exit_eicon.visible = false
if main_ref != null and main_ref.has_method("go_hub"):
main_ref.go_hub("left")
else:
push_error("Foxpost: main_ref.go_hub missing")
# -------------------------------------------------
# Interaction entry
# -------------------------------------------------
func _on_box_interacted() -> void:
if interaction_locked:
return
if has_reward:
await _show_reinteraction_line(
"Foxpost",
"Már kivetted a csomagod.",
foxpost_portrait
)
return
player.set_can_move(false)
_stage_picker()
# -------------------------------------------------
# Picker -> wrong loops -> right reward
# -------------------------------------------------
func _stage_picker() -> void:
dialogue_ui.show_dialogue(
"Foxpost",
"Melyik rekeszt nyitod?",
foxpost_portrait,
[
{"label": "21-es rekesz"},
{"label": "32-es rekesz"},
{"label": "53-as rekesz"},
{"label": "64-es rekesz"},
]
)
_connect_choice_once(_choice_picker)
func _choice_picker(i: int) -> void:
# Correct is 53-as rekesz (index 2)
if i == 2:
await _stage_right()
else:
_stage_wrong()
func _stage_wrong() -> void:
dialogue_ui.show_dialogue(
"Foxpost",
"Sajnos ez nem az. Próbálj egy másikat.",
foxpost_portrait,
[]
)
# Once typing ends, auto-return to picker (Aurora pattern)
while dialogue_ui != null and dialogue_ui.is_typing():
await get_tree().process_frame
if dialogue_ui:
dialogue_ui.hide_dialogue()
_stage_picker()
func _stage_right() -> void:
dialogue_ui.show_dialogue(
"Foxpost",
"**A rekesz kinyílik...**\nVedd át a csomagod, már régóta vár rád.",
foxpost_portrait,
[]
)
# Once typing ends, auto-continue to reward (Aurora pattern)
while dialogue_ui != null and dialogue_ui.is_typing():
await get_tree().process_frame
if dialogue_ui:
dialogue_ui.hide_dialogue()
await _grant_reward()
# -------------------------------------------------
# Reward: show overlay + unlock home
# -------------------------------------------------
func _grant_reward() -> void:
if interaction_locked:
return
interaction_locked = true
has_reward = true
GameState.unlock_home = true
await _play_item_get_sequence(package_icon)
if box_eicon:
box_eicon.visible = false
if exit_eicon:
exit_eicon.visible = true
player.set_can_move(true)
interaction_locked = false
# -------------------------------------------------
# Item get sequence (copied from Aurora)
# -------------------------------------------------
func _play_item_get_sequence(texture: Texture2D) -> void:
if fade_rect == null or item_get_overlay == null:
push_error("Foxpost: Missing fade_rect / item_get_overlay")
return
if texture == null:
push_error("Foxpost: Reward texture is null")
return
var icon := item_get_overlay.get_node("Center/ItemIcon") as TextureRect
if icon == null:
push_error("Foxpost: ItemGetOverlay missing Center/ItemIcon")
return
player.set_can_move(false)
fade_rect.visible = true
fade_rect.modulate.a = 0.0
item_get_overlay.visible = true
icon.visible = true
icon.texture = texture
icon.modulate = Color(1, 1, 1, 0)
icon.scale = Vector2(1.0, 1.0)
var t := create_tween()
t.set_pause_mode(Tween.TWEEN_PAUSE_PROCESS)
t.tween_property(fade_rect, "modulate:a", 1.0, 0.25).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
await t.finished
var t2 := create_tween()
t2.set_pause_mode(Tween.TWEEN_PAUSE_PROCESS)
t2.tween_property(icon, "modulate:a", 1.0, 0.18).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
t2.parallel().tween_property(icon, "scale", Vector2(1.12, 1.12), 0.18).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
t2.tween_property(icon, "scale", Vector2(1.0, 1.0), 0.18).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN)
t2.tween_property(icon, "scale", Vector2(1.16, 1.16), 0.20).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
t2.tween_property(icon, "scale", Vector2(1.0, 1.0), 0.20).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN)
t2.tween_interval(0.25)
t2.tween_property(icon, "modulate:a", 0.0, 0.20).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN)
await t2.finished
icon.visible = false
item_get_overlay.visible = false
var t3 := create_tween()
t3.set_pause_mode(Tween.TWEEN_PAUSE_PROCESS)
t3.tween_property(fade_rect, "modulate:a", 0.0, 0.25).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN)
await t3.finished
fade_rect.visible = false
player.set_can_move(true)Editor is loading...
Leave a Comment