can save and load player loc/rot and held guns
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=8 format=4 uid="uid://cwutm86yp0rk6"]
|
||||
[gd_scene load_steps=9 format=4 uid="uid://cwutm86yp0rk6"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/crown.gd" id="1_imbjk"]
|
||||
|
||||
@@ -105,6 +105,9 @@ _data = {
|
||||
"crown_float": SubResource("Animation_dcho3")
|
||||
}
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_8rss4"]
|
||||
radius = 2.0
|
||||
|
||||
[node name="Crown" type="Node3D"]
|
||||
script = ExtResource("1_imbjk")
|
||||
|
||||
@@ -118,3 +121,10 @@ libraries = {
|
||||
"": SubResource("AnimationLibrary_7qbml")
|
||||
}
|
||||
autoplay = "crown_float"
|
||||
|
||||
[node name="Area3D" type="Area3D" parent="."]
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
|
||||
shape = SubResource("SphereShape3D_8rss4")
|
||||
|
||||
@@ -95,6 +95,12 @@ theme_override_fonts/font = ExtResource("3_4nq4f")
|
||||
theme_override_font_sizes/font_size = 150
|
||||
text = "Resume"
|
||||
|
||||
[node name="Load" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("3_4nq4f")
|
||||
theme_override_font_sizes/font_size = 150
|
||||
text = "load"
|
||||
|
||||
[node name="Save & Quit" type="Button" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_fonts/font = ExtResource("3_4nq4f")
|
||||
@@ -102,4 +108,5 @@ theme_override_font_sizes/font_size = 150
|
||||
text = "Save & Quit"
|
||||
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/Resume" to="." method="_on_resume_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/Load" to="." method="_on_load_pressed"]
|
||||
[connection signal="pressed" from="MarginContainer/VBoxContainer/Save & Quit" to="." method="_on_save__quit_pressed"]
|
||||
|
||||
@@ -48,7 +48,6 @@ func _ready():
|
||||
|
||||
#Spawn Crown
|
||||
var crown_spawn = crown.instantiate()
|
||||
print("LEVELMANAGER LAST HIT " + str(SaveLoad.last_hit_path))
|
||||
if SaveLoad.last_hit_path:
|
||||
var crown_target = get_node(SaveLoad.last_hit_path)
|
||||
crown_target.add_child(crown_spawn)
|
||||
|
||||
@@ -3,13 +3,14 @@ extends Node3D
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
print("CROWN IN SCENE")
|
||||
var target = get_node(SaveLoad.last_hit_path)
|
||||
if target:
|
||||
global_rotation = Vector3(0,0,0)
|
||||
global_transform.origin = target.global_position + Vector3(0,2,0)
|
||||
|
||||
target_change()
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func target_change():
|
||||
var target = get_node(SaveLoad.last_hit_path)
|
||||
if target:
|
||||
global_rotation = Vector3(0,0,0)
|
||||
global_transform.origin = target.global_position + Vector3(0,2,0)
|
||||
|
||||
@@ -18,3 +18,7 @@ func _on_resume_pressed() -> void:
|
||||
|
||||
func _on_save__quit_pressed() -> void:
|
||||
level_control.save_quit()
|
||||
|
||||
|
||||
func _on_load_pressed() -> void:
|
||||
SaveLoad.load_data()
|
||||
|
||||
@@ -425,7 +425,7 @@ func enemy_killed():
|
||||
SaveLoad.enemies_killed += 1
|
||||
else:
|
||||
SaveLoad.enemies_killed = 1
|
||||
|
||||
|
||||
SaveLoad.save_persistent_data()
|
||||
enemy_killed_audio.play()
|
||||
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
extends Node
|
||||
|
||||
## SAVE DATA
|
||||
#Persistent
|
||||
#PERSISTENT DATA
|
||||
var last_hit_path
|
||||
var player_deaths
|
||||
var enemies_killed
|
||||
|
||||
#GAME DATA
|
||||
var player_loc
|
||||
var player_rot
|
||||
var held_guns
|
||||
var current_ammo
|
||||
var reserve_ammo
|
||||
|
||||
|
||||
## SAVE DATA PATHS
|
||||
var persistent_save_path = "user://persistent_data.save"
|
||||
var game_save_path = "user://game_save_data.save"
|
||||
|
||||
func _ready() -> void:
|
||||
if player_deaths == null:
|
||||
@@ -23,6 +32,8 @@ func save_persistent_data():
|
||||
print("SAVING PLAYER DEATHS " + str(player_deaths))
|
||||
file.store_var(enemies_killed)
|
||||
print("SAVING ENEMIES KILLED " + str(enemies_killed))
|
||||
|
||||
file.close()
|
||||
|
||||
func load_persistent_data():
|
||||
if FileAccess.file_exists(persistent_save_path):
|
||||
@@ -33,17 +44,60 @@ func load_persistent_data():
|
||||
print("PLAYER DEATHS : " + str(player_deaths))
|
||||
enemies_killed = file.get_var()
|
||||
print("ENEMIES KILLED : " + str(enemies_killed))
|
||||
|
||||
file.close()
|
||||
else:
|
||||
print("no data saved...")
|
||||
last_hit_path = null
|
||||
player_deaths = null
|
||||
enemies_killed = null
|
||||
|
||||
|
||||
func save_game_data():
|
||||
pass
|
||||
var level_control = get_tree().current_scene
|
||||
var player = level_control.player
|
||||
var file = FileAccess.open(game_save_path, FileAccess.WRITE)
|
||||
#ASSIGN DATA TO VARIABLES
|
||||
player_loc = player.global_position
|
||||
player_rot = player.global_rotation
|
||||
held_guns = save_resource_path(level_control.held_guns)
|
||||
current_ammo = level_control.ammo_current
|
||||
reserve_ammo = level_control.ammo_reserve
|
||||
|
||||
#SAVE DATA
|
||||
file.store_var(player_loc)
|
||||
file.store_var(player_rot)
|
||||
file.store_var(held_guns)
|
||||
file.store_var(current_ammo)
|
||||
file.store_var(reserve_ammo)
|
||||
|
||||
file.close()
|
||||
|
||||
func load_save_game_data():
|
||||
pass
|
||||
var level_control = get_tree().current_scene
|
||||
var player = level_control.player
|
||||
|
||||
if FileAccess.file_exists(game_save_path):
|
||||
var file = FileAccess.open(game_save_path, FileAccess.READ)
|
||||
|
||||
#GET DATA
|
||||
player_loc = file.get_var()
|
||||
player_rot = file.get_var()
|
||||
var held_guns_encoded = file.get_var()
|
||||
held_guns = load_resource_path(held_guns_encoded)
|
||||
current_ammo = file.get_var()
|
||||
reserve_ammo = file.get_var()
|
||||
|
||||
|
||||
#APPLY DATA
|
||||
player.global_position = player_loc
|
||||
player.global_rotation = player_rot
|
||||
level_control.held_guns = held_guns
|
||||
level_control.ammo_current = current_ammo
|
||||
level_control.ammo_reserve = reserve_ammo
|
||||
file.close()
|
||||
else:
|
||||
print("no data saved...")
|
||||
|
||||
func data_validate(file,variable):
|
||||
if file.get_var(variable):
|
||||
@@ -61,3 +115,22 @@ func persistent_data_calc(variable,amount):
|
||||
func load_data():
|
||||
load_persistent_data()
|
||||
load_save_game_data()
|
||||
|
||||
func save_resource_path(array):
|
||||
var final_array = []
|
||||
for i in array:
|
||||
if i is PackedScene:
|
||||
var resource_path = i.resource_path
|
||||
if resource_path != "":
|
||||
final_array.append(resource_path)
|
||||
print("Resource Path: ", resource_path)
|
||||
print("FINAL ARRAY ", final_array)
|
||||
return final_array
|
||||
|
||||
func load_resource_path(array):
|
||||
var final_array = []
|
||||
for i in array:
|
||||
var i_loaded = load(i)
|
||||
final_array.append(i_loaded)
|
||||
print("loaded ",final_array)
|
||||
return final_array
|
||||
|
||||
@@ -4,3 +4,4 @@ signal switch_changed()
|
||||
signal switch_timeout()
|
||||
signal enemy_hit()
|
||||
signal enemy_killed()
|
||||
signal king_killed()
|
||||
|
||||
@@ -190,6 +190,9 @@ func die():
|
||||
get_tree().get_root().add_child(particlespawn)
|
||||
|
||||
drop_loot(loot_amount)
|
||||
if SaveLoad.last_hit_path == str(get_path()):
|
||||
SaveLoad.last_hit_path = null
|
||||
|
||||
SignalBus.emit_signal("enemy_killed")
|
||||
queue_free()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user