frame-of-mind/src/logic-scenes/card_burner/card_burner.gd

118 lines
3.7 KiB
GDScript3
Raw Normal View History

class_name CardBurner extends CenterContainer
2026-01-12 17:39:34 +00:00
var focused: bool = false:
set(focus):
if is_node_ready():
2026-01-12 17:39:34 +00:00
if not focus == focused:
if focus:
process_mode = Node.PROCESS_MODE_INHERIT
self.show()
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
if not PromptManager.icons == InputPrompt.Icons.KEYBOARD or true:
handle_direction_input(Vector2.UP)
else:
self.hide()
process_mode = Node.PROCESS_MODE_DISABLED
2026-01-12 17:39:34 +00:00
focused = focus
@onready var cursor: CandleCursor = %CandleCursor
@onready var ancors: Array[Control] = [%Ancor1, %Ancor2, %Ancor3, %Ancor4]
func _ready():
2026-01-05 17:18:48 +00:00
# Note: burn_cards is now called directly by the transition system, not via register_scene_actor
2025-06-03 21:18:34 +00:00
%SkipButton.pressed.connect(card_burned.emit)
func burn_cards(_id: int, _repeat: bool = false) -> void:
2026-01-18 18:16:56 +00:00
# Get all card names from the board (excluding stickies which start with "p")
var card_names: Array[StringName] = []
for item_name in State.save_game.board_positions.keys():
if not item_name.begins_with("p"):
card_names.append(item_name)
2025-06-03 21:18:34 +00:00
2026-01-18 18:16:56 +00:00
# Get card instances and shuffle them
var random_cards: Array = HardCards.get_cards_by_name_array(card_names)["cards"]
2025-06-03 21:18:34 +00:00
random_cards.shuffle()
for ancor:Control in ancors:
2025-06-03 21:18:34 +00:00
if random_cards.size() > 0:
ancor.get_child(0).queue_free()
var new_child: Card = random_cards.pop_front()
ancor.add_child(new_child)
new_child.owner = self
new_child.has_burned.connect(card_burned.emit)
await card_burned
$AnimationPlayer.play("vanish")
await $AnimationPlayer.animation_finished
signal card_burned
func handle_hover(to_handle: Area2D):
if to_handle is Card:
if to_handle.burn_state == Card.burned.NOT:
to_handle.burn_state = Card.burned.SINGED
func handle_mouse_button(event: InputEventMouseButton, card: Card):
if event.button_index == MOUSE_BUTTON_MASK_LEFT and event.is_pressed() and not event.is_echo():
card.burn_state = Card.burned.BURNING
func _input(event: InputEvent) -> void:
2026-01-12 17:39:34 +00:00
if focused:
if event.is_action_pressed("ui_up"):
handle_direction_input(Vector2.UP)
elif event.is_action_pressed("ui_down"):
handle_direction_input(Vector2.DOWN)
elif event.is_action_pressed("ui_left"):
handle_direction_input(Vector2.LEFT)
elif event.is_action_pressed("ui_right"):
handle_direction_input(Vector2.RIGHT)
elif event is InputEventMouse:
cursor.gamepad_mode = false
ancors[card_index].get_child(0)._on_mouse_exited()
elif event.is_action_pressed("ui_accept"):
ancors[card_index].get_child(0).burn_state = Card.burned.BURNING
var focus_cards: bool = false:
set(focus):
focus_cards = focus
if focus_cards:
cursor.visible = true
%SkipButton.release_focus()
card_index = card_index
else:
cursor.visible = false
%SkipButton.grab_focus()
ancors[card_index].get_child(0)._on_mouse_exited()
var card_index: int = 0:
set(index):
ancors[card_index].get_child(0)._on_mouse_exited()
card_index = index % 4
handle_hover(ancors[card_index].get_child(0))
func handle_direction_input(direction: Vector2):
if not cursor.gamepad_mode:
for ancor in ancors:
ancor.get_child(0)._on_mouse_exited()
cursor.gamepad_mode = true
focus_cards = focus_cards
match direction:
Vector2.UP:
focus_cards = true
cursor.visible = true
%SkipButton.release_focus()
card_index = card_index
Vector2.DOWN:
focus_cards = false
cursor.visible = false
%SkipButton.grab_focus()
ancors[card_index].get_child(0)._on_mouse_exited()
Vector2.LEFT:
focus_cards = true
card_index -= 1
Vector2.RIGHT:
focus_cards = true
card_index += 1
cursor.gamepad_target = ancors[card_index].get_child(0).global_position + Vector2(-120, 150)
if not focus_cards: cursor.gamepad_target += Vector2(0, 50)