-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathcache.gd
More file actions
58 lines (40 loc) · 1.46 KB
/
cache.gd
File metadata and controls
58 lines (40 loc) · 1.46 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
extends Node
const APP_CACHE_PATH = "user://.cache"
var _cache := ConfigFile.new()
var _cache_auto_save := ConfigFileSaveOnSet.new(IConfigFileLike.of_config(_cache), APP_CACHE_PATH)
func _enter_tree() -> void:
_cache.load(APP_CACHE_PATH)
func has_value(section: String, key: String) -> void:
return _cache.has_section_key(section, key)
func get_value(section: String, key: String, default: Variant = null) -> Variant:
return _cache.get_value(section, key, default)
func set_value(section: String, key: String, value: Variant) -> void:
_cache.set_value(section, key, value)
func save() -> void:
return _cache.save(APP_CACHE_PATH)
func smart_value(scope: Variant, key: String, autosave:=false) -> ConfigFileValue:
var section := section_of(scope)
assert(section != null)
return ConfigFileValue.new(
_cache_auto_save.as_config_like() if autosave else IConfigFileLike.of_config(_cache),
section,
key
)
func smart_section(scope: Variant, autosave:=false) -> ConfigFileSection:
var section := section_of(scope)
assert(section != null)
return ConfigFileSection.new(
section,
_cache_auto_save.as_config_like() if autosave else IConfigFileLike.of_config(_cache),
)
func section_of(obj: Variant) -> String:
var section := ""
if obj is String:
section = obj
elif obj is Script:
section = obj.resource_path
elif utils.obj_has_method(obj, "get_script"):
section = (obj as Object).get_script().resource_path
else:
assert(false, "!!!")
return section