From 87cb1680c0bfc748f8654924b46b417271780e72 Mon Sep 17 00:00:00 2001 From: erkkon Date: Fri, 21 Jul 2023 21:17:32 +0200 Subject: [PATCH] save in variable --- project.godot | 1 + scripts/data_manager.gd | 38 ++++++++++++++++++++++++++++++++++++++ scripts/ui/MainScreen.gd | 10 +++++++++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 scripts/data_manager.gd diff --git a/project.godot b/project.godot index de6012d..92633bc 100644 --- a/project.godot +++ b/project.godot @@ -19,6 +19,7 @@ config/icon="res://icon.png" [autoload] Global="*res://scripts/global.gd" +DataManager="*res://scripts/data_manager.gd" [display] diff --git a/scripts/data_manager.gd b/scripts/data_manager.gd new file mode 100644 index 0000000..2f5d887 --- /dev/null +++ b/scripts/data_manager.gd @@ -0,0 +1,38 @@ +extends Node + +const file_name = "open_aim_trainer.json" +const file_path = "user://" + file_name + +var game_data = {} + +func _ready(): + game_data = load_data() + print("....") + print(game_data) + + +func save_data(key, value): + + game_data[key] = value + var json = JSON.stringify(game_data) + print(json) + var file = FileAccess.open(file_path, FileAccess.WRITE) + file.store_line(json) + file.close() + +func get_data(key): + return game_data.get(key) + +func load_data(): + var json = {} + var file = FileAccess.open(file_path, FileAccess.READ) + if file: + json = JSON.new() + print(game_data) + game_data = json.parse(file.get_as_text()) + print(json.data) + file.close() + else: + print("File not found.") + + return json.data diff --git a/scripts/ui/MainScreen.gd b/scripts/ui/MainScreen.gd index 3623088..611659f 100644 --- a/scripts/ui/MainScreen.gd +++ b/scripts/ui/MainScreen.gd @@ -3,6 +3,7 @@ extends Control @onready var ResOptionButton = $MarginContainer/HBoxContainer/VBoxContainer/OptionButton @onready var resolution_label := $MarginContainer/HBoxContainer/VBoxContainer/ResolutionLabel @onready var gamelist := $Panel/ScrollContainer/VBoxContainer2 +@onready var slider_quality := $MarginContainer/HBoxContainer/VBoxContainer/QualitySlider #var Resoltuions: Dictionary = { # "3840x2160" : Vector2(3840,2160), @@ -53,6 +54,10 @@ var models3d: Dictionary = { # Called when the node enters the scene tree for the first time. func _ready(): # AddResolutions() + + if DataManager.get_data("resolution"): + slider_quality.value = DataManager.get_data("resolution") + AddGames() get_viewport().size_changed.connect(self.update_resolution_label) update_resolution_label() @@ -123,9 +128,12 @@ func _on_play_pressed(): func _on_quality_slider_value_changed(value: float) -> void: + quality_change(value) + DataManager.save_data("resolution", value) + +func quality_change(value: float) -> void: get_viewport().scaling_3d_scale = value update_resolution_label() - func _on_quit_pressed(): get_tree().quit()