summaryrefslogtreecommitdiff
path: root/components/Settings.gd
blob: f6f0b419ce2e5cc0da13a8480bc98ea0acb2f9d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
extends Node

var sound_level : int = 100

##########
# LOADER #
##########

onready var _file = File.new()
const _SETTINGS_PATH = "user://settings.json"

func _save_data():
	return {
		'sound_level': sound_level,
	}

func _load_data(json):
	sound_level = json['sound_level']

func _load():
	if _file.file_exists(_SETTINGS_PATH):
		return
	_file.open(_SETTINGS_PATH, File.READ)
	var text = _file.get_as_text()
	var json = parse_json(text)
	_load_data(json)
	_file.close()

func save():
	var json = _save_data()
	var text = to_json(json)
	_file.open(_SETTINGS_PATH, File.WRITE)
	_file.store_string(text)
	_file.close()