Browse Source

Merge pull request 'Save/Load System' (#7) from save-load-system into master

pull/8/head prototype-a736243e7b
Ryan Reed 1 month ago
parent
commit
a736243e7b
32 changed files with 392 additions and 10 deletions
  1. +12
    -0
      README.md
  2. +2
    -0
      autoloads/entity_manager.gd
  3. +12
    -0
      project.godot
  4. +41
    -0
      save_load/autoloads/save_game_manager.gd
  5. +1
    -0
      save_load/autoloads/save_game_manager.gd.uid
  6. +26
    -0
      save_load/components/save_data_component.gd
  7. +1
    -0
      save_load/components/save_data_component.gd.uid
  8. +6
    -0
      save_load/components/save_data_component.tscn
  9. +64
    -0
      save_load/components/save_level_data_component.gd
  10. +1
    -0
      save_load/components/save_level_data_component.gd.uid
  11. +6
    -0
      save_load/components/save_level_data_component.tscn
  12. +16
    -0
      save_load/resources/node_types/block_data_resource.gd
  13. +1
    -0
      save_load/resources/node_types/block_data_resource.gd.uid
  14. +12
    -0
      save_load/resources/node_types/block_data_resource.tres
  15. +20
    -0
      save_load/resources/node_types/node3d_data_resource.gd
  16. +1
    -0
      save_load/resources/node_types/node3d_data_resource.gd.uid
  17. +9
    -0
      save_load/resources/node_types/node3d_data_resource.tres
  18. +16
    -0
      save_load/resources/node_types/player_data_resource.gd
  19. +1
    -0
      save_load/resources/node_types/player_data_resource.gd.uid
  20. +10
    -0
      save_load/resources/node_types/player_data_resource.tres
  21. +8
    -0
      save_load/resources/save_game_data_resource.gd
  22. +1
    -0
      save_load/resources/save_game_data_resource.gd.uid
  23. +9
    -0
      save_load/resources/save_game_data_resource.tres
  24. +28
    -0
      save_load/resources/scene_data_resource.gd
  25. +1
    -0
      save_load/resources/scene_data_resource.gd.uid
  26. +10
    -0
      save_load/resources/scene_data_resource.tres
  27. +6
    -1
      scenes/blocks/block.tscn
  28. +29
    -3
      scenes/blocks/dropped_block.tscn
  29. +6
    -1
      scenes/player/player.tscn
  30. +1
    -0
      scenes/ui/waila.gd
  31. +30
    -2
      scenes/world/world.gd
  32. +5
    -3
      scenes/world/world.tscn

+ 12
- 0
README.md View File

@ -6,3 +6,15 @@ Building a Minecraft clone of sorts to learn Godot.
This was initially based on Sable Spirit Studio's YT series but has evolved to be quite a bit different.
## Key Bindings
| Input | Description |
| ----- | ----------- |
| `F5` | Quick Save |
| `F6` | Quick Load |
| `left-mouse-click` | Delete block |
| `right-mouse-click` | Create block |
| `scroll-wheel` | Change selected block (does not show the currently select item in the quickslots yet) |
| `Shift` | Sprint/Run |
| `Ctrl` | Crouch |

+ 2
- 0
autoloads/entity_manager.gd View File

@ -2,3 +2,5 @@ extends Node
signal create_block(id: String, position: Vector3)
signal drop_block(id: String, position: Vector3)
signal reset_world ## Used for signaling a deletion of all in the BlocksContainer and DroppedItemsContainer
signal spawn_player(transform: Transform3D)

+ 12
- 0
project.godot View File

@ -11,6 +11,7 @@ config_version=5
[application]
config/name="Skyblock"
config/version="0.0.1"
run/main_scene="uid://cgx0nawwjjj7g"
config/features=PackedStringArray("4.4", "Forward Plus")
config/icon="res://icon.svg"
@ -21,6 +22,7 @@ Globals="*res://autoloads/globals.gd"
EntityManager="*res://autoloads/entity_manager.gd"
InventoryManager="*res://autoloads/inventory_manager.gd"
DBItems="*res://autoloads/db_items.gd"
SaveGameManager="*res://save_load/autoloads/save_game_manager.gd"
[debug]
@ -139,6 +141,16 @@ open_inventory={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":73,"key_label":0,"unicode":105,"location":0,"echo":false,"script":null)
]
}
quick_load={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194337,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
quick_save={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194336,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
[layer_names]


+ 41
- 0
save_load/autoloads/save_game_manager.gd View File

@ -0,0 +1,41 @@
## Performs the actual Saving[br][br]
##
## Below is a basic definition of various components and resources for reference:[br]
## * SaveLevelDataComponent - The root save component that performs saving and loading of the actual data from disk
## * SaveDataComponent - Attached to a node that has properties that need to be saved
## * Node Type Resources - Each type of node that requires saving, such as a TileMapLayer, needs a resource created
extends Node
signal game_saved
signal game_loaded
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("quick_save"):
_save_game()
if event.is_action_pressed("quick_load"):
_load_game()
func _save_game() -> void:
var save_level_data_component: SaveLevelDataComponent = get_tree().get_first_node_in_group("save_level_data_component")
if save_level_data_component == null:
push_error("Could not find SaveLevelDataComponent node in level")
return
save_level_data_component.save_game()
game_saved.emit()
func _load_game() -> void:
EntityManager.reset_world.emit()
var save_level_data_component: SaveLevelDataComponent = get_tree().get_first_node_in_group("save_level_data_component")
if save_level_data_component == null:
push_error("Could not find SaveLevelDataComponent node in level")
return
save_level_data_component.load_game()
game_loaded.emit()

+ 1
- 0
save_load/autoloads/save_game_manager.gd.uid View File

@ -0,0 +1 @@
uid://dau7tp2xpp0w

+ 26
- 0
save_load/components/save_data_component.gd View File

@ -0,0 +1,26 @@
## Add to any node that has data we need to save
## Each node type, such as TileMapLayer, will need a resource created for it
## See `res://save_load/resources/node_types/`
class_name SaveDataComponent
extends Node
@export var save_data_resource: Node3DDataResource ## The resource describing the type of object being saved
@onready var parent_node: Node3D = get_parent()
func _ready() -> void:
add_to_group("save_data_component")
func _save_data() -> Resource:
if parent_node == null:
return
if save_data_resource == null:
push_error("save_data_resource not defined on node ", parent_node.name)
return
save_data_resource._save_data(parent_node)
return save_data_resource

+ 1
- 0
save_load/components/save_data_component.gd.uid View File

@ -0,0 +1 @@
uid://b0400fjcqflgh

+ 6
- 0
save_load/components/save_data_component.tscn View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://baki8rbf1ti0r"]
[ext_resource type="Script" uid="uid://b0400fjcqflgh" path="res://save_load/components/save_data_component.gd" id="1_nm1vf"]
[node name="SaveDataComponent" type="Node"]
script = ExtResource("1_nm1vf")

+ 64
- 0
save_load/components/save_level_data_component.gd View File

@ -0,0 +1,64 @@
## Performs the actual saving and loading of data related to this level/scene
## Utilized by the SaveGameManager
class_name SaveLevelDataComponent
extends Node
## See documentation to where this path is: https://docs.godotengine.org/en/stable/tutorials/io/data_paths.html#accessing-persistent-user-data-user[br][br]
## Default Paths:[br]
## * Windows: %APPDATA%\Godot\app_userdata\[project_name][br]
## * macOS: ~/Library/Application Support/Godot/app_userdata/[project_name][br]
## * Linux: ~/.local/share/godot/app_userdata/[project_name][br]
@export var save_game_data_path: String = "user://game_data/"
@export var save_file_name: String = "save_%s_game_data.tres"
var level_scene_name: String
var game_data_resource: SaveGameDataResource
var level_save_file_name: String
var save_game_file_path: String
func _ready() -> void:
add_to_group("save_level_data_component")
level_scene_name = get_parent().name
level_save_file_name = save_file_name % level_scene_name
save_game_file_path = save_game_data_path + level_save_file_name
func save_node_data() -> void:
var nodes: Array = get_tree().get_nodes_in_group("save_data_component")
if nodes == null: return
game_data_resource = SaveGameDataResource.new()
for node: Node in nodes:
if node is SaveDataComponent:
@warning_ignore("unsafe_method_access")
var save_data_resource: Node3DDataResource = node._save_data()
var save_final_resource: Node3DDataResource = save_data_resource.duplicate()
game_data_resource.save_data_nodes.append(save_final_resource)
func save_game() -> void:
if !DirAccess.dir_exists_absolute(save_game_data_path):
DirAccess.make_dir_absolute(save_game_data_path)
save_node_data()
var result: int = ResourceSaver.save(game_data_resource, save_game_file_path)
if result != OK:
printerr("Failed to save game: ", result)
func load_game() -> void:
if !FileAccess.file_exists(save_game_file_path):
printerr("Failed to load save. File does not exist: ", save_game_file_path)
return
game_data_resource = ResourceLoader.load(save_game_file_path)
if game_data_resource == null:
printerr("Failed to load save. Unknown format? ", save_game_file_path)
return
var root_node: Window = get_tree().root
for resource: Resource in game_data_resource.save_data_nodes:
if resource is Node3DDataResource:
(resource as Node3DDataResource)._load_data(root_node)

+ 1
- 0
save_load/components/save_level_data_component.gd.uid View File

@ -0,0 +1 @@
uid://c7x2qvyu62230

+ 6
- 0
save_load/components/save_level_data_component.tscn View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://c3pqilb6yh5kc"]
[ext_resource type="Script" uid="uid://c7x2qvyu62230" path="res://save_load/components/save_level_data_component.gd" id="1_exguq"]
[node name="SaveLevelDataComponent" type="Node"]
script = ExtResource("1_exguq")

+ 16
- 0
save_load/resources/node_types/block_data_resource.gd View File

@ -0,0 +1,16 @@
## The resource utilized for saving a Block
class_name BlockDataResource
extends Node3DDataResource
@export var block_id: String = "001"
func _save_data(node: Node3D) -> void:
super._save_data(node)
block_id = node.id
func _load_data(_window: Window) -> void:
EntityManager.create_block.emit(block_id, transform.origin)

+ 1
- 0
save_load/resources/node_types/block_data_resource.gd.uid View File

@ -0,0 +1 @@
uid://syaia0l6vjt1

+ 12
- 0
save_load/resources/node_types/block_data_resource.tres View File

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="BlockDataResource" load_steps=2 format=3 uid="uid://dfos8np8agysk"]
[ext_resource type="Script" uid="uid://syaia0l6vjt1" path="res://save_load/resources/node_types/block_data_resource.gd" id="1_a06et"]
[resource]
script = ExtResource("1_a06et")
block_id = "001"
block_position = Vector3(0, 0, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
node_path = NodePath("")
parent_node_path = NodePath("")
metadata/_custom_type_script = "uid://syaia0l6vjt1"

+ 20
- 0
save_load/resources/node_types/node3d_data_resource.gd View File

@ -0,0 +1,20 @@
## The base resource for saving a specific Node
class_name Node3DDataResource
extends Resource
@export var transform: Transform3D
@export var node_path: NodePath
@export var parent_node_path: NodePath
func _save_data(node: Node3D) -> void:
transform = node.transform
node_path = node.get_path()
var parent_node: Node3D = node.get_parent()
if parent_node != null:
parent_node_path = parent_node.get_path()
func _load_data(_window: Window) -> void:
pass

+ 1
- 0
save_load/resources/node_types/node3d_data_resource.gd.uid View File

@ -0,0 +1 @@
uid://drj0sfem1gmsk

+ 9
- 0
save_load/resources/node_types/node3d_data_resource.tres View File

@ -0,0 +1,9 @@
[gd_resource type="Resource" script_class="NodeDataResource" load_steps=2 format=3 uid="uid://dald1lud7ktsj"]
[ext_resource type="Script" uid="uid://drj0sfem1gmsk" path="res://save_load/resources/node_types/node3d_data_resource.gd" id="1_b70a7"]
[resource]
script = ExtResource("1_b70a7")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
node_path = NodePath("")
parent_node_path = NodePath("")

+ 16
- 0
save_load/resources/node_types/player_data_resource.gd View File

@ -0,0 +1,16 @@
## The resource utilized for saving a Player
class_name PlayerDataResource
extends Node3DDataResource
func _save_data(node: Node3D) -> void:
super._save_data(node)
# TODO: Save inventory or any other data
func _load_data(window: Window) -> void:
var scene_node: Node = window.get_node_or_null(node_path)
if scene_node == null: return
EntityManager.spawn_player.emit(transform)

+ 1
- 0
save_load/resources/node_types/player_data_resource.gd.uid View File

@ -0,0 +1 @@
uid://dodqpooodtguo

+ 10
- 0
save_load/resources/node_types/player_data_resource.tres View File

@ -0,0 +1,10 @@
[gd_resource type="Resource" script_class="PlayerDataResource" load_steps=2 format=3 uid="uid://bvsurbn5xgchr"]
[ext_resource type="Script" uid="uid://dodqpooodtguo" path="res://save_load/resources/node_types/player_data_resource.gd" id="1_scty6"]
[resource]
script = ExtResource("1_scty6")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)
node_path = NodePath("")
parent_node_path = NodePath("")
metadata/_custom_type_script = "uid://dodqpooodtguo"

+ 8
- 0
save_load/resources/save_game_data_resource.gd View File

@ -0,0 +1,8 @@
## The entire save structure that contains all Node3DDataResources
## Node3DDataResources will be located by the SaveLevelDataComponent
class_name SaveGameDataResource
extends Resource
@export var game_version: String = ProjectSettings.get_setting("application/config/version")
@export var save_data_nodes: Array[Node3DDataResource]

+ 1
- 0
save_load/resources/save_game_data_resource.gd.uid View File

@ -0,0 +1 @@
uid://di6ov7tpewhft

+ 9
- 0
save_load/resources/save_game_data_resource.tres View File

@ -0,0 +1,9 @@
[gd_resource type="Resource" script_class="SaveGameDataResource" load_steps=3 format=3 uid="uid://dkniygoky2jcx"]
[ext_resource type="Script" uid="uid://drj0sfem1gmsk" path="res://save_load/resources/node_types/node3d_data_resource.gd" id="1_7yx7n"]
[ext_resource type="Script" uid="uid://di6ov7tpewhft" path="res://save_load/resources/save_game_data_resource.gd" id="1_sbw5t"]
[resource]
script = ExtResource("1_sbw5t")
save_data_nodes = Array[ExtResource("1_7yx7n")]([])
metadata/_custom_type_script = "uid://di6ov7tpewhft"

+ 28
- 0
save_load/resources/scene_data_resource.gd View File

@ -0,0 +1,28 @@
## Used with the SaveDataComponent for defining node and scene_file_path
class_name SceneDataResource
extends Node3DDataResource
@export var node_name: String
@export var scene_file_path: String
func _save_data(node: Node3D) -> void:
super._save_data(node)
node_name = node.name
scene_file_path = node.scene_file_path
func _load_data(window: Window) -> void:
var parent_node: Node3D
if parent_node_path != null:
parent_node = window.get_node_or_null(parent_node_path)
var scene_node: Node3D
if node_path != null:
var scene_file_resource: Resource = load(scene_file_path)
scene_node = scene_file_resource.instantiate()
if parent_node != null and scene_node != null:
parent_node.add_child(scene_node)

+ 1
- 0
save_load/resources/scene_data_resource.gd.uid View File

@ -0,0 +1 @@
uid://bxr74kmjt6heh

+ 10
- 0
save_load/resources/scene_data_resource.tres View File

@ -0,0 +1,10 @@
[gd_resource type="Resource" script_class="SceneDataResource" load_steps=2 format=3 uid="uid://duqhhi2nlic6n"]
[ext_resource type="Script" uid="uid://bxr74kmjt6heh" path="res://save_load/resources/scene_data_resource.gd" id="1_ihw72"]
[resource]
script = ExtResource("1_ihw72")
global_position = Vector2(0, 0)
node_path = NodePath("")
parent_node_path = NodePath("")
metadata/_custom_type_script = "uid://bxr74kmjt6heh"

+ 6
- 1
scenes/blocks/block.tscn View File

@ -1,8 +1,10 @@
[gd_scene load_steps=8 format=3 uid="uid://b8evbp40gnomt"]
[gd_scene load_steps=10 format=3 uid="uid://b8evbp40gnomt"]
[ext_resource type="Script" uid="uid://buvqmrrtmxs2h" path="res://scenes/blocks/block.gd" id="1_7fut1"]
[ext_resource type="Material" uid="uid://bgc6efqf8aiqo" path="res://assets/materials/block_highlight.tres" id="2_524ei"]
[ext_resource type="Texture2D" uid="uid://dsvk3faenewrl" path="res://assets/textures/grass-block.png" id="3_qi7hx"]
[ext_resource type="PackedScene" uid="uid://baki8rbf1ti0r" path="res://save_load/components/save_data_component.tscn" id="4_60een"]
[ext_resource type="Resource" uid="uid://dfos8np8agysk" path="res://save_load/resources/node_types/block_data_resource.tres" id="5_60een"]
[sub_resource type="BoxShape3D" id="BoxShape3D_n5naa"]
@ -29,3 +31,6 @@ mesh = SubResource("BoxMesh_7fut1")
[node name="BlockMesh" type="MeshInstance3D" parent="."]
mesh = SubResource("BoxMesh_e15ke")
surface_material_override/0 = SubResource("StandardMaterial3D_4e127")
[node name="SaveDataComponent" parent="." instance=ExtResource("4_60een")]
save_data_resource = ExtResource("5_60een")

+ 29
- 3
scenes/blocks/dropped_block.tscn View File

@ -1,7 +1,9 @@
[gd_scene load_steps=7 format=3 uid="uid://bn2olldntd7a6"]
[gd_scene load_steps=13 format=3 uid="uid://bn2olldntd7a6"]
[ext_resource type="Script" uid="uid://dkd2qbndc3q1o" path="res://scenes/blocks/dropped_block.gd" id="1_50ggx"]
[ext_resource type="PackedScene" uid="uid://b8evbp40gnomt" path="res://scenes/blocks/block.tscn" id="3_qtifl"]
[ext_resource type="Script" uid="uid://buvqmrrtmxs2h" path="res://scenes/blocks/block.gd" id="2_qtifl"]
[ext_resource type="Material" uid="uid://bgc6efqf8aiqo" path="res://assets/materials/block_highlight.tres" id="3_8xfh1"]
[ext_resource type="Texture2D" uid="uid://dsvk3faenewrl" path="res://assets/textures/grass-block.png" id="3_ix4xk"]
[sub_resource type="Animation" id="Animation_kym7p"]
length = 0.001
@ -66,6 +68,18 @@ _data = {
&"start_animation": SubResource("Animation_50ggx")
}
[sub_resource type="BoxShape3D" id="BoxShape3D_n5naa"]
[sub_resource type="BoxMesh" id="BoxMesh_7fut1"]
material = ExtResource("3_8xfh1")
size = Vector3(1.01, 1.01, 1.01)
[sub_resource type="BoxMesh" id="BoxMesh_e15ke"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_4e127"]
albedo_texture = ExtResource("3_ix4xk")
texture_filter = 0
[sub_resource type="SphereShape3D" id="SphereShape3D_5kft2"]
radius = 1.0
@ -78,7 +92,19 @@ libraries = {
}
autoplay = "start_animation"
[node name="Block" parent="." instance=ExtResource("3_qtifl")]
[node name="Block" type="StaticBody3D" parent="."]
script = ExtResource("2_qtifl")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Block"]
shape = SubResource("BoxShape3D_n5naa")
[node name="HighlightMesh" type="MeshInstance3D" parent="Block"]
visible = false
mesh = SubResource("BoxMesh_7fut1")
[node name="BlockMesh" type="MeshInstance3D" parent="Block"]
mesh = SubResource("BoxMesh_e15ke")
surface_material_override/0 = SubResource("StandardMaterial3D_4e127")
[node name="PickupArea" type="Area3D" parent="Block"]
transform = Transform3D(0.965926, -0.258819, 0, 0.258819, 0.965926, 0, 0, 0, 1, 0, 0, 0)


+ 6
- 1
scenes/player/player.tscn View File

@ -1,7 +1,9 @@
[gd_scene load_steps=5 format=3 uid="uid://beu1b4leqwgh3"]
[gd_scene load_steps=7 format=3 uid="uid://beu1b4leqwgh3"]
[ext_resource type="Script" uid="uid://daly0bs0oat3j" path="res://scenes/player/player.gd" id="1_7sql3"]
[ext_resource type="Script" uid="uid://bruuttf8j7wet" path="res://scenes/player/ray_cast_look.gd" id="2_dovo2"]
[ext_resource type="PackedScene" uid="uid://baki8rbf1ti0r" path="res://save_load/components/save_data_component.tscn" id="3_lvxji"]
[ext_resource type="Resource" uid="uid://bvsurbn5xgchr" path="res://save_load/resources/node_types/player_data_resource.tres" id="4_p47bc"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_tv3cd"]
radius = 0.47
@ -39,3 +41,6 @@ script = ExtResource("2_dovo2")
[node name="RayCastCrouch" type="RayCast3D" parent="."]
editor_description = "Y should be just slightly higher than the height of the standing collision shape"
target_position = Vector3(0, 1.96, 0)
[node name="SaveDataComponent" parent="." instance=ExtResource("3_lvxji")]
save_data_resource = ExtResource("4_p47bc")

+ 1
- 0
scenes/ui/waila.gd View File

@ -30,6 +30,7 @@ func get_target() -> Block:
func hook_target(id: String) -> void:
if not Globals.enable_waila: return
if not id: return
var item: ItemResource = DBItems.data[id]
name_label.text = item.name + " (" + id + ")"


+ 30
- 2
scenes/world/world.gd View File

@ -2,18 +2,28 @@ class_name World
extends Node3D
@export var blocks_container: Node3D
@export var dropped_items_container: Node3D
@export var default_spawn_position: Vector3 = Vector3.ZERO
@export_group("Nodes and Scenes")
@export var blocks_container: Node3D ## Container where spawned blocks are added
@export var dropped_items_container: Node3D ## Container where spawned dropped items are added
@export var player_scene: PackedScene
func _ready() -> void:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
EntityManager.create_block.connect(_create_block.bind())
EntityManager.drop_block.connect(_create_dropped_block.bind())
EntityManager.reset_world.connect(_on_reset_world.bind())
EntityManager.spawn_player.connect(_spawn_player.bind())
_initialize_ground()
_create_test_blocks()
var default_transform: Transform3D = Transform3D()
default_transform.origin = default_spawn_position
_spawn_player(default_transform)
func _create_block(id: String, block_position: Vector3) -> void:
var block: Block = Globals.BLOCK_PREFAB.instantiate()
@ -35,6 +45,16 @@ func _create_test_blocks() -> void:
_create_block("00" + str(index), Vector3(index, 3, -5))
_create_dropped_block("00" + str(index), Vector3(index, 2, -3))
func _spawn_player(player_position: Transform3D) -> void:
if has_node("Player"):
$Player.queue_free()
await $Player.tree_exited
var player: Player = player_scene.instantiate()
player.transform = player_position
player.name = "Player"
add_child(player)
func _initialize_ground() -> void:
for x: int in range(-10, 11):
@ -47,3 +67,11 @@ func _initialize_ground() -> void:
EntityManager.create_block.emit("001", ground_position)
else:
EntityManager.create_block.emit("002", ground_position)
## Generally for resetting/emptying the world to allow for load_game
func _on_reset_world() -> void:
for block: Block in blocks_container.get_children():
block.queue_free()
for block: DroppedBlock in dropped_items_container.get_children():
block.queue_free()

+ 5
- 3
scenes/world/world.tscn View File

@ -1,7 +1,8 @@
[gd_scene load_steps=6 format=3 uid="uid://mkfitwqnerku"]
[gd_scene load_steps=7 format=3 uid="uid://mkfitwqnerku"]
[ext_resource type="Script" uid="uid://c0jbvki2cylct" path="res://scenes/world/world.gd" id="1_6m72w"]
[ext_resource type="PackedScene" uid="uid://beu1b4leqwgh3" path="res://scenes/player/player.tscn" id="2_sl2e5"]
[ext_resource type="PackedScene" uid="uid://c3pqilb6yh5kc" path="res://save_load/components/save_level_data_component.tscn" id="3_1fp7r"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_4rhad"]
sky_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
@ -20,6 +21,7 @@ glow_enabled = true
script = ExtResource("1_6m72w")
blocks_container = NodePath("BlocksContainer")
dropped_items_container = NodePath("DroppedItemsContainer")
player_scene = ExtResource("2_sl2e5")
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_sl2e5")
@ -28,8 +30,8 @@ environment = SubResource("Environment_sl2e5")
transform = Transform3D(-0.866025, -0.433013, 0.25, 0, 0.5, 0.866025, -0.5, 0.75, -0.433013, 0, 0, 0)
shadow_enabled = true
[node name="Player" parent="." instance=ExtResource("2_sl2e5")]
[node name="BlocksContainer" type="Node3D" parent="."]
[node name="DroppedItemsContainer" type="Node3D" parent="."]
[node name="SaveLevelDataComponent" parent="." instance=ExtResource("3_1fp7r")]

Loading…
Cancel
Save