formatting
This commit is contained in:
parent
709859abad
commit
45919dc5ae
19
caching.gd
19
caching.gd
@ -86,6 +86,7 @@ func get_card_data_from_id(id: String) -> Dictionary:
|
|||||||
|
|
||||||
return _get_card_data_from_bulk(_search_results_generic("id", id))
|
return _get_card_data_from_bulk(_search_results_generic("id", id))
|
||||||
|
|
||||||
|
|
||||||
func _search_results_name(search_query: String) -> Dictionary:
|
func _search_results_name(search_query: String) -> Dictionary:
|
||||||
var selected_entry = null
|
var selected_entry = null
|
||||||
for entry in _bulk_data:
|
for entry in _bulk_data:
|
||||||
@ -98,7 +99,7 @@ func _search_results_name(search_query: String) -> Dictionary:
|
|||||||
return entry
|
return entry
|
||||||
push_error("Could not find desired card {" + search_query + "}")
|
push_error("Could not find desired card {" + search_query + "}")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
func _search_results_generic(field: String, search_query: String) -> Dictionary:
|
func _search_results_generic(field: String, search_query: String) -> Dictionary:
|
||||||
var selected_entry = null
|
var selected_entry = null
|
||||||
@ -107,25 +108,27 @@ func _search_results_generic(field: String, search_query: String) -> Dictionary:
|
|||||||
continue
|
continue
|
||||||
if entry[field] == search_query:
|
if entry[field] == search_query:
|
||||||
return entry[field]
|
return entry[field]
|
||||||
|
|
||||||
push_error("Could not find desired card {" + search_query + "}")
|
push_error("Could not find desired card {" + search_query + "}")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
func _get_card_data_from_bulk(dict_entry: Dictionary) -> Dictionary:
|
func _get_card_data_from_bulk(dict_entry: Dictionary) -> Dictionary:
|
||||||
if dict_entry["image_status"] != "missing":
|
if dict_entry["image_status"] != "missing":
|
||||||
_fetch_card_img(dict_entry)
|
_fetch_card_img(dict_entry)
|
||||||
|
|
||||||
var dir = DirAccess.open("user://")
|
var dir = DirAccess.open("user://")
|
||||||
dir.make_dir_recursive("user://card_cache/" + dict_entry["id"] + "/")
|
dir.make_dir_recursive("user://card_cache/" + dict_entry["id"] + "/")
|
||||||
dir = null
|
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.store_line(JSON.stringify(dict_entry, "\t"))
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
print("Card: " + dict_entry["name"] + " (" + dict_entry["id"] + ") found, and cached.")
|
print("Card: " + dict_entry["name"] + " (" + dict_entry["id"] + ") found, and cached.")
|
||||||
|
|
||||||
return dict_entry
|
return dict_entry
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,16 +7,17 @@ var _decklist
|
|||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
_decklist = Dictionary()
|
_decklist = Dictionary()
|
||||||
|
|
||||||
|
|
||||||
func _write_to_decks(_decks: Array) -> void:
|
func _write_to_decks(_decks: Array) -> void:
|
||||||
if FileAccess.file_exists("user://decks.json"):
|
if FileAccess.file_exists("user://decks.json"):
|
||||||
DirAccess.remove_absolute("user://decks.json")
|
DirAccess.remove_absolute("user://decks.json")
|
||||||
|
|
||||||
var file = FileAccess.open("user://decks.json", FileAccess.WRITE)
|
var file = FileAccess.open("user://decks.json", FileAccess.WRITE)
|
||||||
file.store_line(JSON.stringify(_decks))
|
file.store_line(JSON.stringify(_decks))
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
func load_decks() -> Array:
|
func load_decks() -> Array:
|
||||||
if !FileAccess.file_exists("user://decks.json"):
|
if !FileAccess.file_exists("user://decks.json"):
|
||||||
return []
|
return []
|
||||||
@ -25,6 +26,7 @@ func load_decks() -> Array:
|
|||||||
file.close()
|
file.close()
|
||||||
return JSON.parse_string(file_text)
|
return JSON.parse_string(file_text)
|
||||||
|
|
||||||
|
|
||||||
func _convert_mtgo_to_cache_lookup(decklist: String) -> Dictionary:
|
func _convert_mtgo_to_cache_lookup(decklist: String) -> Dictionary:
|
||||||
var _cards = {}
|
var _cards = {}
|
||||||
var lines = decklist.split("\n")
|
var lines = decklist.split("\n")
|
||||||
@ -46,7 +48,7 @@ func _do_free(cache) -> void:
|
|||||||
func add_new_deck(cards: String, name: String, about = "") -> void:
|
func add_new_deck(cards: String, name: String, about = "") -> void:
|
||||||
var _queries = _convert_mtgo_to_cache_lookup(cards)
|
var _queries = _convert_mtgo_to_cache_lookup(cards)
|
||||||
_do_decklist_cache(_queries)
|
_do_decklist_cache(_queries)
|
||||||
|
|
||||||
var _decks = load_decks()
|
var _decks = load_decks()
|
||||||
_decks.push_back({"name": name, "about": about, "decklist": _queries})
|
_decks.push_back({"name": name, "about": about, "decklist": _queries})
|
||||||
_write_to_decks(_decks)
|
_write_to_decks(_decks)
|
||||||
|
@ -7,6 +7,7 @@ var fields: Array[Node] = []
|
|||||||
|
|
||||||
var decks: Array[Dictionary]
|
var decks: Array[Dictionary]
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
# The first field in the array will be the player's own field.
|
# The first field in the array will be the player's own field.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user