Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Panel
- #SAVE STUFF
- const SAVE_DIR = "user://saves/" #This is useful for HTML5 as well.
- #.json
- var SAVE_PATH = SAVE_DIR + "save_options.json"
- # Called when the node enters the scene tree for the first time.
- func _ready():
- load_data()
- pass # Replace with function body.
- func _save():
- Globals._ensure_directory_exists(SAVE_DIR)
- #1. Initialize a Data Dictionary
- var save_dict = {}
- #Audio
- save_dict = {
- "MasterVolume": $AudioConfigurationMenu/Panel/MasterVolume/HSlider.value,
- "SoundVolume": $AudioConfigurationMenu/Panel/SoundVolume/HSlider.value,
- "MusicVolume": $AudioConfigurationMenu/Panel/MusicVolume/HSlider.value,
- }
- #2. Create a file
- var save_file = File.new()
- save_file.open(SAVE_PATH,File.WRITE)
- #3. Serialize the data dictionary to JSON
- var save_string = JSON.print(save_dict, "\t")
- save_file.store_line(save_string)
- #4. Write the JSON to the file and save to disk
- save_file.close()
- return save_dict
- func load_data():
- # Try to load a file
- var save_file = File.new()
- if not save_file.file_exists(SAVE_PATH):
- return
- # Parse the file data if it exists
- save_file.open(SAVE_PATH,File.READ)
- var data = parse_json(save_file.get_as_text())
- #print(data["MasterVolume"])
- $AudioConfigurationMenu/Panel/MasterVolume/HSlider.value = data["MasterVolume"]
- $AudioConfigurationMenu/Panel/SoundVolume/HSlider.value = data["SoundVolume"]
- $AudioConfigurationMenu/Panel/MusicVolume/HSlider.value = data["MusicVolume"]
- return data
- func _on_CheckBox_toggled(button_pressed):
- OS.window_fullscreen = button_pressed
- pass # Replace with function body.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement