added basic scene manager
This commit is contained in:
parent
f694d5c4f8
commit
2cf0846597
7 changed files with 37 additions and 57 deletions
|
|
@ -28,7 +28,7 @@ var level: int = 1
|
|||
var xp: int = 1
|
||||
|
||||
|
||||
# the ID is the filename of the monster from res://resources/monsters/<filename>.tres
|
||||
# the ID is the filename of the monster from res://entities/monsters/<filename>.tres
|
||||
func set_data(p_unique_id = "", current_values: Dictionary = {}, p_level: int = 1) -> void:
|
||||
if p_unique_id.is_empty():
|
||||
printerr("Monster.gd: No ID given")
|
||||
|
|
@ -59,7 +59,7 @@ func set_data(p_unique_id = "", current_values: Dictionary = {}, p_level: int =
|
|||
|
||||
func load_base_monster_data(p_unique_id):
|
||||
var path = "res://resources/monsters/" + p_unique_id + ".tres"
|
||||
if FileAccess.file_exists(path):
|
||||
if ResourceLoader.exists(path):
|
||||
var base_monster = load(path)
|
||||
return base_monster
|
||||
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
extends Node
|
||||
|
||||
# SIGNALS
|
||||
signal inventory_changed
|
||||
|
||||
# Player data
|
||||
var player_name: String = "Player"
|
||||
var money: int = 0
|
||||
var world: String = "res://scenes/worlds/debug_level.tscn"
|
||||
|
||||
# Inventory data
|
||||
# Items with their unique id and amount
|
||||
|
||||
# Monster Party data
|
||||
# monster with their values (unique id, atk, def, tmp for now)
|
||||
var monsters: Array
|
||||
|
||||
func _init() -> void:
|
||||
set_name("SaveData")
|
||||
|
||||
func save():
|
||||
var player_data = {
|
||||
"player_name": player_name,
|
||||
"money": money,
|
||||
"world": world
|
||||
}
|
||||
|
||||
# Collect all data to save in one dictionary
|
||||
var save_dict = {
|
||||
"player_data": player_data
|
||||
}
|
||||
|
||||
return save_dict
|
||||
|
||||
func setup_new_inventory() -> void:
|
||||
var data = MonsterData.new()
|
||||
data.set_data("debuggy", {}, 5)
|
||||
print("After setting it in inventory: ", data.display_name)
|
||||
|
||||
monsters.append(data)
|
||||
inventory_changed.emit()
|
||||
|
|
@ -44,17 +44,12 @@ func load_game():
|
|||
|
||||
# Save a reference to the current save game
|
||||
current_save = saved_game
|
||||
print(saved_game.party[0].display_name)
|
||||
|
||||
# Clean up all non-static objects from the scene
|
||||
get_tree().call_group("save_nodes", "on_before_load_game")
|
||||
|
||||
# Restore world data
|
||||
# doing it via get_tree, until the SceneManager exists
|
||||
var _world : Node = load(saved_game.world).instantiate()
|
||||
get_node("/root/Game/CurrentLevel").add_child(_world)
|
||||
world = _world
|
||||
#SceneManager.set_world(saved_game.world)
|
||||
SceneManager.set_world(saved_game.world)
|
||||
|
||||
# Restore all other nodes
|
||||
for node in saved_game.saved_data:
|
||||
|
|
@ -63,8 +58,8 @@ func load_game():
|
|||
var restored_node = scene.instantiate()
|
||||
|
||||
# Add the item to the world
|
||||
# todo: add parent as value to save
|
||||
world.add_child(restored_node)
|
||||
# todo: add parent as value to save and restore to the parent
|
||||
SceneManager.current_world.add_child(restored_node)
|
||||
|
||||
# run a callback to restore the item's state
|
||||
if restored_node.has_method("on_load_game"):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue