Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default options #2948

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions WeakAuras/DefaultOptions.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
--[[ Manual override for the default font and font size until proper options are built ]]
if not WeakAuras.IsLibsOK() 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

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


WeakAuras.defaultFont = "Friz Quadrata TT"
WeakAuras.defaultFontSize = 12
2 changes: 1 addition & 1 deletion WeakAuras/Init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ if not WeakAuras.IsLibsOK() then
end

-- These function stubs are defined here to reduce the number of errors that occur if WeakAuras.lua fails to compile
--- @type fun(regionType: string, createFunction: function, modifyFunction: function, defaults: table, properties: table|function|nil, validate: function?))
--- @type fun(regionType: string, createFunction: function, modifyFunction: function, defaults: function, properties: table|function|nil, validate: function?))
function WeakAuras.RegisterRegionType(_, _, _ ,_)
end

Expand Down
25 changes: 21 additions & 4 deletions WeakAuras/RegionTypes/AuraBar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local SharedMedia = LibStub("LibSharedMedia-3.0");
local L = WeakAuras.L;

-- Default settings
local default = {
local baseDefault = {
icon = false,
desaturate = false,
iconSource = -1,
Expand Down Expand Up @@ -42,8 +42,9 @@ local default = {
zoom = 0
};

WeakAuras.regionPrototype.AddAdjustedDurationToDefault(default);
WeakAuras.regionPrototype.AddAlphaToDefault(default);
WeakAuras.regionPrototype.AddAdjustedDurationToDefault(baseDefault);
WeakAuras.regionPrototype.AddAlphaToDefault(baseDefault);


local screenWidth, screenHeight = math.ceil(GetScreenWidth() / 20) * 20, math.ceil(GetScreenHeight() / 20) * 20;

Expand Down Expand Up @@ -152,7 +153,23 @@ local properties = {
},
};

WeakAuras.regionPrototype.AddProperties(properties, default);
WeakAuras.regionPrototype.AddProperties(properties, baseDefault);

local mappings = {
normal = {
base = baseDefault,
map = {
[{'region', 'aurabar', 'icon'}] = "icon",
[{'region', 'aurabar', 'texture'}] = "texture",
}
}
}

local defaultsCache = Private.CreateDefaultsCache(mappings)

local function default(action)
return defaultsCache:GetDefault(action, "normal")
end

local function GetProperties(data)
local overlayInfo = Private.GetOverlayInfo(data);
Expand Down
114 changes: 114 additions & 0 deletions WeakAuras/RegionTypes/DefaultsCache.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
if not WeakAuras.IsLibsOK() 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, mappingName)
if not self.mappings[mappingName] then
error("DefaultsCache:GetDefault called with a wrong key: " .. mappingName, 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][mappingName] then
self.defaults[action] = self.defaults[action] or {}

local mapping = self.mappings[mappingName]
local defaults = CopyTable(mapping.base)
ApplyDefaults(defaults, action, mapping.map)

self.defaults[action][mappingName] = defaults
end

return self.defaults[action][mappingName]
end,
AddDefault = function(self, mappingName, mapping)
if not mapping.base or not mapping.map then
error("DefaultsCache: mapping has incorrect format, key: " .. mappingName, 1)
end
self.mappings[mappingName] = mapping
end
}

local function CreateDefaultsCache(mappings)
local cache = {}
cache.mappings = {}
cache.defaults = {}

for k, func in pairs(funcs) do
cache[k] = func
end

for mappingName, mapping in pairs(mappings) do
cache:AddDefault(mappingName, mapping)
end

Private.callbacks:RegisterCallback("DefaultsChanged", function() cache:ClearCache() end)
return cache
end

Private.CreateDefaultsCache = CreateDefaultsCache
6 changes: 5 additions & 1 deletion WeakAuras/RegionTypes/DynamicGroup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local WeakAuras = WeakAuras
local L = WeakAuras.L
local SharedMedia = LibStub("LibSharedMedia-3.0")

