Advertisement
Neverknow247

save_select_screen.gd

Oct 5th, 2023 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 1.58 KB | Source Code | 0 0
  1. extends Control
  2.  
  3. var stats = Stats
  4. var save_and_load = SaveAndLoad
  5.  
  6. @onready var save_one = $CenterContainer/HBoxContainer/save_one
  7. @onready var save_two = $CenterContainer/HBoxContainer/save_two
  8. @onready var save_three = $CenterContainer/HBoxContainer/save_three
  9.  
  10. @onready var name_save = $name_save
  11. @onready var save_name_edit = $name_save/CenterContainer/VBoxContainer/save_name_edit
  12.  
  13. var save_names = ["save_1","save_2","save_3"]
  14. @onready var save_buttons = [save_one,save_two,save_three]
  15.  
  16. func _ready():
  17.     update_buttons()
  18.  
  19. func update_buttons():
  20.     for i in save_names.size():
  21.         stats.save_slot = save_names[i]
  22.         save_and_load.change_save_location()
  23.         save_and_load.load_data()
  24.         save_and_load.save_all()
  25.         print(stats.save_data)
  26.         save_buttons[i].text = stats.save_data["save_name"]
  27.  
  28. func load_game():
  29.     save_and_load.change_save_location()
  30.     save_and_load.load_data()
  31.     if stats.save_data.new_save:
  32.         name_save.visible = true
  33.     else:
  34.         stats.save_data.power_on_count += 1
  35.         save_and_load.update_save_data()
  36.         get_tree().change_scene_to_file("res://menus/main_menu.tscn")
  37.  
  38. func _on_save_one_pressed():
  39.     stats.save_slot = save_names[0]
  40.     load_game()
  41.  
  42. func _on_save_two_pressed():
  43.     stats.save_slot = save_names[1]
  44.     load_game()
  45.  
  46. func _on_save_three_pressed():
  47.     stats.save_slot = save_names[2]
  48.     load_game()
  49.  
  50. func _on_enter_name_button_pressed():
  51.     stats.save_data.save_name = save_name_edit.text
  52.     stats.save_data.new_save = false
  53.     stats.save_data.power_on_count += 1
  54.     save_and_load.update_save_data()
  55.     get_tree().change_scene_to_file("res://menus/main_menu.tscn")
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement