Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CanvasLayer
- const SAVE_DIR = "res://saves/"
- var save_path1 = SAVE_DIR + "save1.txt"
- var save_path2 = SAVE_DIR + "save2.txt"
- var save_path3 = SAVE_DIR + "save3.txt"
- var helper : String
- onready var selector1Grup1 = $One/VBoxContainer/HBoxContainer/selector
- onready var Text1Grup1 = $One/VBoxContainer/HBoxContainer/Text
- onready var selector2Grup1 = $One/VBoxContainer/HBoxContainer2/selector
- onready var Text2Grup1 = $One/VBoxContainer/HBoxContainer2/Text
- onready var selector1Grup2 = $Two/VBoxContainer/HBoxContainer/selector
- onready var Text1Grup2 = $Two/VBoxContainer/HBoxContainer/Text
- onready var selector2Grup2 = $Two/VBoxContainer/HBoxContainer2/selector
- onready var Text2Grup2 = $Two/VBoxContainer/HBoxContainer2/Text
- onready var selector1Grup3 = $Three/VBoxContainer/HBoxContainer/selector
- onready var Text1Grup3 = $Three/VBoxContainer/HBoxContainer/Text
- onready var selector2Grup3 = $Three/VBoxContainer/HBoxContainer2/selector
- onready var Text2Grup3 = $Three/VBoxContainer/HBoxContainer2/Text
- onready var move = $AudioStreamPlayer
- onready var select = $AudioStreamPlayer2
- onready var selector = $CenterContainer/HBoxContainer/selector
- signal Health_Changed(value)
- var current_selection = 0
- var current = 0
- func _ready():
- get_tree().paused = true
- set_current_selection(current_selection)
- check_state(save_path1, Text1Grup1)
- check_state(save_path2, Text1Grup2)
- check_state(save_path3, Text1Grup3)
- func _process(_delta):
- left_right()
- check_state(save_path1, Text1Grup1)
- check_state(save_path2, Text1Grup2)
- check_state(save_path3, Text1Grup3)
- match current_selection:
- 0:
- handle_the_continue(selector1Grup1, selector2Grup1)
- handle_selection(save_path1)
- 1:
- handle_the_continue(selector1Grup2, selector2Grup2)
- handle_selection(save_path2)
- 2:
- handle_the_continue(selector1Grup3, selector2Grup3)
- handle_selection(save_path3)
- 3:
- if Input.is_action_just_pressed("ui_accept"):
- get_tree().paused = false
- queue_free()
- func handle_selection(_save_path):
- if current == 0 and Input.is_action_just_pressed("ui_accept"):
- var file = File.new()
- if file.file_exists(_save_path):
- get_tree().paused = false
- var aux = _load_data(_save_path)
- SceneSaving.health_loaded = aux.current_health
- SceneSaving.max_health_loaded = aux.max_health
- var _haha = get_tree().change_scene(aux.current_scene)
- SceneSaving.player_position_loaded = Vector2(aux.player_coord_x, aux.player_coord_y)
- emit_signal("Health_Changed", SceneSaving.health_loaded)
- else:
- _save_data(_save_path)
- elif current == 1 and Input.is_action_just_pressed("ui_accept"):
- delete(current_selection)
- func left_right():
- if Input.is_action_just_pressed("ui_left") and current_selection > 0:
- current_selection -= 1
- move.play()
- set_current_selection(current_selection)
- elif Input.is_action_just_pressed("ui_right") and current_selection < 3:
- current_selection += 1
- move.play()
- set_current_selection(current_selection)
- func set_current_selection(_current_selection : int) -> void:
- selector1Grup1.text = ""
- selector2Grup1.text = ""
- selector1Grup2.text = ""
- selector2Grup2.text = ""
- selector1Grup3.text = ""
- selector2Grup3.text = ""
- selector.text = ""
- match _current_selection:
- 0:
- selector1Grup1.text = ">"
- 1:
- selector1Grup2.text = ">"
- 2:
- selector1Grup3.text = ">"
- 3:
- selector.text = ">"
- func handle_the_continue(_text: Label, _text1:Label) ->void:
- if Input.is_action_just_pressed("ui_down") and current < 1:
- current+=1
- if current == 1:
- _text.text = ""
- _text1.text = ">"
- move.play()
- elif Input.is_action_just_pressed("ui_up") and current > 0:
- current-=1
- if current == 0:
- _text.text = ">"
- _text1.text = ""
- move.play()
- elif Input.is_action_just_pressed("ui_right") or Input.is_action_just_pressed("ui_left"):
- current = 0
- func delete(_current):
- var dir = Directory.new()
- match _current:
- 0:
- dir.remove(save_path1)
- print("deleted succsesfully")
- 1:
- dir.remove(save_path2)
- print("deleted succsesfully")
- 2:
- dir.remove(save_path3)
- print("deleted succsesfully")
- func _save_data(_save_path):
- var dataw = {
- "max_health" : PlayerStats.max_health,
- "current_health" : PlayerStats.health,
- "current_scene" : SceneSaving.SceneSaver,
- "player_coord_x" : SceneSaving.PlayerPosition.x,
- "player_coord_y" : SceneSaving.PlayerPosition.y
- }
- var dir = Directory.new()
- if !dir.dir_exists(SAVE_DIR):
- dir.make_dir_recursive(SAVE_DIR)
- var file = File.new()
- var error = file.open(_save_path, File.WRITE)
- if error == OK:
- if not file.file_exists(_save_path):
- file.store_var(dataw)
- file.close()
- func _load_data(_save_path):
- var file = File.new()
- if file.file_exists(_save_path):
- var error = file.open(_save_path, File.READ)
- if error == OK:
- return file.get_var()
- file.close()
- func check_state(_save_path, _data : Label):
- var file = File.new()
- if file.file_exists(_save_path):
- _data.text = "Continue"
- else:
- _data.text = "Empty"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement