From ff19560f0b8d3935e3b28f7889d9649e4bdd1e2c Mon Sep 17 00:00:00 2001 From: gotfishmakesticks <80163046+gotfishmakesticks@users.noreply.github.com> Date: Mon, 13 Nov 2023 08:57:14 +0300 Subject: [PATCH] Profile creating/loading in menu adjustments --- scenes/MainShip.tscn | 1 - scripts/game.gd | 2 ++ scripts/menu/MainMenu.gd | 14 +++++++++++++- scripts/menu/MainMenuButton.gd | 23 +++++++++++++++++++++-- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/scenes/MainShip.tscn b/scenes/MainShip.tscn index 33919f6..fa8a643 100644 --- a/scenes/MainShip.tscn +++ b/scenes/MainShip.tscn @@ -28,7 +28,6 @@ metadata/_edit_horizontal_guides_ = [] [node name="PrimaryWeapon" type="Node2D" parent="."] [node name="SingleLaser" parent="PrimaryWeapon" instance=ExtResource("4_s724s")] -position = Vector2(8, 0) [node name="SecondaryWeapon" type="Node2D" parent="."] diff --git a/scripts/game.gd b/scripts/game.gd index c0df877..7d35e0b 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -69,6 +69,8 @@ static func profile_delete(profile_name : String) -> void: static func profile_legit_check(profile_meta : Dictionary) -> Dictionary: var old_hash = [] var new_hash = [] + if profile_meta == {}: + return {} for key in profile_meta['meta']: old_hash.append(profile_meta['hash'][key]) new_hash.append((str(profile_meta['meta'][key]) + salt).sha256_buffer().hex_encode()) diff --git a/scripts/menu/MainMenu.gd b/scripts/menu/MainMenu.gd index b952d0f..6a2bf77 100644 --- a/scripts/menu/MainMenu.gd +++ b/scripts/menu/MainMenu.gd @@ -16,7 +16,9 @@ func _ready(): 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) + else: + change_menu(5) profile_status.text = "Current profile: [{profile}]".format({"profile": Game.profile.profile_meta['meta']['profile_name']}) func change_menu(id): @@ -42,6 +44,7 @@ func change_menu(id): b5.id = "Null" input.visible = true input.text = "" + input.placeholder_text = "Enter your profile name here!" 3: # Load Profile b1.id = "Null" b2.id = "LoadProfileConfirm" @@ -50,12 +53,21 @@ func change_menu(id): b5.id = "Null" input.visible = true input.text = "" + input.placeholder_text = "Enter your profile name here!" 4: # Play Menu b1.id = "LoadGame" b2.id = "NewGame" b3.id = "Back" b4.id = "Null" b5.id = "Null" + 5: # First-timer Create Profile + b1.id = "Null" + b2.id = "FirstCreateProfileConfirm" + b3.id = "Null" + b4.id = "Null" + b5.id = "Null" + input.visible = true + input.text = "" b1.change_name() b2.change_name() b3.change_name() diff --git a/scripts/menu/MainMenuButton.gd b/scripts/menu/MainMenuButton.gd index d09bd81..1488848 100644 --- a/scripts/menu/MainMenuButton.gd +++ b/scripts/menu/MainMenuButton.gd @@ -16,6 +16,7 @@ var texts = { "Back" : "Back", "Play" : "Play", "LoadGame" : "Load from Profile", + "FirstCreateProfileConfirm" : "Confirm", "Null" : Game.gameversion } @@ -34,17 +35,35 @@ func _on_button_up(): var profile_name = controller.input.text Game.profile_create(profile_name) Game.profile_load(profile_name) + controller.input.text = "" + "FirstCreateProfileConfirm": + Game.profile_create("") + Game.profile = Profile.create(Game.profile_load("")) + var profile_name = controller.input.text + Game.profile.profile_meta['meta']['last_profile'] = profile_name + Game.profile_save(get_tree().current_scene) + Game.profile_create(profile_name) + var profile_meta = Game.profile_load(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) + controller.change_menu(0) "LoadProfileConfirm": var profile_name = controller.input.text var profile_meta = Game.profile_legit_check(Game.profile_load(profile_name)) + controller.input.text = "" if profile_meta != {}: + if !Game.profile.is_root: + Game.profile = Profile.create(Game.profile_load("")) Game.profile.profile_meta['meta']['last_profile'] = profile_name + controller.input.placeholder_text = "Loaded profile {profile}.".format({"profile": profile_name}) Game.profile_save(get_tree().current_scene) Game.profile = Profile.create(profile_meta) + else: + controller.input.placeholder_text = "Could not load the given profile." var format = {"profile": Game.profile.profile_meta['meta']['profile_name']} controller.profile_status.text = "Current profile: [{profile}]".format(format) - "DeleteProfile": - Game.profile_delete("1") "ExitGame": get_tree().quit() "Profiles":