grunk/src/util/loading_tools.gd

26 lines
932 B
GDScript3
Raw Normal View History

2025-04-22 21:30:11 -06:00
class_name LoadingTools
## Utilities for loading game states
const WORLD_SCENE := "res://src/world/world.tscn"
static func _load_world(level: PackedScene, save: SaveState = null) -> void:
var finish_load := func(world: World) -> void:
world.save_state = save
world.initial_level = level
print_debug("Loading world")
2025-04-22 21:30:11 -06:00
Game.instance.queue_scene(WORLD_SCENE).then(finish_load)
static func load_level(level_path: String, save: SaveState = null) -> void:
print_debug("Loading level from ", level_path)
2025-04-22 21:30:11 -06:00
var chain_load := func(level: PackedScene) -> void: LoadingTools._load_world(level, save)
Game.instance.queue_load(level_path).then(chain_load)
static func load_save(save_path: String) -> void:
print_debug("Loading save from ", save_path)
2025-04-22 21:30:11 -06:00
var chain_load := func(save: SaveState) -> void: load_level(save.level_path, save)
Game.instance.queue_load(save_path, ResourceLoader.CACHE_MODE_REPLACE_DEEP).then(chain_load)