From fc3a31d14476c3a0f3153e9f3d8269ff01db077f Mon Sep 17 00:00:00 2001 From: Nathan Singer Date: Sun, 27 Apr 2025 17:46:06 -0400 Subject: [PATCH] converts file = null to file.close() --- caching.gd | 6 ++--- deck_input.gd | 71 +++++---------------------------------------------- player.gd | 2 +- tabletop.gd | 4 ++- 4 files changed, 13 insertions(+), 70 deletions(-) diff --git a/caching.gd b/caching.gd index 060509f..a759b78 100644 --- a/caching.gd +++ b/caching.gd @@ -18,7 +18,7 @@ func _all_downloads_done() -> bool: func _setup_cache_in_mem(): var file = FileAccess.open("user://bulk.json", FileAccess.READ) _bulk_data = JSON.parse_string(file.get_as_text()) - file = null + file.close() func setup() -> Error: @@ -101,7 +101,7 @@ func _get_card_data_from_bulk(field: String, search_query: String) -> Dictionary var file = FileAccess.open("user://card_cache/" + selected_entry["id"] + "/card.json", FileAccess.WRITE) file.store_line(JSON.stringify(selected_entry, "\t")) - file = null + file.close() print("Card: " + selected_entry["name"] + "(" + selected_entry["id"] + ") found, and cached.") @@ -183,7 +183,7 @@ func get_bulk_data(force: bool) -> Error: var data_cache = FileAccess.open("user://bulk.json", FileAccess.WRITE) data_cache.store_string(unprocessed_body) - data_cache = null + data_cache.close() fetch_done.emit() diff --git a/deck_input.gd b/deck_input.gd index 2bac8ff..f60157d 100644 --- a/deck_input.gd +++ b/deck_input.gd @@ -4,69 +4,10 @@ var _caching = preload("res://caching.gd") var _decklist -var cards = "1 All That Glitters\n1 Ancestral Mask\n1 Angelic Destiny\n1 Arcane Signet\n1 Archon of Sun's Grace\n1 Austere Command\n1 Banishing Light\n1 Bear Umbra\n1 Blossoming Sands\n1 Canopy Vista\n1 Celestial Mantle\n1 Collective Resistance\n1 Command Tower\n1 Danitha Capashen, Paragon\n1 Danitha, New Benalia's Light\n1 Darksteel Mutation -1 Daybreak Coronet -1 Destiny Spinner -1 Eidolon of Blossoms -1 Eidolon of Countless Battles -1 Ellivere of the Wild Court -1 Enchantress's Presence -1 Envoy of the Ancestors -1 Ethereal Armor -1 Fertile Ground -13 Forest -1 Frantic Strength -1 Generous Gift -1 Gilded Lotus -1 Glittering Frost -1 Grasp of Fate -1 Gylwain, Casting Director -1 Hall of Heliod's Generosity -1 Heliod's Pilgrim -1 Hidden Grotto -1 Horrid Vigor -1 Idyllic Tutor -1 Jukai Naturalist -1 Kenrith's Transformation -1 Kor Spiritdancer -1 Krosan Verge -1 Light-Paws, Emperor's Voice -1 Luminous Broodmoth -1 Mantle of the Ancients -1 Overgrowth -1 Overprotect -1 Pacifism -14 Plains -1 Rancor -1 Retether -1 Rogue's Passage -1 Sage's Reverie -1 Sanctum Weaver -1 Selesnya Guildgate -1 Setessan Champion -1 Shalai, Voice of Plenty -1 Snake Umbra -1 Sol Ring -1 Solemnity -1 Songbirds' Blessing -1 Starfield Mystic -1 Swords to Plowshares -1 Tanglespan Lookout -1 Timber Paladin -1 Timely Ward -1 Tithe Taker -1 Transcendent Envoy -1 Twinblade Blessing -1 Umbra Mystic -1 Unfinished Business -1 Utopia Sprawl -1 Wild Growth -1 Winds of Rath -1 Yenna, Redtooth Regent +var cards: String -1 Sythis, Harvest's Hand" - -func _init() -> void: +func _init(_cards: String) -> void: + cards = _cards _decklist = Dictionary() @@ -81,6 +22,7 @@ func _convert_mtgo_to_cache_lookup(decklist: String) -> Dictionary: _cards[words[1]] = words[0] return _cards + func _do_free(cache) -> void: if !cache.has_emitted_all(): return @@ -98,13 +40,12 @@ func do_decklist_grab(decklist: String) -> void: cache.fetch_done.connect(_do_free.bind(cache)) + func _show_decklist() -> void: for card in _decklist: print(card + " : " + _decklist[card]) + func _ready() -> void: do_decklist_grab(cards) _show_decklist() - - - diff --git a/player.gd b/player.gd index 4f52f77..fa727e0 100644 --- a/player.gd +++ b/player.gd @@ -12,7 +12,7 @@ func _load_decks(): return # no loaded decks var file = FileAccess.open("user://decks.json", FileAccess.READ) decks = JSON.parse_string(file.get_as_text()) - file = null + file.close() # Called when the node enters the scene tree for the first time. func _ready() -> void: diff --git a/tabletop.gd b/tabletop.gd index 6bbb7b0..87630ec 100644 --- a/tabletop.gd +++ b/tabletop.gd @@ -5,6 +5,8 @@ var deck_input = preload("res://deck_input.gd") var _caching = preload("res://caching.gd") +var cards = "1 All That Glitters\n1 Ancestral Mask\n1 Angelic Destiny\n1 Arcane Signet\n1 Archon of Sun's Grace\n1 Austere Command\n1 Banishing Light\n1 Bear Umbra\n1 Blossoming Sands\n1 Canopy Vista\n1 Celestial Mantle\n1 Collective Resistance\n1 Command Tower\n1 Danitha Capashen, Paragon\n1 Danitha, New Benalia's Light\n1 Darksteel Mutation\n1 Daybreak Coronet\n1 Destiny Spinner\n1 Eidolon of Blossoms\n1 Eidolon of Countless Battles\n1 Ellivere of the Wild Court\n1 Enchantress's Presence\n1 Envoy of the Ancestors\n1 Ethereal Armor\n1 Fertile Ground\n13 Forest\n1 Frantic Strength\n1 Generous Gift\n1 Gilded Lotus\n1 Glittering Frost\n1 Grasp of Fate\n1 Gylwain, Casting Director\n1 Hall of Heliod's Generosity\n1 Heliod's Pilgrim\n1 Hidden Grotto\n1 Horrid Vigor\n1 Idyllic Tutor\n1 Jukai Naturalist\n1 Kenrith's Transformation\n1 Kor Spiritdancer\n1 Krosan Verge\n1 Light-Paws, Emperor's Voice\n1 Luminous Broodmoth\n1 Mantle of the Ancients\n1 Overgrowth\n1 Overprotect\n1 Pacifism\n14 Plains\n1 Rancor\n1 Retether\n1 Rogue's Passage\n1 Sage's Reverie\n1 Sanctum Weaver\n1 Selesnya Guildgate\n1 Setessan Champion\n1 Shalai, Voice of Plenty\n1 Snake Umbra\n1 Sol Ring\n1 Solemnity\n1 Songbirds' Blessing\n1 Starfield Mystic\n1 Swords to Plowshares\n1 Tanglespan Lookout\n1 Timber Paladin\n1 Timely Ward\n1 Tithe Takern1 Transcendent Envoy\n1 Twinblade Blessing\n1 Umbra Mystic\n1 Unfinished Business\n1 Utopia Sprawl\n1 Wild Growth\n1 Winds of Rath\n1 Yenna, Redtooth Regent\n1 Sythis, Harvest's Hand" + func _bulk_callback(cache) -> void: cache.setup() @@ -23,7 +25,7 @@ func _ready() -> void: cache.get_card_data_from_name("1996 World Champion") - var deck = deck_input.new() + var deck = deck_input.new(cards) add_child(deck)