fixes caching not working properly

This commit is contained in:
Nathan Singer 2025-04-27 17:27:39 -04:00
parent 5937b4db69
commit 1d9c3fc473
3 changed files with 33 additions and 6 deletions

View File

@ -12,15 +12,35 @@ var _emitted_start = 0
var _consts = preload("res://data/consts.gd")
func _init() -> void:
_req_headers = PackedStringArray(["User-Agent: " + _consts.APP_NAME + "/" + _consts.APP_VERSION, "Accept: */*"])
func _all_downloads_done() -> bool:
return _emitted_done == _emitted_start
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
func setup() -> Error:
if !FileAccess.file_exists("user://bulk.json"):
get_bulk_data(false)
push_error("Bulk Data was not downloaded! Downloading now!")
return FAILED
if !_all_downloads_done():
push_error("Not done downloading Bulk Data.")
return FAILED
_setup_cache_in_mem()
return OK
func _init() -> void:
_req_headers = PackedStringArray(["User-Agent: " + _consts.APP_NAME + "/" + _consts.APP_VERSION, "Accept: */*"])
fetch_done.connect(_on_end_emit)
fetch_start.connect(_on_start_emit)
func _on_start_emit() -> void:
_emitted_start += 1
@ -165,9 +185,11 @@ func get_bulk_data(force: bool) -> Error:
data_cache.store_string(unprocessed_body)
data_cache = null
fetch_done.emit()
return OK
func _notification(what):
if what == NOTIFICATION_PREDELETE:
if _emitted_done != _emitted_start:
if !_all_downloads_done():
push_error("ERR::MEM::CACHE\nCache being deleted before all threads have finished processing!")

View File

@ -64,7 +64,7 @@ func _gui_input(event: InputEvent) -> void:
MOUSE_BUTTON_RIGHT:
pass
func _unhandled_key_input(event: InputEvent) -> void:
if not event.is_action_pressed("default_action"):
return

View File

@ -5,11 +5,16 @@ var deck_input = preload("res://deck_input.gd")
var _caching = preload("res://caching.gd")
func _bulk_callback(cache) -> void:
cache.setup()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var cache = _caching.new()
add_child(cache)
cache.get_bulk_data(false)
if cache.setup() != OK:
cache.fetch_done.connect(_bulk_callback.bind(cache))
# TODO: Create 2-4 player instances as children of this tabletop node.
var player = player_class.new()