Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Ketho committed Aug 30, 2024
1 parent 2f822f0 commit 067865c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Broker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ local function MilitaryTime(v)
local sec = floor(v) % 60
local minute = floor(v/60) % 60
local hour = floor(v/3600)

if v >= 3600 then
return format("%02.f:%02.f:%02.f", hour, minute, sec)
else
Expand Down
76 changes: 38 additions & 38 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,58 @@ local profile, char

function KIT:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("KethoInstanceTimerDB", S.defaults, true)

self.db.RegisterCallback(self, "OnProfileChanged", "RefreshDB")
self.db.RegisterCallback(self, "OnProfileCopied", "RefreshDB")
self.db.RegisterCallback(self, "OnProfileReset", "RefreshDB")
self:RefreshDB()

self.db.global.version = S.VERSION
self.db.global.build = S.BUILD

options.args.libsink = self:GetSinkAce3OptionsDataTable()
options.args.libsink.order = 2

options.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
options.args.profiles.order = 4
options.args.profiles.name = "|TInterface\\Icons\\INV_Misc_Note_01:16:16:-2:-1"..S.crop.."|t "..options.args.profiles.name

ACR:RegisterOptionsTable(NAME, S.options)
ACD:AddToBlizOptions(NAME, NAME)
ACD:SetDefaultSize(NAME, 550, 430)

---------------------
--- Dungeon Names ---
---------------------

if S.isRetail then
-- grab the localized names from the dungeon finder
for i = 1, GetNumRFDungeons() do
local id, name = GetRFDungeonInfo(i)
S.DungeonName[id] = name
end

for k, v in pairs(S.SpecialDungeon) do
S.DungeonName[k] = GetLFGDungeonInfo(k)
end
end

S.RemapDungeon()

----------------------
--- Slash Commands ---
----------------------

for _, v in ipairs({"kit", "kethoinstance", "kethoinstancetimer"}) do
self:RegisterChatCommand(v, "SlashCommand")
end

-----------------------------
--- Custom SavedVariables ---
-----------------------------

char.TimeInstanceList = char.TimeInstanceList or {}

-- time data should be preserved between every /reload
char.timeInstance = char.timeInstance or 0
char.startDate = char.startDate or ""
Expand All @@ -77,17 +77,17 @@ function KIT:OnEnable()
for _, v in ipairs(S.isRetail and S.Events or S.ClassicEvents) do
self:RegisterEvent(v)
end

-- support [Class Colors] by Phanx
if CUSTOM_CLASS_COLORS then
CUSTOM_CLASS_COLORS:RegisterCallback("WipeCache", self)
end

-- player is not in a group (anymore) -> reset timer
if not IsInGroup() then
self:ResetTime(true)
end

-- initialize stopwatch while in an instance
if S.IsStopwatch() then
S.instance = select(2, IsInInstance())
Expand All @@ -97,11 +97,11 @@ end

function KIT:OnDisable()
self:UnregisterAllEvents()

if CUSTOM_CLASS_COLORS then
CUSTOM_CLASS_COLORS:UnregisterCallback("WipeCache", self)
end

if S.IsStopwatch() then
S.StopwatchEnd()
end
Expand All @@ -110,9 +110,9 @@ end
function KIT:RefreshDB()
profile = self.db.profile
char = self.db.char

self:SetSinkStorage(profile) -- LibSink

-- update table references in other files
for i = 1, 2 do
self["RefreshDB"..i](self)
Expand Down Expand Up @@ -153,18 +153,18 @@ end

function KIT:PLAYER_ENTERING_WORLD(event)
S.instance = select(2, IsInInstance())

local prevInstance = S.mapinstance
S.mapinstance = select(8, GetInstanceInfo())

if S.pve[S.instance] and not S.IsGarrison() then
-- zoned from an instance to a different instance
local changedInstances = prevInstance and prevInstance ~= S.mapinstance
-- entered instance
if char.timeInstance == 0 or changedInstances then
self:StartData()
end

if S.IsStopwatch() then
S.StopwatchStart()
end
Expand All @@ -174,7 +174,7 @@ function KIT:PLAYER_ENTERING_WORLD(event)
elseif (S.instance == "none" or S.IsGarrison()) and not IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
-- left instance
self:ResetTime(true)

if profile.Stopwatch then
S.StopwatchEnd()
end
Expand All @@ -187,33 +187,33 @@ end

function KIT:COMBAT_LOG_EVENT_UNFILTERED(event)
local timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = CombatLogGetCurrentEventInfo()

if subevent ~= "UNIT_DIED" then return end

local unitType, _, _, _, _, npcId = strsplit("-", destGUID)
npcId = tonumber(npcId)

local hasBossID = S.isRetail and S.BossIDs[npcId] or S.ClassicBossIDs[npcId]
-- dont report raid finder in normal/heroic/mythic raids
-- note that we still want to report in dungeons like maraudon and seasonal
local name = not S.IsNormalRaid() and S.DungeonIDs[npcId] or hasBossID

if S.npc[unitType] and name and char.timeInstance > 0 then

-- boss fights with multiple npcs
if S.Multiple[npcId] and not S.CheckMultiple(npcId) then return end

-- if its raid finder/seasonal, get specific name, otherwise fall back to zone
local name = (type(name) == "string") and name

-- Record
self:Record(name)

-- Report
if profile[S.instance] then
self:Pour(self:InstanceText(nil, name))
end

self:Finalize()
end
end
Expand All @@ -229,7 +229,7 @@ function KIT:CHAT_MSG_SYSTEM(event, msg)
-- left or kicked from group; or reset through ResetInstances()
if msg == ERR_LEFT_GROUP_YOU or msg == ERR_UNINVITE_YOU or strfind(msg, INSTANCE_RESET_SUCCESS) then
self:ResetTime(true)

if profile.Stopwatch then
S.StopwatchEnd()
end
Expand All @@ -244,7 +244,7 @@ function KIT:LFG_PROPOSAL_SUCCEEDED(event)
C_Timer.After(20, function()
if char.timeInstance == 0 then
self:StartData()

if S.IsStopwatch() then
S.StopwatchStart()
end
Expand All @@ -261,11 +261,11 @@ function KIT:SecondaryCompletion()
C_Timer.After(1, function()
if char.timeInstance > 0 then
self:Record()

if profile[S.instance] then
self:Pour(self:InstanceText())
end

self:Finalize()
end
end)
Expand Down
Loading

0 comments on commit 067865c

Please sign in to comment.