blob: 3bcb1a40cf2c05eaa8347a3a99c682d9012a9ed8 (
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
38
39
40
41
42
43
44
45
|
extends Node
enum Difficulty {PEACEFUL, EASY, HARD}
var sound_level : int = 100
var difficulty = Difficulty.EASY
##########
# LOADER #
##########
func _ready():
randomize()
onready var _file = File.new()
const _SETTINGS_PATH = "user://settings.json"
func _save_data():
return {
'sound_level': sound_level,
'difficulty': difficulty,
}
func _load_data(json):
sound_level = json['sound_level']
difficulty = json['difficulty']
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()
|