formatting

This commit is contained in:
ShyProton 2025-04-28 00:59:02 -04:00
parent 709859abad
commit 45919dc5ae
3 changed files with 17 additions and 11 deletions

@ -86,6 +86,7 @@ func get_card_data_from_id(id: String) -> Dictionary:
return _get_card_data_from_bulk(_search_results_generic("id", id))
func _search_results_name(search_query: String) -> Dictionary:
var selected_entry = null
for entry in _bulk_data:
@ -98,7 +99,7 @@ func _search_results_name(search_query: String) -> Dictionary:
return entry
push_error("Could not find desired card {" + search_query + "}")
return {}
func _search_results_generic(field: String, search_query: String) -> Dictionary:
var selected_entry = null
@ -107,25 +108,27 @@ func _search_results_generic(field: String, search_query: String) -> Dictionary:
continue
if entry[field] == search_query:
return entry[field]
push_error("Could not find desired card {" + search_query + "}")
return {}
func _get_card_data_from_bulk(dict_entry: Dictionary) -> Dictionary:
if dict_entry["image_status"] != "missing":
_fetch_card_img(dict_entry)
var dir = DirAccess.open("user://")
dir.make_dir_recursive("user://card_cache/" + dict_entry["id"] + "/")
dir = null
var file = FileAccess.open("user://card_cache/" + dict_entry["id"] + "/card.json", FileAccess.WRITE)
var file = FileAccess.open(
"user://card_cache/" + dict_entry["id"] + "/card.json", FileAccess.WRITE
)
file.store_line(JSON.stringify(dict_entry, "\t"))
file.close()
print("Card: " + dict_entry["name"] + " (" + dict_entry["id"] + ") found, and cached.")
return dict_entry

@ -7,16 +7,17 @@ var _decklist
func _init() -> void:
_decklist = Dictionary()
func _write_to_decks(_decks: Array) -> void:
if FileAccess.file_exists("user://decks.json"):
DirAccess.remove_absolute("user://decks.json")
var file = FileAccess.open("user://decks.json", FileAccess.WRITE)
file.store_line(JSON.stringify(_decks))
file.close()
func load_decks() -> Array:
if !FileAccess.file_exists("user://decks.json"):
return []
@ -25,6 +26,7 @@ func load_decks() -> Array:
file.close()
return JSON.parse_string(file_text)
func _convert_mtgo_to_cache_lookup(decklist: String) -> Dictionary:
var _cards = {}
var lines = decklist.split("\n")
@ -46,7 +48,7 @@ func _do_free(cache) -> void:
func add_new_deck(cards: String, name: String, about = "") -> void:
var _queries = _convert_mtgo_to_cache_lookup(cards)
_do_decklist_cache(_queries)
var _decks = load_decks()
_decks.push_back({"name": name, "about": about, "decklist": _queries})
_write_to_decks(_decks)

@ -7,6 +7,7 @@ var fields: Array[Node] = []
var decks: Array[Dictionary]
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# The first field in the array will be the player's own field.