Game data save/load, profile autoload

This commit is contained in:
gotfishmakesticks 2023-11-12 21:06:52 +03:00
commit cf4687350d
7 changed files with 48 additions and 4 deletions

View file

@ -181,7 +181,7 @@ patch_margin_bottom = 2
script = ExtResource("2_rfxij") script = ExtResource("2_rfxij")
data = { data = {
"id": "weapon", "id": "weapon",
"position": Vector2(8, 0), "position": Vector2(16, 0),
"slot": "secondary", "slot": "secondary",
"weapon": "SingleRocketMk1" "weapon": "SingleRocketMk1"
} }
@ -271,7 +271,7 @@ patch_margin_bottom = 2
script = ExtResource("2_rfxij") script = ExtResource("2_rfxij")
data = { data = {
"id": "weapon", "id": "weapon",
"position": Vector2(16, 0), "position": Vector2(8, 0),
"slot": "primary", "slot": "primary",
"weapon": "SingleLaserMk1" "weapon": "SingleLaserMk1"
} }

View file

@ -5,6 +5,7 @@
[ext_resource type="Texture2D" uid="uid://c3gei46k8muk3" path="res://sprites/laserbox.png" id="3_ahhl5"] [ext_resource type="Texture2D" uid="uid://c3gei46k8muk3" path="res://sprites/laserbox.png" id="3_ahhl5"]
[node name="DoubleLaserMk1" type="Node2D" node_paths=PackedStringArray("shoot_timer", "spawner_points")] [node name="DoubleLaserMk1" type="Node2D" node_paths=PackedStringArray("shoot_timer", "spawner_points")]
position = Vector2(8, 0)
script = ExtResource("1_ugbl6") script = ExtResource("1_ugbl6")
projectile = ExtResource("2_b52h8") projectile = ExtResource("2_b52h8")
ammo_type = "Laser Energy" ammo_type = "Laser Energy"

View file

@ -5,6 +5,7 @@
[ext_resource type="Texture2D" uid="uid://c3gei46k8muk3" path="res://sprites/laserbox.png" id="3_n1sx7"] [ext_resource type="Texture2D" uid="uid://c3gei46k8muk3" path="res://sprites/laserbox.png" id="3_n1sx7"]
[node name="SingleLaser" type="Node2D" node_paths=PackedStringArray("shoot_timer", "spawner_points")] [node name="SingleLaser" type="Node2D" node_paths=PackedStringArray("shoot_timer", "spawner_points")]
position = Vector2(8, 0)
script = ExtResource("1_dwcuc") script = ExtResource("1_dwcuc")
projectile = ExtResource("2_eiesu") projectile = ExtResource("2_eiesu")
ammo_type = "Laser Energy" ammo_type = "Laser Energy"

View file

@ -5,6 +5,7 @@
[ext_resource type="Texture2D" uid="uid://c3gei46k8muk3" path="res://sprites/laserbox.png" id="3_7gexv"] [ext_resource type="Texture2D" uid="uid://c3gei46k8muk3" path="res://sprites/laserbox.png" id="3_7gexv"]
[node name="SingleRocketMk1" type="Node2D" node_paths=PackedStringArray("shoot_timer", "spawner_points")] [node name="SingleRocketMk1" type="Node2D" node_paths=PackedStringArray("shoot_timer", "spawner_points")]
position = Vector2(16, 0)
script = ExtResource("1_wdpx2") script = ExtResource("1_wdpx2")
projectile = ExtResource("2_fypwx") projectile = ExtResource("2_fypwx")
ammo_type = "Rockets" ammo_type = "Rockets"

View file

