2026-01-18 18:37:11 +00:00
|
|
|
class_name CardBurner
|
2026-01-18 18:21:03 +00:00
|
|
|
extends Playable
|
2025-06-02 23:49:33 +00:00
|
|
|
|
2025-08-19 09:01:12 +00:00
|
|
|
|
|
|
|
|
@onready var cursor: CandleCursor = %CandleCursor
|
|
|
|
|
@onready var ancors: Array[Control] = [%Ancor1, %Ancor2, %Ancor3, %Ancor4]
|
|
|
|
|
|
2026-01-18 18:37:11 +00:00
|
|
|
signal card_burned
|
|
|
|
|
|
2026-01-18 20:01:20 +00:00
|
|
|
var cards : Array[Card] = []
|
|
|
|
|
var _submitted := false
|
2026-01-18 18:37:11 +00:00
|
|
|
|
2025-06-02 23:49:33 +00:00
|
|
|
func _ready():
|
2026-01-18 20:01:20 +00:00
|
|
|
print_debug("CardBurner.gd: %s._ready()" % self.name)
|
|
|
|
|
super._ready()
|
2025-06-03 21:18:34 +00:00
|
|
|
%SkipButton.pressed.connect(card_burned.emit)
|
2025-06-02 23:49:33 +00:00
|
|
|
|
2026-01-18 18:37:11 +00:00
|
|
|
|
|
|
|
|
## Main play coroutine - simple linear flow for burning a card
|
|
|
|
|
func play() -> void:
|
|
|
|
|
print_debug("CardBurner: Starting card burning sequence")
|
|
|
|
|
|
|
|
|
|
# 1. Get all card names from the board (excluding stickies which start with "p")
|
2026-01-18 18:16:56 +00:00
|
|
|
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)
|
2026-01-18 18:37:11 +00:00
|
|
|
|
|
|
|
|
print_debug("CardBurner: Found %d cards to choose from" % card_names.size())
|
|
|
|
|
|
|
|
|
|
# 2. Get card instances and shuffle them
|
2026-01-18 20:01:20 +00:00
|
|
|
var stack : Array = HardCards.get_cards_by_name_array(card_names)["cards"]
|
|
|
|
|
stack.shuffle()
|
|
|
|
|
|
|
|
|
|
cards = []
|
2026-01-18 18:37:11 +00:00
|
|
|
|
|
|
|
|
# 3. Populate the 4 anchor slots with random cards
|
|
|
|
|
for ancor: Control in ancors:
|
2026-01-18 20:01:20 +00:00
|
|
|
var card: Card = stack.pop_front()
|
|
|
|
|
cards.append(card)
|
|
|
|
|
ancor.add_child(card)
|
|
|
|
|
print_debug("CardBurner: Added card '%s' to anchor" % card.name)
|
|
|
|
|
|
|
|
|
|
print("CardBurner: ", len(cards))
|
2026-01-18 18:37:11 +00:00
|
|
|
|
2026-01-18 20:23:37 +00:00
|
|
|
await appear()
|
|
|
|
|
|
2026-01-18 18:37:11 +00:00
|
|
|
# 4. Wait for player to burn a card (or skip)
|
|
|
|
|
print_debug("CardBurner: Waiting for player to burn a card...")
|
2026-01-18 20:01:20 +00:00
|
|
|
handle_direction_input(Vector2.UP)
|
2025-06-03 21:18:34 +00:00
|
|
|
await card_burned
|
2026-01-18 18:37:11 +00:00
|
|
|
|
|
|
|
|
# 5. Play vanish animation and wait for completion
|
|
|
|
|
print_debug("CardBurner: Card burned, playing vanish animation")
|
2025-06-03 21:18:34 +00:00
|
|
|
$AnimationPlayer.play("vanish")
|
|
|
|
|
await $AnimationPlayer.animation_finished
|
|
|
|
|
|
2026-01-18 18:37:11 +00:00
|
|
|
print_debug("CardBurner: Sequence complete")
|
2026-01-18 20:23:37 +00:00
|
|
|
await vanish()
|
2026-01-18 18:37:11 +00:00
|
|
|
|
2026-01-18 20:01:20 +00:00
|
|
|
|
|
|
|
|
func handle_hover(card: Draggable) -> void:
|
2026-01-18 20:02:17 +00:00
|
|
|
if _submitted: return
|
2026-01-18 18:37:11 +00:00
|
|
|
if not card is Card: return
|
2026-01-18 20:01:20 +00:00
|
|
|
selection = cards.find(card)
|
2026-01-18 20:23:37 +00:00
|
|
|
cursor.gamepad_mode = false
|
2025-06-03 21:18:34 +00:00
|
|
|
|
2026-01-18 20:01:20 +00:00
|
|
|
|
|
|
|
|
func handle_mouse_button(event: InputEventMouseButton, card: Card) -> void:
|
2025-06-03 21:18:34 +00:00
|
|
|
if event.button_index == MOUSE_BUTTON_MASK_LEFT and event.is_pressed() and not event.is_echo():
|
2026-01-18 20:01:20 +00:00
|
|
|
_submit(card)
|
|
|
|
|
|
|
|
|
|
func _submit(card : Card):
|
|
|
|
|
_submitted = true
|
2026-01-18 20:23:37 +00:00
|
|
|
%ActionPrompt.visible = false
|
2026-01-18 20:01:20 +00:00
|
|
|
%SkipButton.visible = false
|
2026-01-18 20:23:37 +00:00
|
|
|
|
2026-01-18 20:01:20 +00:00
|
|
|
await card.torch()
|
|
|
|
|
card_burned.emit()
|
|
|
|
|
|
2025-08-19 09:01:12 +00:00
|
|
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
2026-01-18 20:01:20 +00:00
|
|
|
if _submitted: return
|
|
|
|
|
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_action_pressed("ui_accept"):
|
|
|
|
|
_submit(cards[selection])
|
2025-08-19 09:01:12 +00:00
|
|
|
|
|
|
|
|
|
2025-09-04 23:58:23 +00:00
|
|
|
var focus_cards: bool = false:
|
|
|
|
|
set(focus):
|
2026-01-18 20:01:20 +00:00
|
|
|
if _submitted: return
|
2025-09-04 23:58:23 +00:00
|
|
|
focus_cards = focus
|
|
|
|
|
if focus_cards:
|
|
|
|
|
cursor.visible = true
|
|
|
|
|
%SkipButton.release_focus()
|
|
|
|
|
else:
|
|
|
|
|
cursor.visible = false
|
|
|
|
|
%SkipButton.grab_focus()
|
2026-01-18 20:01:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
var selection: int:
|
|
|
|
|
set(value):
|
|
|
|
|
if _submitted: return
|
|
|
|
|
selection = value % len(cards)
|
|
|
|
|
for i in range(len(cards)):
|
|
|
|
|
var card := cards[i]
|
|
|
|
|
card.highlighted = (selection == i)
|
|
|
|
|
card.burn_state = Card.burned.SINGED if card.highlighted else Card.burned.NOT
|
|
|
|
|
if card.highlighted:
|
2026-01-18 20:23:37 +00:00
|
|
|
cursor.show()
|
2026-01-18 20:01:20 +00:00
|
|
|
cursor.gamepad_target = card.global_position + Vector2(-120, 150)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func handle_direction_input(direction: Vector2) -> void:
|
|
|
|
|
if _submitted: return
|
2025-09-04 23:58:23 +00:00
|
|
|
if not cursor.gamepad_mode:
|
|
|
|
|
cursor.gamepad_mode = true
|
|
|
|
|
focus_cards = focus_cards
|
2026-01-18 20:01:20 +00:00
|
|
|
|
2025-08-19 09:01:12 +00:00
|
|
|
match direction:
|
|
|
|
|
Vector2.UP:
|
2026-01-18 20:23:37 +00:00
|
|
|
cursor.show()
|
2025-08-19 09:01:12 +00:00
|
|
|
focus_cards = true
|
|
|
|
|
cursor.visible = true
|
|
|
|
|
%SkipButton.release_focus()
|
2026-01-18 20:01:20 +00:00
|
|
|
selection = selection
|
2025-08-19 09:01:12 +00:00
|
|
|
Vector2.DOWN:
|
2026-01-18 20:23:37 +00:00
|
|
|
cursor.hide()
|
2025-08-19 09:01:12 +00:00
|
|
|
focus_cards = false
|
|
|
|
|
cursor.visible = false
|
|
|
|
|
%SkipButton.grab_focus()
|
|
|
|
|
Vector2.LEFT:
|
2025-09-04 23:58:23 +00:00
|
|
|
focus_cards = true
|
2026-01-18 20:01:20 +00:00
|
|
|
selection -= 1
|
2025-08-19 09:01:12 +00:00
|
|
|
Vector2.RIGHT:
|
2025-09-04 23:58:23 +00:00
|
|
|
focus_cards = true
|
2026-01-18 20:01:20 +00:00
|
|
|
selection += 1
|