local default = {
local baseDefault = {
controlledChildren = {},
border = false,
borderColor = {0, 0, 0, 1},
Expand Down Expand Up @@ -43,6 +43,10 @@ local default = {
columnSpace = 1
}

local function default()
return baseDefault
end

local controlPointFunctions = {
["SetAnchorPoint"] = function(self, point, relativeFrame, relativePoint, offsetX, offsetY)
self:ClearAllPoints();
Expand Down
8 changes: 6 additions & 2 deletions WeakAuras/RegionTypes/Group.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local AddonName, Private = ...
local SharedMedia = LibStub("LibSharedMedia-3.0");

-- Default settings
local default = {
local baseDefault = {
controlledChildren = {},
anchorPoint = "CENTER",
anchorFrameType = "SCREEN",
Expand All @@ -21,7 +21,11 @@ local default = {
borderSize = 2,
borderBackdrop = "Blizzard Tooltip",
scale = 1,
};
}

local function default()
return baseDefault
end

-- Called when first creating a new region/display
local function create(parent)
Expand Down
23 changes: 20 additions & 3 deletions WeakAuras/RegionTypes/Icon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ end
-- WoW API
local _G = _G

local default = {
local baseDefault = {
icon = true,
desaturate = false,
iconSource = -1,
Expand All @@ -34,7 +34,7 @@ local default = {
useCooldownModRate = true
};

WeakAuras.regionPrototype.AddAlphaToDefault(default);
WeakAuras.regionPrototype.AddAlphaToDefault(baseDefault);

local screenWidth, screenHeight = math.ceil(GetScreenWidth() / 20) * 20, math.ceil(GetScreenHeight() / 20) * 20;

Expand Down Expand Up @@ -110,7 +110,24 @@ local properties = {
}
};

WeakAuras.regionPrototype.AddProperties(properties, default);
WeakAuras.regionPrototype.AddProperties(properties, baseDefault);

local mappings = {
normal = {
base = baseDefault,
map = {
[{'region', 'icon', 'zoom'}] = "zoom",
[{'region', 'icon', 'cooldown'}] = "cooldown",
[{'region', 'icon', 'cooldownTextDisabled'}] = "cooldownTextDisabled",
}
},
}

local defaultsCache = Private.CreateDefaultsCache(mappings)

local function default(action)
return defaultsCache:GetDefault(action, "normal")
end

local function GetProperties(data)
local result = CopyTable(properties)
Expand Down
8 changes: 6 additions & 2 deletions WeakAuras/RegionTypes/Model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local SharedMedia = LibStub("LibSharedMedia-3.0");
local L = WeakAuras.L;

-- Default settings
local default = {
local baseDefault = {
model_path = "spells/arcanepower_state_chest.m2", -- arthas is not a thing on classic
model_fileId = "122968", -- Creature/Arthaslichking/arthaslichking.m2
modelIsUnit = false,
Expand Down Expand Up @@ -67,7 +67,11 @@ local properties = {
},
}

WeakAuras.regionPrototype.AddProperties(properties, default);
WeakAuras.regionPrototype.AddProperties(properties, baseDefault);

local function default()
return baseDefault
end

local function GetProperties(data)
return properties;
Expand Down
17 changes: 8 additions & 9 deletions WeakAuras/RegionTypes/ProgressTexture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ local AddonName, Private = ...

local L = WeakAuras.L;

local defaultFont = WeakAuras.defaultFont
local defaultFontSize = WeakAuras.defaultFontSize

-- Credit to CommanderSirow for taking the time to properly craft the TransformPoint function
-- to the enhance the abilities of Progress Textures.
-- Also Credit to Semlar for explaining how circular progress can be shown
Expand All @@ -22,7 +19,7 @@ local defaultFontSize = WeakAuras.defaultFontSize
-- region.scale (1.0) - user defined scaling [1, INF]
-- region.full_rotation (false) - Allow full rotation [bool]

local default = {
local baseDefault = {
foregroundTexture = "Interface\\Addons\\WeakAuras\\PowerAurasMedia\\Auras\\Aura3",
backgroundTexture = "Interface\\Addons\\WeakAuras\\PowerAurasMedia\\Auras\\Aura3",
desaturateBackground = false,
Expand Down Expand Up @@ -51,16 +48,14 @@ local default = {
anchorFrameType = "SCREEN",
xOffset = 0,
yOffset = 0,
font = defaultFont,
fontSize = defaultFontSize,
mirror = false,
frameStrata = 1,
slantMode = "INSIDE"
};

WeakAuras.regionPrototype.AddAlphaToDefault(default);
WeakAuras.regionPrototype.AddAlphaToDefault(baseDefault);

WeakAuras.regionPrototype.AddAdjustedDurationToDefault(default);
WeakAuras.regionPrototype.AddAdjustedDurationToDefault(baseDefault);

local screenWidth, screenHeight = math.ceil(GetScreenWidth() / 20) * 20, math.ceil(GetScreenHeight() / 20) * 20;

Expand Down Expand Up @@ -139,7 +134,11 @@ local properties = {
}
}

WeakAuras.regionPrototype.AddProperties(properties, default);
WeakAuras.regionPrototype.AddProperties(properties, baseDefault);

local function default()
return baseDefault
end

local function GetProperties(data)
local overlayInfo = Private.GetOverlayInfo(data);
Expand Down
Loading