@ -26,6 +26,26 @@ func _ready():
ship.camera.limit_right = map_width/2.0 ship.camera.limit_right = map_width/2.0
ship.camera.limit_top = -map_height/2.0 ship.camera.limit_top = -map_height/2.0
ship.camera.limit_bottom = map_height/2.0 ship.camera.limit_bottom = map_height/2.0
if Game.profile.profile_meta.has('game_load'):
Game.profile.profile_meta.erase('game_load')
var save = Game.profile.profile_meta['game']
ship.money = save['money']
ship.hull.hp = save['hp']
ship.hull.fuel = save['fuel']
ship.hull.ammunition = save['ammo']
if save.has('primaryweapon'):
for node in ship.primary_slot.get_children():
node.queue_free()
var weapon_inst = Game.get_weapon(save['primaryweapon']).instantiate()
weapon_inst.id = save['primaryweapon']
ship.primary_slot.add_child(weapon_inst)
if save.has('secondaryweapon'):
for node in ship.secondary_slot.get_children():
node.queue_free()
var weapon_inst = Game.get_weapon(save['secondaryweapon']).instantiate()
weapon_inst.id = save['secondaryweapon']
ship.secondary_slot.add_child(weapon_inst)
func addtargetlist(body : Node2D): func addtargetlist(body : Node2D):
if !can_target.has(body): if !can_target.has(body):

View file

@ -12,6 +12,10 @@ var menu_id = 0
@onready var input = $Control/Input @onready var input = $Control/Input
func _ready(): func _ready():
var profile_meta = Game.profile_load("")
if profile_meta != {} and profile_meta['meta'].has('last_profile'):
profile_meta = Game.profile_load(profile_meta['meta']['last_profile'])
Game.profile = Profile.create(profile_meta)
change_menu(0) change_menu(0)
profile_status.text = "Current profile: [{profile}]".format({"profile": Game.profile.profile_meta['meta']['profile_name']}) profile_status.text = "Current profile: [{profile}]".format({"profile": Game.profile.profile_meta['meta']['profile_name']})
@ -19,7 +23,7 @@ func change_menu(id):
input.visible = false input.visible = false
match id: match id:
0: # Main 0: # Main
b1.id = "NewGame" b1.id = "Play"
b2.id = "Profiles" b2.id = "Profiles"
b3.id = "Settings" b3.id = "Settings"
b4.id = "Credits" b4.id = "Credits"
@ -46,6 +50,12 @@ func change_menu(id):
b5.id = "Null" b5.id = "Null"
input.visible = true input.visible = true
input.text = "" input.text = ""
4: # Play Menu
b1.id = "LoadGame"
b2.id = "NewGame"
b3.id = "Back"
b4.id = "Null"
b5.id = "Null"
b1.change_name() b1.change_name()
b2.change_name() b2.change_name()
b3.change_name() b3.change_name()

View file

@ -14,6 +14,8 @@ var texts = {
"Profiles" : "Profiles", "Profiles" : "Profiles",
"Credits" : "Credits", "Credits" : "Credits",
"Back" : "Back", "Back" : "Back",
"Play" : "Play",
"LoadGame" : "Load from Profile",
"Null" : Game.gameversion "Null" : Game.gameversion
} }
@ -35,7 +37,10 @@ func _on_button_up():
"LoadProfileConfirm": "LoadProfileConfirm":
var profile_name = controller.input.text var profile_name = controller.input.text
var profile_meta = Game.profile_legit_check(Game.profile_load(profile_name)) var profile_meta = Game.profile_legit_check(Game.profile_load(profile_name))
Game.profile = Profile.create(profile_meta) if profile_meta != {}:
Game.profile.profile_meta['meta']['last_profile'] = profile_name
Game.profile_save(get_tree().current_scene)
Game.profile = Profile.create(profile_meta)
var format = {"profile": Game.profile.profile_meta['meta']['profile_name']} var format = {"profile": Game.profile.profile_meta['meta']['profile_name']}
controller.profile_status.text = "Current profile: [{profile}]".format(format) controller.profile_status.text = "Current profile: [{profile}]".format(format)
"DeleteProfile": "DeleteProfile":
@ -56,6 +61,12 @@ func _on_button_up():
controller.change_menu(2) controller.change_menu(2)
"LoadProfile": "LoadProfile":
controller.change_menu(3) controller.change_menu(3)
"Play":
controller.change_menu(4)
"LoadGame":
if Game.profile.profile_meta.has('game'):
Game.profile.profile_meta['game_load'] = true
get_tree().change_scene_to_file("res://scenes/Space.tscn")
func change_name(): func change_name():
visible = id != "Null" visible = id != "Null"