2023-11-22 05:26:11 +01:00
|
|
|
class_name DeckHolder
|
2023-11-25 11:40:53 +01:00
|
|
|
## @experimental
|
|
|
|
## A static class holding references to all decks opened in the current session.
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-11-25 11:40:53 +01:00
|
|
|
## List of decks opened this session.
|
2023-11-22 05:26:11 +01:00
|
|
|
static var decks: Array[Deck]
|
|
|
|
|
|
|
|
|
2023-11-25 11:40:53 +01:00
|
|
|
## Returns a new empty deck and assigns a new random ID to it.
|
2023-11-22 05:26:11 +01:00
|
|
|
static func add_empty_deck() -> Deck:
|
|
|
|
var deck := Deck.new()
|
|
|
|
DeckHolder.decks.append(deck)
|
|
|
|
var uuid := UUID.v4()
|
|
|
|
deck.id = uuid
|
|
|
|
return deck
|
|
|
|
|
|
|
|
|
2023-11-25 11:40:53 +01:00
|
|
|
## Opens a deck from the [param path].
|
2023-11-22 05:26:11 +01:00
|
|
|
static func open_deck_from_file(path: String) -> Deck:
|
|
|
|
var f := FileAccess.open(path, FileAccess.READ)
|
|
|
|
if f.get_error() != OK:
|
|
|
|
return null
|
|
|
|
|
|
|
|
var deck := Deck.from_dict(JSON.parse_string(f.get_as_text()), path)
|
|
|
|
DeckHolder.decks.append(deck)
|
|
|
|
|
|
|
|
return deck
|
|
|
|
|
|
|
|
|
2023-11-25 11:40:53 +01:00
|
|
|
## Unloads a deck.
|
2023-11-22 05:26:11 +01:00
|
|
|
static func close_deck(deck: Deck) -> void:
|
|
|
|
DeckHolder.decks.erase(deck)
|
2023-12-01 10:30:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
static func send_event(event_name: StringName, event_data: Dictionary = {}) -> void:
|
|
|
|
for deck in decks:
|
|
|
|
deck.send_event(event_name, event_data)
|