added basic scene manager
This commit is contained in:
parent
f694d5c4f8
commit
2cf0846597
7 changed files with 37 additions and 57 deletions
11
game.gd
11
game.gd
|
|
@ -10,7 +10,11 @@ func _ready() -> void:
|
||||||
if skip_menu == true:
|
if skip_menu == true:
|
||||||
UI.show_ingame_controls(!skip_menu)
|
UI.show_ingame_controls(!skip_menu)
|
||||||
UI.show_main_menu(!skip_menu)
|
UI.show_main_menu(!skip_menu)
|
||||||
start_new_game()
|
if SaveManager.save_exists():
|
||||||
|
continue_game()
|
||||||
|
else:
|
||||||
|
start_new_game()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# On start of the game, the main menu is shown
|
# On start of the game, the main menu is shown
|
||||||
|
|
@ -21,15 +25,14 @@ func _ready() -> void:
|
||||||
|
|
||||||
# this event comes from the MainMenu Node in the UI
|
# this event comes from the MainMenu Node in the UI
|
||||||
func start_new_game() -> void:
|
func start_new_game() -> void:
|
||||||
var world = preload("res://worlds/debug_level.tscn").instantiate()
|
|
||||||
UI.show_ingame_controls()
|
UI.show_ingame_controls()
|
||||||
|
|
||||||
# Add the starting world
|
# Add the starting world
|
||||||
%CurrentLevel.add_child(world)
|
SceneManager.set_world("res://worlds/debug_level.tscn")
|
||||||
|
|
||||||
# Add the starting player to the starting world
|
# Add the starting player to the starting world
|
||||||
var player = preload("res://entities/player/player.tscn").instantiate()
|
var player = preload("res://entities/player/player.tscn").instantiate()
|
||||||
world.add_child(player)
|
SceneManager.current_world.add_child(player)
|
||||||
|
|
||||||
# Give the player a monster
|
# Give the player a monster
|
||||||
var monster = MonsterData.new()
|
var monster = MonsterData.new()
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,8 @@
|
||||||
|
|
||||||
[node name="Game" type="Node3D"]
|
[node name="Game" type="Node3D"]
|
||||||
script = ExtResource("1_mfbtr")
|
script = ExtResource("1_mfbtr")
|
||||||
skip_menu = false
|
|
||||||
|
|
||||||
[node name="UI" parent="." instance=ExtResource("2_ynhuf")]
|
[node name="UI" parent="." instance=ExtResource("2_ynhuf")]
|
||||||
|
|
||||||
[node name="CurrentLevel" type="Node3D" parent="."]
|
[node name="CurrentScene" type="Node3D" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
|
|
||||||
22
globals/scene_manager.gd
Normal file
22
globals/scene_manager.gd
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
@onready var scene_root = $/root/Game/CurrentScene
|
||||||
|
var current_world : Node = null
|
||||||
|
|
||||||
|
func set_world(path: String):
|
||||||
|
if ResourceLoader.exists(path):
|
||||||
|
var world = load(path).instantiate()
|
||||||
|
scene_root.add_child(world)
|
||||||
|
current_world = world
|
||||||
|
else:
|
||||||
|
printerr("Level %s does not exist" % path)
|
||||||
|
|
||||||
|
func remove_world():
|
||||||
|
var world = scene_root.get_child(0)
|
||||||
|
if world == null:
|
||||||
|
printerr("No world node found")
|
||||||
|
return
|
||||||
|
|
||||||
|
scene_root.remove_child(world)
|
||||||
|
world.queue_free()
|
||||||
|
current_world = null
|
||||||
|
|
@ -20,6 +20,7 @@ config/icon="res://assets/logo/logo.png"
|
||||||
|
|
||||||
SaveManager="*res://resources/save_game/save_manager.gd"
|
SaveManager="*res://resources/save_game/save_manager.gd"
|
||||||
UI="*res://ui/ui.gd"
|
UI="*res://ui/ui.gd"
|
||||||
|
SceneManager="*res://globals/scene_manager.gd"
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
|
|
@ -34,6 +35,7 @@ window/handheld/orientation=1
|
||||||
folder_colors={
|
folder_colors={
|
||||||
"res://assets/": "red",
|
"res://assets/": "red",
|
||||||
"res://entities/": "blue",
|
"res://entities/": "blue",
|
||||||
|
"res://globals/": "purple",
|
||||||
"res://materials/": "pink",
|
"res://materials/": "pink",
|
||||||
"res://resources/": "yellow",
|
"res://resources/": "yellow",
|
||||||
"res://ui/": "green"
|
"res://ui/": "green"
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ var level: int = 1
|
||||||
var xp: 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:
|
func set_data(p_unique_id = "", current_values: Dictionary = {}, p_level: int = 1) -> void:
|
||||||
if p_unique_id.is_empty():
|
if p_unique_id.is_empty():
|
||||||
printerr("Monster.gd: No ID given")
|
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):
|
func load_base_monster_data(p_unique_id):
|
||||||
var path = "res://resources/monsters/" + p_unique_id + ".tres"
|
var path = "res://resources/monsters/" + p_unique_id + ".tres"
|
||||||
if FileAccess.file_exists(path):
|
if ResourceLoader.exists(path):
|
||||||
var base_monster = load(path)
|
var base_monster = load(path)
|
||||||
return base_monster
|
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
|
# Save a reference to the current save game
|
||||||
current_save = saved_game
|
current_save = saved_game
|
||||||
print(saved_game.party[0].display_name)
|
|
||||||
|
|
||||||
# Clean up all non-static objects from the scene
|
# Clean up all non-static objects from the scene
|
||||||
get_tree().call_group("save_nodes", "on_before_load_game")
|
get_tree().call_group("save_nodes", "on_before_load_game")
|
||||||
|
|
||||||
# Restore world data
|
# Restore world data
|
||||||
# doing it via get_tree, until the SceneManager exists
|
SceneManager.set_world(saved_game.world)
|
||||||
var _world : Node = load(saved_game.world).instantiate()
|
|
||||||
get_node("/root/Game/CurrentLevel").add_child(_world)
|
|
||||||
world = _world
|
|
||||||
#SceneManager.set_world(saved_game.world)
|
|
||||||
|
|
||||||
# Restore all other nodes
|
# Restore all other nodes
|
||||||
for node in saved_game.saved_data:
|
for node in saved_game.saved_data:
|
||||||
|
|
@ -63,8 +58,8 @@ func load_game():
|
||||||
var restored_node = scene.instantiate()
|
var restored_node = scene.instantiate()
|
||||||
|
|
||||||
# Add the item to the world
|
# Add the item to the world
|
||||||
# todo: add parent as value to save
|
# todo: add parent as value to save and restore to the parent
|
||||||
world.add_child(restored_node)
|
SceneManager.current_world.add_child(restored_node)
|
||||||
|
|
||||||
# run a callback to restore the item's state
|
# run a callback to restore the item's state
|
||||||
if restored_node.has_method("on_load_game"):
|
if restored_node.has_method("on_load_game"):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue