online multiplayer chess game (note server currently down)
save settings
| -rw-r--r-- | Utils.gd | 7 | ||||
| -rw-r--r-- | project.godot | 1 | ||||
| -rw-r--r-- | saveload.gd | 43 | ||||
| -rw-r--r-- | ui/GameUI.tscn | 17 | ||||
| -rw-r--r-- | ui/Settings.gd | 7 |
5 files changed, 66 insertions, 9 deletions
@@ -50,10 +50,6 @@ func get_node_name(node): func walk_dir(path = "res://assets/pieces"): # walk the directory, finding the asset packs var folders := [] # init the folders - var favoritism := false - if path == "res://assets/pieces": # put favorite on top - folders.append("california") - favoritism = true var dir := Directory.new() # init the directory if dir.open(path) == OK: # open the directory dir.list_dir_begin() # list the directory @@ -63,9 +59,6 @@ func walk_dir(path = "res://assets/pieces"): # walk the directory, finding the if file_name == "." or file_name == "..": # if it is a dot or dot dot file_name = dir.get_next() # get the next file continue - if favoritism and file_name == "california": - file_name = dir.get_next() - continue folders.append(file_name) # add the folder file_name = dir.get_next() # get the next file else: diff --git a/project.godot b/project.godot index 063eedf..d9cac7d 100644 --- a/project.godot +++ b/project.godot @@ -77,6 +77,7 @@ Globals="*res://Globals.gd" Events="*res://Events.gd" Utils="*res://Utils.gd" SoundFx="*res://sounds/SoundFX.tscn" +SaveLoad="*res://saveload.gd" [debug] diff --git a/saveload.gd b/saveload.gd new file mode 100644 index 0000000..e0ea473 --- /dev/null +++ b/saveload.gd @@ -0,0 +1,43 @@ +extends Node + +const settings_file = "user://chess.settings" + +var files := { + "settings": + { # file types + "file": settings_file, + "data": + { + "vsync": OS.vsync_enabled, + "fullscreen": OS.window_fullscreen, + "borderless": OS.window_borderless, + "piece_set": "california" + } + } +} + + +func _ready(): + load_data("settings") + + +func save(type): + var file = File.new() + file.open(files[type]["file"], File.WRITE) + file.store_string(var2str(files[type]["data"])) + + +func load_data(type: String): + if check_file(type): + var file = File.new() + file.open(files[type]["file"], File.READ) + if file.get_as_text().length() > 0: + var read_dictionary: Dictionary = str2var(file.get_as_text()) + if files[type]["data"].size() == read_dictionary.size(): + files[type]["data"] = read_dictionary + file.close() + + +func check_file(type): + var file = File.new() + return file.file_exists(files[type]["file"]) diff --git a/ui/GameUI.tscn b/ui/GameUI.tscn index f54003e..3f72619 100644 --- a/ui/GameUI.tscn +++ b/ui/GameUI.tscn @@ -18,17 +18,26 @@ anchor_right = 1.0 anchor_bottom = 1.0 margin_left = -400.0 theme = ExtResource( 1 ) +__meta__ = { +"_edit_lock_": true +} [node name="Back" type="ColorRect" parent="Holder"] anchor_right = 1.0 anchor_bottom = 1.0 color = Color( 0.141176, 0.141176, 0.141176, 1 ) +__meta__ = { +"_edit_lock_": true +} [node name="VBox" type="VBoxContainer" parent="Holder/Back"] anchor_right = 1.0 anchor_bottom = 1.0 custom_constants/separation = 50 alignment = 1 +__meta__ = { +"_edit_lock_": true +} [node name="BlackTime" type="Label" parent="Holder/Back/VBox"] margin_top = 251.0 @@ -39,6 +48,10 @@ text = "00:00.0" align = 1 valign = 1 script = ExtResource( 4 ) +__meta__ = { +"_edit_group_": true, +"_edit_lock_": true +} [node name="ColorRect" type="ColorRect" parent="Holder/Back/VBox/BlackTime"] show_behind_parent = true @@ -65,6 +78,10 @@ text = "00:00.0" align = 1 valign = 1 script = ExtResource( 4 ) +__meta__ = { +"_edit_group_": true, +"_edit_lock_": true +} white = true [node name="ColorRect" type="ColorRect" parent="Holder/Back/VBox/WhiteTime"] diff --git a/ui/Settings.gd b/ui/Settings.gd index 192a599..fa12d2f 100644 --- a/ui/Settings.gd +++ b/ui/Settings.gd @@ -6,12 +6,14 @@ onready var fullscreenbutton := $ColorRect/HBoxContainer/VBoxContainer2/Fullscre onready var vsyncbutton := $ColorRect/HBoxContainer/VBoxContainer2/VsyncButton onready var borderlessbutton := $ColorRect/HBoxContainer/VBoxContainer2/Borderless -var settings := {"vsync": OS.vsync_enabled, "fullscreen": OS.window_fullscreen, "borderless": OS.window_borderless} setget set_settings +onready var settings: Dictionary = SaveLoad.files["settings"]["data"] setget set_settings func set_settings(new_settings): toggle_button_visuals(new_settings) settings = new_settings + SaveLoad.files["settings"]["data"] = settings + SaveLoad.save("settings") func toggle(onoff): @@ -28,7 +30,7 @@ func _ready(): toggle_button_visuals() for i in piece_sets: piece_set_button.add_icon_item(load("res://assets/pieces/" + i + "/wP.png"), i) - piece_set_button.selected = 0 + piece_set_button.selected = piece_sets.find(settings.piece_set) func _input(event): @@ -42,6 +44,7 @@ func _on_BackButton_pressed(): func _on_PieceSet_item_selected(index): Globals.piece_set = piece_sets[index] + self.settings.piece_set = piece_sets[index] func _on_VsyncButton_toggled(button_pressed: bool): |