refactor(data-loader): ♻️ Restructure data loading logic with lazy loading and caching for improved efficiency
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
2dd7354c33
commit
554ed62ca3
2 changed files with 12 additions and 18 deletions
|
|
@ -24,7 +24,7 @@ const _RESOURCES_DIR_MAP: Dictionary = {
|
|||
"terrain": "tiles",
|
||||
"throne_room": "throne_rooms",
|
||||
"homeworlds": "worlds",
|
||||
"resources": "natural_resources",
|
||||
"resources": "deposits",
|
||||
"world_biomes": "ecology/biomes",
|
||||
"world_flora": "ecology/flora",
|
||||
"world_fauna": "ecology/fauna",
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ extends RefCounted
|
|||
## Reads world manifests from engine/src/worlds/, loads biome/substrate collections,
|
||||
## and registers runtime biomes into BiomeRegistry.
|
||||
|
||||
const WORLDS_BASE: String = "res://engine/src/worlds"
|
||||
const WORLDS_BASE: String = "res://resources/worlds"
|
||||
const BIOMES_BASE: String = "res://resources/biomes"
|
||||
const EVENTS_BASE: String = "res://resources/events"
|
||||
|
||||
var manifest: Dictionary = {}
|
||||
var active_world: String = ""
|
||||
|
|
@ -37,23 +39,15 @@ func load_world(world_id: String, ecology: Variant) -> void:
|
|||
if not data.is_empty():
|
||||
physics[key] = data
|
||||
|
||||
# Load subscribed event collections
|
||||
# Load subscribed events
|
||||
var events: Dictionary = {}
|
||||
for collection_id: Variant in manifest.get("subscribes_events", []):
|
||||
var collection_path: String = "%s/collections/%s" % [WORLDS_BASE, str(collection_id)]
|
||||
var collection_dir: DirAccess = DirAccess.open(collection_path)
|
||||
if collection_dir == null:
|
||||
push_warning("DataLoader: Missing event collection '%s'" % collection_id)
|
||||
for event_id: Variant in manifest.get("subscribes_events", []):
|
||||
var event_path: String = "%s/%s.json" % [EVENTS_BASE, str(event_id)]
|
||||
var entry: Dictionary = _load_json(event_path)
|
||||
if entry.is_empty():
|
||||
push_warning("DataLoader: Missing event '%s'" % event_id)
|
||||
continue
|
||||
collection_dir.list_dir_begin()
|
||||
var fname: String = collection_dir.get_next()
|
||||
while fname != "":
|
||||
if fname.ends_with(".json") and not collection_dir.current_is_dir():
|
||||
var entry: Dictionary = _load_json("%s/%s" % [collection_path, fname])
|
||||
if not entry.is_empty():
|
||||
events[fname.get_basename()] = entry
|
||||
fname = collection_dir.get_next()
|
||||
collection_dir.list_dir_end()
|
||||
events[str(event_id)] = entry
|
||||
if not events.is_empty():
|
||||
physics["events"] = events
|
||||
|
||||
|
|
@ -88,7 +82,7 @@ func load_world(world_id: String, ecology: Variant) -> void:
|
|||
|
||||
|
||||
func _load_collection_entries(collection_id: String, key: String) -> Array:
|
||||
var path: String = "%s/collections/%s/%s.json" % [WORLDS_BASE, collection_id, key]
|
||||
var path: String = "%s/%s/%s.json" % [BIOMES_BASE, collection_id, key]
|
||||
var data: Dictionary = _load_json(path)
|
||||
var entries: Array = data.get(key, [])
|
||||
if entries.is_empty():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue