Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. extends CanvasLayer
  2.  
  3. const SAVE_DIR = "res://saves/"
  4. var save_path1 = SAVE_DIR + "save1.txt"
  5. var save_path2 = SAVE_DIR + "save2.txt"
  6. var save_path3 = SAVE_DIR + "save3.txt"
  7.  
  8. var helper : String
  9.  
  10. onready var selector1Grup1 = $One/VBoxContainer/HBoxContainer/selector
  11. onready var Text1Grup1 = $One/VBoxContainer/HBoxContainer/Text
  12. onready var selector2Grup1 = $One/VBoxContainer/HBoxContainer2/selector
  13. onready var Text2Grup1 = $One/VBoxContainer/HBoxContainer2/Text
  14. onready var selector1Grup2 = $Two/VBoxContainer/HBoxContainer/selector
  15. onready var Text1Grup2 = $Two/VBoxContainer/HBoxContainer/Text
  16. onready var selector2Grup2 = $Two/VBoxContainer/HBoxContainer2/selector
  17. onready var Text2Grup2 = $Two/VBoxContainer/HBoxContainer2/Text
  18. onready var selector1Grup3 = $Three/VBoxContainer/HBoxContainer/selector
  19. onready var Text1Grup3 = $Three/VBoxContainer/HBoxContainer/Text
  20. onready var selector2Grup3 = $Three/VBoxContainer/HBoxContainer2/selector
  21. onready var Text2Grup3 = $Three/VBoxContainer/HBoxContainer2/Text
  22.  
  23. onready var move = $AudioStreamPlayer
  24. onready var select = $AudioStreamPlayer2
  25. onready var selector = $CenterContainer/HBoxContainer/selector
  26.  
  27. signal Health_Changed(value)
  28.  
  29. var current_selection = 0
  30. var current = 0
  31.  
  32. func _ready():
  33. get_tree().paused = true
  34. set_current_selection(current_selection)
  35. check_state(save_path1, Text1Grup1)
  36. check_state(save_path2, Text1Grup2)
  37. check_state(save_path3, Text1Grup3)
  38.  
  39.  
  40. func _process(_delta):
  41. left_right()
  42. check_state(save_path1, Text1Grup1)
  43. check_state(save_path2, Text1Grup2)
  44. check_state(save_path3, Text1Grup3)
  45. match current_selection:
  46. 0:
  47. handle_the_continue(selector1Grup1, selector2Grup1)
  48. handle_selection(save_path1)
  49. 1:
  50. handle_the_continue(selector1Grup2, selector2Grup2)
  51. handle_selection(save_path2)
  52. 2:
  53. handle_the_continue(selector1Grup3, selector2Grup3)
  54. handle_selection(save_path3)
  55. 3:
  56. if Input.is_action_just_pressed("ui_accept"):
  57. get_tree().paused = false
  58. queue_free()
  59.  
  60. func handle_selection(_save_path):
  61. if current == 0 and Input.is_action_just_pressed("ui_accept"):
  62. var file = File.new()
  63. if file.file_exists(_save_path):
  64. get_tree().paused = false
  65. var aux = _load_data(_save_path)
  66. SceneSaving.health_loaded = aux.current_health
  67. SceneSaving.max_health_loaded = aux.max_health
  68. var _haha = get_tree().change_scene(aux.current_scene)
  69. SceneSaving.player_position_loaded = Vector2(aux.player_coord_x, aux.player_coord_y)
  70.  
  71. emit_signal("Health_Changed", SceneSaving.health_loaded)
  72. else:
  73. _save_data(_save_path)
  74. elif current == 1 and Input.is_action_just_pressed("ui_accept"):
  75. delete(current_selection)
  76.  
  77. func left_right():
  78. if Input.is_action_just_pressed("ui_left") and current_selection > 0:
  79. current_selection -= 1
  80. move.play()
  81. set_current_selection(current_selection)
  82. elif Input.is_action_just_pressed("ui_right") and current_selection < 3:
  83. current_selection += 1
  84. move.play()
  85. set_current_selection(current_selection)
  86.  
  87. func set_current_selection(_current_selection : int) -> void:
  88. selector1Grup1.text = ""
  89. selector2Grup1.text = ""
  90. selector1Grup2.text = ""
  91. selector2Grup2.text = ""
  92. selector1Grup3.text = ""
  93. selector2Grup3.text = ""
  94. selector.text = ""
  95. match _current_selection:
  96. 0:
  97. selector1Grup1.text = ">"
  98. 1:
  99. selector1Grup2.text = ">"
  100. 2:
  101. selector1Grup3.text = ">"
  102. 3:
  103. selector.text = ">"
  104.  
  105. func handle_the_continue(_text: Label, _text1:Label) ->void:
  106. if Input.is_action_just_pressed("ui_down") and current < 1:
  107. current+=1
  108. if current == 1:
  109. _text.text = ""
  110. _text1.text = ">"
  111. move.play()
  112. elif Input.is_action_just_pressed("ui_up") and current > 0:
  113. current-=1
  114. if current == 0:
  115. _text.text = ">"
  116. _text1.text = ""
  117. move.play()
  118. elif Input.is_action_just_pressed("ui_right") or Input.is_action_just_pressed("ui_left"):
  119. current = 0
  120.  
  121. func delete(_current):
  122. var dir = Directory.new()
  123. match _current:
  124. 0:
  125. dir.remove(save_path1)
  126. print("deleted succsesfully")
  127. 1:
  128. dir.remove(save_path2)
  129. print("deleted succsesfully")
  130. 2:
  131. dir.remove(save_path3)
  132. print("deleted succsesfully")
  133.  
  134. func _save_data(_save_path):
  135. var dataw = {
  136. "max_health" : PlayerStats.max_health,
  137. "current_health" : PlayerStats.health,
  138. "current_scene" : SceneSaving.SceneSaver,
  139. "player_coord_x" : SceneSaving.PlayerPosition.x,
  140. "player_coord_y" : SceneSaving.PlayerPosition.y
  141. }
  142.  
  143. var dir = Directory.new()
  144. if !dir.dir_exists(SAVE_DIR):
  145. dir.make_dir_recursive(SAVE_DIR)
  146.  
  147. var file = File.new()
  148. var error = file.open(_save_path, File.WRITE)
  149. if error == OK:
  150. if not file.file_exists(_save_path):
  151. file.store_var(dataw)
  152. file.close()
  153.  
  154. func _load_data(_save_path):
  155. var file = File.new()
  156. if file.file_exists(_save_path):
  157. var error = file.open(_save_path, File.READ)
  158. if error == OK:
  159. return file.get_var()
  160. file.close()
  161.  
  162. func check_state(_save_path, _data : Label):
  163. var file = File.new()
  164. if file.file_exists(_save_path):
  165. _data.text = "Continue"
  166. else:
  167. _data.text = "Empty"
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement