Quantcast
Channel: WoWInterface - Latest list
Viewing all articles
Browse latest Browse all 49326

EasyStorage (1.3)

$
0
0
Change Log:
--------------------
1.3
small optimization

1.2
added Remove method

1.1.2
added values check (useful to find path errors)

1.1.1
path to saved variable also can be declared as point separated string

1.1.0
supports many instances

Description:
--------------------
Library to make access to saves easy. Frequently when author accessing saved variable like "MySavedVariablePerChar.node_root.node2.somevalue" it is necessary to check is all intermediate nodes not nil. On storing same checks and initializing of tables. On erasing variables or nodes to prevent garbage of empty nodes should be done lot of checks and actions.

This simple library can do it for you. Sample

local es = LibStub("EasyStorage-1.2", false)

MyAddon_SavedVariablesPerCharacter = MyAddon_SavedVariablesPerCharacter or {}
MyAddonPerChar = es:New(MyAddon_SavedVariablesPerCharacter)

MyAddon_SavedVariablesGlobal = MyAddon_SavedVariablesGlobal or {}
MyAddonGlobal = es:New(MyAddon_SavedVariablesGlobal)
...
value1 = MyAddonPerChar:Get({"node_root", "node2"}, true)
value2 = MyAddonGlobal:Get({"node_root", "node3"}, 10)
...
MyAddonPerChar:Set({"node_root", "node1"}, nil)
MyAddonPerChar:Set({"node_root", "node2"}, some_value)
MyAddonPerChar:Set({"node_root", "node3"}, 20)
MyAddonPerChar:Set({"node_root", "node4"}, "some text")
local node_by_name = "something"
MyAddonGlobal:Set({"node_root", node_by_name}, {})
MyAddonGlobal:Set({"node_root", "very_deep_node", 1, 2, 3, 4, 5, 6}, { = 60})
...
MyAddonGlobal:Set("node_root.very_deep_node.1.2.enabled", true)


API

New(storage) returns instance
Get(array of keys, default) returns value
Get(point separated string, default) returns value
Set(array of keys, value)
Set(point separated string, value)
Remove(array of keys, key)
Remove(point separated string, key)

Requires

LibStub

Viewing all articles
Browse latest Browse all 49326

Trending Articles