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

Release 0.22.2 #114

Merged
merged 1 commit into from
Jun 13, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.22.2

- fix encounter EP

# 0.22.1

- fix bug :)
Expand Down
2 changes: 1 addition & 1 deletion CalamityEPGP/CalamityEPGP.toc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Title: CalamityEPGP
## Notes: EPGP addon for Cataclysm Classic
## Author: Kardiir-Atiesh
## Version: 0.22.1
## Version: 0.22.2
## Interface: 40400
## SavedVariables: CalamityEPGP
## DefaultState: enabled
Expand Down
86 changes: 76 additions & 10 deletions CalamityEPGP/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local Config = {
defaultDecayGp = 10,
syncAltEp = false,
syncAltGp = true,
rollDuration = 25,
rollDuration = 17,
closeOnAward = true,
gpBase = ns.values.gpDefaults.base,
gpSlotMods = ns.values.gpDefaults.slotModifiers,
Expand All @@ -39,6 +39,79 @@ Config.aceConfig = LibStub("AceConfig-3.0")
Config.aceConfigDialog = LibStub("AceConfigDialog-3.0")


function Config.cfgTableIndex(table, key)
local dbTable
local defaultsTable
if table._path == '.' then
dbTable = ns.db.cfg
defaultsTable = Config.defaults
else
dbTable = ns.Lib.findTableValue(ns.db.cfg, table._path)
defaultsTable = ns.Lib.findTableValue(Config.defaults, table._path)
end

if dbTable ~= nil then
local dbValue = dbTable[key]
if dbValue ~= nil then
return dbValue
end
end

if defaultsTable ~= nil then
local defaultValue = defaultsTable[key]
if defaultValue ~= nil then
return defaultValue
end
end

return nil
end

function Config.cfgTableNewIndex(table, key, value)
local dbTable = ns.db.cfg
if table._path ~= '.' then
for _, key in ipairs(ns.Lib.split(table._path, '.')) do
if dbTable[key] == nil then
dbTable[key] = {}
end

dbTable = dbTable[key]
end
end

dbTable[key] = value
end


function Config:setupCfg(cfgTable, defaultsTable, path)
path = path or '.'

cfgTable._path = path

setmetatable(cfgTable, {
__index = self.cfgTableIndex,
__newindex = self.cfgTableNewIndex,
})

for key, val in pairs(defaultsTable) do
if type(val) == 'table' then
if rawget(cfgTable, key) == nil then
rawset(cfgTable, key, {})
end

local newPath
if path == '.' then
newPath = key
else
newPath = path .. '.' .. key
end

self:setupCfg(cfgTable[key], val, newPath)
end
end
end


function Config:init()
if self.initialized then
return
Expand Down Expand Up @@ -162,13 +235,6 @@ function Config:init()
}
}

-- add defaults to ns.cfg if it's not already poulated
for optName, default in pairs(self.defaults) do
if ns.cfg[optName] == nil then
ns.cfg[optName] = default
end
end

-- create options menus
self:addOptionsMenu(addonName, menus.root)
self:initAltManagementMenu()
Expand Down Expand Up @@ -993,7 +1059,7 @@ function Config:getDefaultDecayEp(_)
end

function Config:setDefaultDecayEp(_, input)
ns.cfg.defaultDecayEp = input
ns.cfg.defaultDecayEp = tonumber(input)
ns.addon.modifiedLmSettings()
end

Expand All @@ -1002,7 +1068,7 @@ function Config:getDefaultDecayGp(_)
end

function Config:setDefaultDecayGp(_, input)
ns.cfg.defaultDecayGp = input
ns.cfg.defaultDecayGp = tonumber(input)
ns.addon.modifiedLmSettings()
end

Expand Down
31 changes: 31 additions & 0 deletions CalamityEPGP/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ function Lib.remove(container, value, all)
end


---@param str string
---@param sep string?
---@return table
function Lib.split(str, sep)
if sep == nil then
sep = "%s"
Expand Down Expand Up @@ -888,3 +891,31 @@ end
function Lib.getEventAndHashId(eventAndHash)
return ('%s:%s'):format(eventAndHash[1][1], eventAndHash[2])
end


---@param t table
---@param path string
function Lib.findTableValue(t, path)
local pathParts = Lib.split(path, '.')

if #pathParts == 1 then
return t[path]
end

for _, key in ipairs(pathParts) do
local newPathParts = {}
for i = 2, #pathParts do
tinsert(newPathParts, pathParts[i])
end

local newTable = t[key]

if newTable == nil then
return nil
end

local newPath = table.concat(newPathParts, '.')

return Lib.findTableValue(newTable, newPath)
end
end
26 changes: 15 additions & 11 deletions CalamityEPGP/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ end
function addon:handleGuildRosterUpdate()
C_Timer.After(0.1, function()
self:init()

-- if self.initialized then
-- self:computeStandings()
-- end
end)
end

Expand Down Expand Up @@ -235,7 +231,6 @@ function addon:init()
db:SetProfile(guildFullName)

ns.db = db.profile
ns.cfg = ns.db.cfg

ns.db.realmId = GetRealmID()
ns.db.knownPlayers = {}
Expand All @@ -255,6 +250,9 @@ function addon:init()
self.libc = LibStub('LibCompress')
self.libcEncodeTable = self.libc:GetAddonEncodeTable()

ns.cfg = {}
ns.Config:setupCfg(ns.cfg, ns.Config.defaults)

self.migrateData()

local newHistory = {}
Expand Down Expand Up @@ -395,10 +393,17 @@ function addon.migrateData()
end

-- GP SLOT MODIFIERS
if not ns.db.slotModifiersVersion then
ns.debug('migrating slot modifiers to v1')
if ns.db.slotModifiersVersion ~= nil then
ns.debug('removing slotModifiersVersion')
ns.db.slotModifiersVersion = nil
end

-- DB CONFIG
if not ns.db.cfgVersion then
ns.debug('migrating cfg to v1')
ns.db.cfg.gpSlotMods = nil
ns.db.slotModifiersVersion = 1
ns.db.cfg.encounterEp = nil
ns.db.cfgVersion = 1
end

ns.debug('done migrating data')
Expand Down Expand Up @@ -1075,7 +1080,7 @@ function addon:initMinimapButton()
end,
})

self.ldbi:Register(addonName, minimapButton, ns.db.cfg.minimap)
self.ldbi:Register(addonName, minimapButton, ns.cfg.minimap)

self.minimapButtonInitialized = true
end
Expand Down Expand Up @@ -1399,8 +1404,7 @@ end
---@param _ any
---@param success number
function addon:handleEncounterEnd(_, encounterId, encounterName, _, _, success)
if not self.useForRaid or
success ~= 1 then
if not self.useForRaid or success ~= 1 then
return
end

Expand Down
Loading