99 lines
2.9 KiB
GDScript
99 lines
2.9 KiB
GDScript
class_name CardBurner extends CenterContainer
|
|
|
|
var has_stage = false:
|
|
set(focus):
|
|
if not focus == has_stage:
|
|
if focus:
|
|
process_mode = Node.PROCESS_MODE_INHERIT
|
|
self.show()
|
|
self.mouse_filter = Control.MOUSE_FILTER_PASS
|
|
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
|
|
else:
|
|
self.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
self.hide()
|
|
process_mode = Node.PROCESS_MODE_DISABLED
|
|
has_stage = focus
|
|
|
|
@onready var cursor: CandleCursor = %CandleCursor
|
|
@onready var ancors: Array[Control] = [%Ancor1, %Ancor2, %Ancor3, %Ancor4]
|
|
|
|
func _ready():
|
|
Scenes.sign_up_for_sequence(burn_cards, Scenes.id.TRANSITION, 1)
|
|
%SkipButton.pressed.connect(card_burned.emit)
|
|
|
|
func burn_cards(_id, _repeat):
|
|
var random_card_names: Array = State.active_save_game.board_state["randoms"]
|
|
|
|
for card_name in random_card_names:
|
|
if card_name.begins_with("p"):
|
|
random_card_names.erase(card_name)
|
|
|
|
var random_cards: Array = HardCards.get_cards_by_name_array(random_card_names)["cards"]
|
|
|
|
random_cards.shuffle()
|
|
|
|
for ancor:Control in ancors:
|
|
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
|
|
|
|
|
|
Scenes.continue_sequence(self)
|
|
|
|
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:
|
|
if has_stage:
|
|
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)
|
|
|
|
|
|
|
|
var focus_cards: bool = true
|
|
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):
|
|
cursor.gamepad_mode = true
|
|
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:
|
|
card_index -= 1
|
|
Vector2.RIGHT:
|
|
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)
|