checheche/Robo-Bus-A31-HMI/common/util/kv_store.gd
2024-12-06 21:22:11 +08:00

28 lines
622 B
GDScript

@tool
extends Node
var config = ConfigFile.new()
const PATH = "user://kvstore.cfg"
const SECTION_DEFAULT = "default"
func _init():
if !FileAccess.file_exists(PATH):
config.save(PATH)
else:
config.load(PATH)
func put(key:String,value):
config.set_value(SECTION_DEFAULT,key,value)
return config.save(PATH)
func get_value(key:String,default):
return config.get_value(SECTION_DEFAULT,key,default)
func has(key:String) -> bool :
return config.has_section_key(SECTION_DEFAULT,key)
func remove_key(key:String):
if config.has_section_key(SECTION_DEFAULT,key) :
config.erase_section_key(SECTION_DEFAULT,key)