Open funkydude opened 2 months ago
I'll nit up-front and suggest it should be ## PrivateSavedVariables: 1
like all the other boolean-style TOC flags.
From the description it sounds like turning this feature on would mean that the entire contents of addonSettings
in your example would be saved to an (undefined) saved variables file - so per your example all of colors
, name
, and global
should be persisted.
There's a few issues that come to mind as-described however;
I don't feel as though the character and machine-specific use cases can be ignored. Blizzard would benefit greatly from a UI security standpoint if private scoping were unilaterally in-use across all their addons, and there's no shortage of addon code today that has valid use cases for character-specific storage.
With respect to mixed use cases and migrating existing addons to use this feature, if an addon that today has both SavedVariables and SavedVariablesPerCharacter defined and then tomorrow turns on PrivateSavedVariables, what's the expected outcome?
I think this one little directive is trying to do a bit too much on its own and needs slightly splitting up.
PrivateSavedVariables
should supply a "private table" to all scripts in an addon, as per your suggestion._G
. If it's enabled, it's the private table. All other logic regarding the reading and writing of the data itself remains identical to how it functions today.SavedVariablesLoadFirst: 1
(see #414).
In practice, this would look as follows:
## PrivateSavedVariables: 1
## SavedVariables: Foo
## SavedVariablesPerCharacter: Bar
## SavedVariablesLoadFirst: 1
local _, _, SavedVariables = ...
SavedVariables.Foo = 1 -- This will be stored in account-wide saved variables file for the addon.
SavedVariables.Bar = 2 -- This will be stored in character-specific saved variables file for the addon.
SavedVariables.Potato = 3 -- This isn't defined in the TOC, and so shouldn't be persisted at all.
This is a feature request to allow addons to define saved variables that are not assigned global variables by default.
Addons can activate this by defining the following in the toc file:
## PrivateSavedVariables: true
This would send a table to each Lua file in the addon, similar to the addon scope table.
This would not replace the current system, it would run alongside it. The
addonSettings
table can be stored in the current saved variables file, or a separate one.This would also have the benefit of allowing addons to use their storage immediately, instead of waiting for their respective
ADDON_LOADED
event to read them.