Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ database, defaults = Library.LibTheodore.Database(database, defaults)
- parameters:
- defaults
- - table defining database structure and default values for each field
- - on start database is synced against this table so every entry from this table that is missing or has different type in database is set in database to default value and every entry in database that is not defined in this table is removed
- database
- - name of saved variable to be used as addon database (not reference, because LibTheodore will create database if it is missing or has wrong type)
- returns:
- defaults
- - unchanged defaults table
- database
- - table with live configuration data (saved variable)
- ]]
- local database, defaults = Library.LibTheodore.Database("MyAddonDB", {
- foo = false,
- bar = 22,
- frames = {
- player = {
- enabled = true,
- position = { x = 0, y = 0, }
- },
- target = {
- enabled = true,
- position = { x = 0, y = 0, }
- },
- },
- });
- --[[ Library.LibTheodore.Register(title, database, defaults, metadata)
- Parameters:
- title
- - addon title
- database
- - addon database
- defaults
- - addon defaults
- metadata
- - separated metadata from defaults, so defaults table is clean and there is no need to create UI element for each value saved in database
- - each entry MUST have following members:
- - path: defines path to the setting in database
- - each entry CAN have following members:
- - title: defines item title
- - description: short description of given member, shown probably in tooltip
- - renderer: function returning frame to be used as value editor, frame must have fixed height, but width will be set to a constant
- - function gets parameter metadata which contains metadata table with given field
- - frame must have methods SetValue, GetValue
- - if udefined default renderer for value type will be used, predefined renderers will be for boolean, number, string
- - callback: function called when value has changed, parameters: oldValue, newValue, defaultValue
- - can contain also additional renderer-specific settings
- ]]
- Library.LibTheodore.Register(database, defaults, "My addon title", {
- { path = "frames.player.enabled", title = "Enabled", description = "Shows or hides player frame" },
- { path = "frames.player.position", renderer = FramePositionRenderer },
- { path = "frames.target.enabled" },
- { path = "frames.target.position", renderer = FramePositionRenderer },
- });
- --[[ Alternative syntaxe
- Parameters:
- - database saved variable name
- - title
- - configuration table
- ]]
- local database = Library.LibTheodore.Register("MyAddonDB", "My addon title", {
- foo = { default = false, ignore = true },
- bar = { default = 22, ignore = true },
- frames = {
- player = {
- enabled = { default = true, title = "Enabled", description = "Shows or hides player frame" },
- position = { default = { x = 0, y = 0, }, renderer = FramePositionRenderer },
- },
- target = {
- enabled = { default = true },
- position = { default = { x = 0, y = 0, }, renderer = FramePositionRenderer }
- },
- },
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement