Advertisement
Dramiel

RIFT LibTheodore API draft

Nov 8th, 2011
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.40 KB | None | 0 0
  1. --[[ database, defaults = Library.LibTheodore.Database(database, defaults)
  2.  
  3. parameters:
  4.  
  5.     defaults
  6.         - table defining database structure and default values for each field
  7.         - 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
  8.  
  9.     database
  10.         - 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)
  11.  
  12. returns:
  13.  
  14.     defaults
  15.         - unchanged defaults table
  16.  
  17.     database
  18.         - table with live configuration data (saved variable)
  19.  
  20. ]]
  21. local database, defaults = Library.LibTheodore.Database("MyAddonDB", {
  22.     foo = false,
  23.     bar = 22,
  24.     frames = {
  25.         player = {
  26.             enabled = true,
  27.             position = { x = 0, y = 0, }
  28.         },
  29.         target = {
  30.             enabled = true,
  31.             position = { x = 0, y = 0, }
  32.         },
  33.     },
  34. });
  35.  
  36. --[[ Library.LibTheodore.Register(title, database, defaults, metadata)
  37.  
  38.  Parameters:
  39.  
  40.     title
  41.         - addon title
  42.  
  43.     database
  44.         - addon database
  45.  
  46.     defaults
  47.         - addon defaults
  48.    
  49.     metadata
  50.         - separated metadata from defaults, so defaults table is clean and there is no need to create UI element for each value saved in database
  51.         - each entry MUST have following members:
  52.             - path: defines path to the setting in database
  53.         - each entry CAN have following members:
  54.             - title: defines item title
  55.             - description: short description of given member, shown probably in tooltip
  56.             - renderer: function returning frame to be used as value editor, frame must have fixed height, but width will be set to a constant
  57.                 - function gets parameter metadata which contains metadata table with given field
  58.                 - frame must have methods SetValue, GetValue
  59.                 - if udefined default renderer for value type will be used, predefined renderers will be for boolean, number, string
  60.             - callback: function called when value has changed, parameters: oldValue, newValue, defaultValue
  61.             - can contain also additional renderer-specific settings
  62.  
  63. ]]
  64. Library.LibTheodore.Register(database, defaults, "My addon title", {
  65.     { path = "frames.player.enabled", title = "Enabled", description = "Shows or hides player frame" },
  66.     { path = "frames.player.position", renderer = FramePositionRenderer },
  67.     { path = "frames.target.enabled" },
  68.     { path = "frames.target.position", renderer = FramePositionRenderer },
  69. });
  70.  
  71. --[[ Alternative syntaxe
  72.  
  73. Parameters:
  74.     - database saved variable name
  75.     - title
  76.     - configuration table
  77.  
  78. ]]
  79. local database = Library.LibTheodore.Register("MyAddonDB", "My addon title", {
  80.     foo = { default = false, ignore = true },
  81.     bar = { default = 22, ignore = true },
  82.     frames = {
  83.         player = {
  84.             enabled = { default = true, title = "Enabled", description = "Shows or hides player frame" },
  85.             position = { default = { x = 0, y = 0, }, renderer = FramePositionRenderer },
  86.         },
  87.         target = {
  88.             enabled = { default = true },
  89.             position = { default = { x = 0, y = 0, }, renderer = FramePositionRenderer }
  90.         },
  91.     },
  92. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement