-
-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Default Options for Glows are missing * Options dialog needs a lot of work * Default Options need to be applied to * templates * imports
- Loading branch information
1 parent
2fbe419
commit b8a7fbe
Showing
36 changed files
with
1,382 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,80 @@ | ||
--[[ Manual override for the default font and font size until proper options are built ]] | ||
local AddonName, Private = ... | ||
|
||
WeakAuras.defaultFont = "Friz Quadrata TT" | ||
WeakAuras.defaultFontSize = 12 | ||
-- TODO copied from BuffTrigger2 | ||
local function GetOrCreateSubTable(base, next, ...) | ||
if not next then | ||
return base | ||
end | ||
|
||
base[next] = base[next] or {} | ||
return GetOrCreateSubTable(base[next], ...) | ||
end | ||
|
||
local function GetSubTable(base, next, ...) | ||
if not base then | ||
return nil | ||
end | ||
|
||
if not next then | ||
return base | ||
end | ||
|
||
return GetSubTable(base[next], ...) | ||
end | ||
|
||
function Private.SetDefault(namespace, key, property, type, value) | ||
if WeakAurasSaved then | ||
local base = GetOrCreateSubTable(WeakAurasSaved, namespace, key, property) | ||
if type ~= nil then | ||
base.type = type | ||
end | ||
if value ~= nil then | ||
base.value = value | ||
end | ||
Private.callbacks:Fire("DefaultsChanged") | ||
end | ||
end | ||
|
||
function Private.GetDefault(namespace, key, property, default) | ||
if WeakAurasSaved then | ||
local base = GetSubTable(WeakAurasSaved, namespace, key, property) | ||
if base then | ||
return base.type, base.value | ||
else | ||
return nil, default | ||
end | ||
end | ||
end | ||
|
||
function Private.ApplyDefaults(data, action, mapping) | ||
for defaultPath, settingsPath in pairs(mapping) do | ||
local namespace, key, property = defaultPath[1], defaultPath[2], defaultPath[3] | ||
local savedApplyType, value = Private.GetDefault(namespace, key, property, nil) | ||
|
||
local apply = false | ||
-- TODO template ? | ||
if action == "import" then | ||
apply = savedApplyType == 2 or savedApplyType == 3 | ||
elseif action == "new" then | ||
apply = savedApplyType == 1 or savedApplyType == 3 | ||
elseif action == "validate" then | ||
-- Nothing to do, validation can be done without user templates | ||
end | ||
|
||
if apply then | ||
local tablePath | ||
local property | ||
if type(settingsPath) == "table" then | ||
tablePath = CopyTable(settingsPath) | ||
tablePath[#tablePath] = nil | ||
property = settingsPath[#settingsPath] | ||
else | ||
tablePath ={} | ||
property = settingsPath | ||
end | ||
|
||
local settingsBase = GetOrCreateSubTable(data, unpack(tablePath)) | ||
settingsBase[property] = value | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
if not WeakAuras.IsCorrectVersion() then return end | ||
local AddonName, Private = ... | ||
|
||
-- TODO copied from BuffTrigger2 | ||
local function GetOrCreateSubTable(base, next, ...) | ||
if not next then | ||
return base | ||
end | ||
|
||
base[next] = base[next] or {} | ||
return GetOrCreateSubTable(base[next], ...) | ||
end | ||
|
||
local function GetSubTable(base, next, ...) | ||
if not base then | ||
return nil | ||
end | ||
|
||
if not next then | ||
return base | ||
end | ||
|
||
return GetSubTable(base[next], ...) | ||
end | ||
|
||
local function ApplyDefaults(data, action, mapping) | ||
for defaultPath, settingsPath in pairs(mapping) do | ||
local namespace, key, property = defaultPath[1], defaultPath[2], defaultPath[3] | ||
local savedApplyType, value = Private.GetDefault(namespace, key, property, nil) | ||
|
||
local apply = false | ||
-- TODO template ? | ||
if action == "import" then | ||
apply = savedApplyType == 2 or savedApplyType == 3 | ||
elseif action == "new" then | ||
apply = savedApplyType == 1 or savedApplyType == 3 | ||
elseif action == "validate" then | ||
-- Nothing to do, validation can be done without user templates | ||
end | ||
|
||
if apply then | ||
local tablePath | ||
local property | ||
if type(settingsPath) == "table" then | ||
tablePath = CopyTable(settingsPath) | ||
tablePath[#tablePath] = nil | ||
property = settingsPath[#settingsPath] | ||
else | ||
tablePath ={} | ||
property = settingsPath | ||
end | ||
|
||
local settingsBase = GetOrCreateSubTable(data, unpack(tablePath)) | ||
if type(value) == "table" then | ||
settingsBase[property] = CopyTable(value) | ||
else | ||
settingsBase[property] = value | ||
end | ||
end | ||
end | ||
end | ||
|
||
local funcs = { | ||
ClearCache = function(self) | ||
wipe(self.defaults) | ||
end, | ||
GetDefault = function(self, action, key) | ||
if not self.mappings[key] then | ||
error("DefaultsCache:GetDefault called with a wrong key: " .. key, 1) | ||
return nil | ||
end | ||
|
||
if not action then | ||
error("DefaultsCache:GetDefault no action", 1) | ||
end | ||
|
||
if not self.defaults[action] or not self.defaults[action][key] then | ||
self.defaults[action] = self.defaults[action] or {} | ||
|
||
local mapping = self.mappings[key] | ||
local defaults = CopyTable(mapping.base) | ||
ApplyDefaults(defaults, action, mapping.map) | ||
|
||
self.defaults[action][key] = defaults | ||
end | ||
|
||
return self.defaults[action][key] | ||
end, | ||
AddDefault = function(self, key, mapping) | ||
if not mapping.base or not mapping.map then | ||
error("DefaultsCache: mapping has incorrect format, key: " .. key, 1) | ||
end | ||
self.mappings[key] = mapping | ||
end | ||
} | ||
|
||
local function CreateDefaultsCache(mappings) | ||
local cache = {} | ||
cache.mappings = {} | ||
cache.defaults = {} | ||
|
||
for k, func in pairs(funcs) do | ||
cache[k] = func | ||
end | ||
|
||
for key, mapping in pairs(mappings) do | ||
cache:AddDefault(key, mapping) | ||
end | ||
|
||
Private.callbacks:RegisterCallback("DefaultsChanged", function() cache:ClearCache() end) | ||
return cache | ||
end | ||
|
||
Private.CreateDefaultsCache = CreateDefaultsCache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.