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

View file

@ -5,6 +5,7 @@
[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")]
position = Vector2(8, 0)
script = ExtResource("1_ugbl6")
projectile = ExtResource("2_b52h8")
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"]
[node name="SingleLaser" type="Node2D" node_paths=PackedStringArray("shoot_timer", "spawner_points")]
position = Vector2(8, 0)
script = ExtResource("1_dwcuc")
projectile = ExtResource("2_eiesu")
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"]
[node name="SingleRocketMk1" type="Node2D" node_paths=PackedStringArray("shoot_timer", "spawner_points")]
position = Vector2(16, 0)
script = ExtResource("1_wdpx2")
projectile = ExtResource("2_fypwx")
ammo_type = "Rockets"

View file

@ -27,6 +27,26 @@ func _ready():
ship.camera.limit_top = -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):
if !can_target.has(body):
can_target.append(body)

View file

@ -12,6 +12,10 @@ var menu_id = 0
@onready var input = $Control/Input
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)
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
match id:
0: # Main
b1.id = "NewGame"
b1.id = "Play"
b2.id = "Profiles"
b3.id = "Settings"
b4.id = "Credits"
@ -46,6 +50,12 @@ func change_menu(id):
b5.id = "Null"
input.visible = true
input.text = ""
4: # Play Menu
b1.id = "LoadGame"
b2.id = "NewGame"
b3.id = "Back"
b4.id = "Null"
b5.id = "Null"
b1.change_name()
b2.change_name()
b3.change_name()

View file

@ -14,6 +14,8 @@ var texts = {
"Profiles" : "Profiles",
"Credits" : "Credits",
"Back" : "Back",
"Play" : "Play",
"LoadGame" : "Load from Profile",
"Null" : Game.gameversion
}
@ -35,6 +37,9 @@ func _on_button_up():
"LoadProfileConfirm":
var profile_name = controller.input.text
var profile_meta = Game.profile_legit_check(Game.profile_load(profile_name))
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']}
controller.profile_status.text = "Current profile: [{profile}]".format(format)
@ -56,6 +61,12 @@ func _on_button_up():
controller.change_menu(2)
"LoadProfile":
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():
visible = id != "Null"