miggor-StreamGraph/classes/deck/deck_holder.gd
Lera Elvoé b36bdaf71c yag's doc sprint (#4)
documented everything (except NodeDB) in the classes/ folder

Reviewed-on: https://codeberg.org/Eroax/Re-DotDeck/pulls/4
Co-authored-by: Lera Elvoé <yagich@poto.cafe>
Co-committed-by: Lera Elvoé <yagich@poto.cafe>
2023-11-25 10:40:53 +00:00

32 lines
794 B
GDScript

class_name DeckHolder
## @experimental
## A static class holding references to all decks opened in the current session.
## List of decks opened this session.
static var decks: Array[Deck]
## Returns a new empty deck and assigns a new random ID to it.
static func add_empty_deck() -> Deck:
var deck := Deck.new()
DeckHolder.decks.append(deck)
var uuid := UUID.v4()
deck.id = uuid
return deck
## Opens a deck from the [param path].
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
## Unloads a deck.
static func close_deck(deck: Deck) -> void:
DeckHolder.decks.erase(deck)