save difficulty in prefs and apply it
This commit is contained in:
parent
0c905be6fc
commit
6d788465ab
3 changed files with 68 additions and 17 deletions
|
@ -4,21 +4,46 @@ extends PopupPanel
|
|||
|
||||
signal start_triggered(config)
|
||||
|
||||
const pref_path = "user://preferences.cfg"
|
||||
|
||||
var preferences = ConfigFile.new()
|
||||
|
||||
func _init():
|
||||
# TODO: load config with ConfigFile
|
||||
# https://docs.godotengine.org/en/stable/tutorials/io/saving_games.html
|
||||
pass
|
||||
var err = preferences.load(pref_path)
|
||||
|
||||
func _ready():
|
||||
# TODO: load previous preferences
|
||||
$Panel/HBoxContainer/Normal.toggle_mode = true
|
||||
pass
|
||||
|
||||
func _on_Cancel_pressed():
|
||||
self.hide()
|
||||
|
||||
func _on_Start_pressed():
|
||||
var config = {}
|
||||
# TODO: save config
|
||||
emit_signal("start_triggered", config)
|
||||
if $Panel/HBoxContainer/Easy.pressed:
|
||||
preferences.set_value("game", "difficulty", "easy")
|
||||
if $Panel/HBoxContainer/Normal.pressed:
|
||||
preferences.set_value("game", "difficulty", "normal")
|
||||
if $Panel/HBoxContainer/Hard.pressed:
|
||||
preferences.set_value("game", "difficulty", "hard")
|
||||
|
||||
preferences.save(pref_path)
|
||||
|
||||
emit_signal("start_triggered", preferences)
|
||||
self.hide()
|
||||
|
||||
func _on_NewGamePanel_about_to_show():
|
||||
$Panel/HBoxContainer/Easy.pressed = false
|
||||
$Panel/HBoxContainer/Normal.pressed = false
|
||||
$Panel/HBoxContainer/Hard.pressed = false
|
||||
|
||||
var difficulty = preferences.get_value("game", "difficulty", "normal")
|
||||
match difficulty:
|
||||
"easy":
|
||||
$Panel/HBoxContainer/Easy.pressed = true
|
||||
"normal":
|
||||
$Panel/HBoxContainer/Normal.pressed = true
|
||||
"hard":
|
||||
$Panel/HBoxContainer/Hard.pressed = true
|
||||
_:
|
||||
$Panel/HBoxContainer/Normal.pressed = true
|
||||
|
||||
$Panel/Start.grab_focus()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue