View Single Post
08/12/14, 09:57 AM   #1
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
work in progress - libASV (Advanced Saved Variables)

The built in system of accessing the saved variables is a mixed blessing. While it helps with keeping the settings ordered, is relatively simple to use and allows simple versioning/return to default, it has downsides & limitations galore.
Nothing made this as obvious as the broken GetDisplayName function in 1.2.3 and it's fix in 1.3.3 and thier effect on ZO_SavedVars.

In the end a saved variable is nothing but a global variable that get's dumped to disk on UI unload and read in from disk on UI load. So many have started working with them directly. So I got the idea to make a library for that. Trying to get a bit of the simplicity and order of the original, without the limitations.

Advantages:
Unified approach wich simplifies debugging and development.
Ability to override everything - account name and character name - to get everyones data.
A new Scale "OS account wide". A specific area of the saved variable not tied to any account. This is helpfull if you want to share data between accounts, but mostly if you have data that is in no way bound to one account (runtime gathered harvensting nodes or skyshard positions, for example).

Downsides:
No versioning control (so no simple return). This is something I will not be likely to support. I might think of some way to do it later. You have to keep track of the version yourself.
No defaults - this is temporary till I ironed the basic code out.
If you switch from the Built in version to this one, you either have to reset the data or write basic migration code yourself (this should be a one time work. I can give examples).


This is the data structure (wich can be found inside your saved variable file) how it would appear in a multi-zen account, multi Character situation:
Lua Code:
  1. SavedVariableName = {
  2.     ["libASV_Strcuture_1"] = {
  3.         ["libASV_OS_user_wide"] = {
  4.              --data goes here
  5.         },
  6.         ["@acountname1"] = {
  7.             ["libASV_AccountWide"] = {},
  8.             ["Character1"] = {},
  9.             ["Character2"] = {}
  10.         },
  11.         ["@acountname2"] = {
  12.             ["libASV_AccountWide"] = {},
  13.             ["Character 3"] = {}
  14.         }
  15.     }
  16. }
Useage example:
:AccessOSUserWide("SavedVariableName") will return the table at "libASV_OS_user_wide" and create all tables that are missing along the way.
:AccountWide("SavedVariableName", [accountOverride]) gives you the libASV_AccountWide table of your account by default. Can be overridden via optional argument. This is for data not tied to any character.
:AllCharacters("SavedVariableName", [accountOverride]) Gives you a table containing all the Characters for the specified account inlcuding all the subtables. This is everything under the account name, aside from the Accont wide area. Defaults to current account. Usefull if you just want to cross access data stored on the Character level.
:CharacterWide("SavedVariableName", [accountOverride], [characterOverride]) - gives you the table for the specified account, specified character and creates tables along the way. Defaults to current, but can be overridden.