Table of Contents
autoloads / preference / preference.gd
Attached Scenes
|
Note
|
No attached scenes. |
Code
extends Node
#class_name Preference
const _FILE_PATH = 'user://preference.cfg'
const DEFAULT_VALUES = {
'bgm': {
'volume': 70,
}
}
var _file : ConfigFile
var _path : String
func _ready(): restore()
func restore(_new_path = null):
_path = _new_path if _new_path else _FILE_PATH
_file = ConfigFile.new()
_file.load(_path)
func save():
_file.save(_path)
BGM.load_preference()
func bgm_volume(v=null): return _of('bgm.volume', v)
func _of(_name, value = null):
var arr = _name.split('.')
var section = arr[0]
var key = arr[1]
if value != null:
_file.set_value(section, key, value)
else:
if _file.has_section_key(section, key):
return _file.get_value(section, key)
else:
return DEFAULT_VALUES[section][key]