Download
(1Kb)
Download
Updated: 01-20-13 07:55 AM
Updated:01-20-13 07:55 AM
Created:09-09-12 03:26 AM
Downloads:1,946
Favorites:1
MD5:

EasyStorage

Version: 1.3
by: another [More]

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

Code:
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}, {["var"] = 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

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
There have been no comments posted to this file.
Be the first to add one.



Category Jump: