Skip to content

Commit

Permalink
Merge branch 'feature/annotations'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharparam committed Sep 6, 2024
2 parents 679ba97 + db27f42 commit 994cbc0
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 101 deletions.
3 changes: 0 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
"WOW_PROJECT_ID",
"WOW_PROJECT_MAINLINE"
],
"Lua.workspace.library": [
"~/.vscode/extensions/ketho.wow-api-0.17.4/Annotations"
],
"Lua.runtime.builtin": {
"basic": "disable",
"debug": "disable",
Expand Down
18 changes: 12 additions & 6 deletions Broker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@
* along with KillTrack. If not, see <http://www.gnu.org/licenses/>.
--]]

local _, KT = ...
---@class KillTrack
local KT = select(2, ...)

KT.Broker = {
---@class KillTrackBroker
local KTB = {
Text = {
Short = "KPM: %.2f",
Long = "Kills Per Minute: %.2f"
}
}

KT.Broker = KTB
local KTT = KT.Tools
local KTB = KT.Broker

local UPDATE = 1
local t = 0
Expand Down Expand Up @@ -62,9 +64,10 @@ local clickFunctions = {
}
}

local obj = ldb:NewDataObject("Broker_KillTrack", data)
local obj = ldb:NewDataObject("Broker_KillTrack", data) --[[@as LibDataBroker.DataDisplay]]

function obj:OnTooltipShow()
---@param self GameTooltip
function obj.OnTooltipShow(self)
self:AddLine(("%s |cff00FF00(%s)|r"):format(KT.Name, KT.Version), 1, 1, 1)
self:AddLine(" ")
local _, kpm, kph, length = KT:GetSessionStats()
Expand Down Expand Up @@ -110,7 +113,7 @@ function obj:OnClick(button)
end

function obj:OnEnter()
GameTooltip:SetOwner(self, "ANCHOR_NONE")
GameTooltip:SetOwner(self --[[@as Frame]], "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", self, "BOTTOMLEFT")
KTB:UpdateTooltip()
tooltipVisible = true
Expand All @@ -132,6 +135,8 @@ function KTB:UpdateTooltip()
GameTooltip:Show()
end

---@param _ Frame
---@param elapsed number
function KTB:OnUpdate(_, elapsed)
t = t + elapsed
if t >= UPDATE then
Expand All @@ -155,6 +160,7 @@ function KTB:OnLoad()
self:UpdateText()
end

---@param enabled boolean
function KTB:SetMinimap(enabled)
KT.Global.BROKER.MINIMAP.hide = not enabled
if enabled then
Expand Down
28 changes: 20 additions & 8 deletions Command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@
* along with KillTrack. If not, see <http://www.gnu.org/licenses/>.
--]]

local _, KT = ...
---@class KillTrack
local KT = select(2, ...)

KT.Command = {
---@class KillTrackCommand
local C = {
Slash = {
"killtrack",
"kt"
},
---@type { [string]: fun(args: string[]) }
Commands = {}
}

local C = KT.Command
KT.Command = C
local KTT = KT.Tools

-- Argument #1 (command) can be either string or a table.
---@param command string|string[]
---@param func fun(args: string[])
function C:Register(command, func)
if type(command) == "string" then
command = {command}
Expand All @@ -43,18 +48,24 @@ function C:Register(command, func)
end
end

---@param command string
---@return boolean
function C:HasCommand(command)
for k,_ in pairs(self.Commands) do
if k == command then return true end
end
return false
end

---@param command string
---@return fun(args: string[])
function C:GetCommand(command)
local cmd = self.Commands[command]
if cmd then return cmd else return self.Commands["__DEFAULT__"] end
end

---@param command string
---@param args string[]
function C:HandleCommand(command, args)
local cmd = self:GetCommand(command)
if cmd then
Expand Down Expand Up @@ -112,10 +123,10 @@ C:Register({"printnew", "pn"}, function()
end)

C:Register({"set", "edit"}, function(args)
local id = tonumber(args[1])
local id = tonumber(args[1]) --[[@as integer]]
local name = args[2]
local global = tonumber(args[3])
local char = tonumber(args[4])
local global = tonumber(args[3]) --[[@as integer]]
local char = tonumber(args[4]) --[[@as integer]]

local err

Expand Down Expand Up @@ -166,8 +177,9 @@ C:Register({"delete", "del", "remove", "rem"}, function(args)
end)

C:Register({"purge"}, function(args)
---@type integer?
local threshold
if #args >= 1 then threshold = tonumber(args[1]) end
if #args >= 1 then threshold = tonumber(args[1]) --[[@as integer]] end
KT:ShowPurge(threshold)
end)

Expand Down Expand Up @@ -218,7 +230,7 @@ C:Register({"immediate", "imm", "i"}, function(args)
if #args < 1 then
KT.Immediate:Show()
elseif args[1]:match("^t") then
local threshold = tonumber(args[2])
local threshold = tonumber(args[2]) --[[@as integer]]
if #args < 2 then
KT:Msg("Usage: immediate threshold <threshold>")
KT:Msg("E.g: /kt immediate threshold 50")
Expand Down
10 changes: 7 additions & 3 deletions Dialogs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* along with KillTrack. If not, see <http://www.gnu.org/licenses/>.
--]]

local _, KT = ...
---@class KillTrack
local KT = select(2, ...)

StaticPopupDialogs.KILLTRACK_FINISH = {
text = "%s entries removed.",
Expand Down Expand Up @@ -47,7 +48,7 @@ StaticPopupDialogs.KILLTRACK_PURGE = {
button2 = "Cancel",
hasEditBox = true,
OnAccept = function(self)
KT:Purge(tonumber(self.editBox:GetText())) KT.MobList:UpdateMobs() KT.MobList:UpdateEntries()
KT:Purge(tonumber(self.editBox:GetText()) --[[@as integer]]) KT.MobList:UpdateMobs() KT.MobList:UpdateEntries()
end,
OnCancel = function() KT.Temp.Threshold = nil end,
OnShow = function(self)
Expand Down Expand Up @@ -83,14 +84,17 @@ StaticPopupDialogs.KILLTRACK_RESET = {
hideOnEscape = true
}

---@param id integer|string
---@param name string
function KT:ShowDelete(id, name)
id = tonumber(id)
id = tonumber(id) --[[@as integer]]
name = tostring(name)
if not id then error("'id' must be a number.") end
self.Temp.DeleteId = id
StaticPopup_Show("KILLTRACK_DELETE", name, id)
end

---@param threshold integer?
function KT:ShowPurge(threshold)
if tonumber(threshold) then
self.Temp.Threshold = tonumber(threshold)
Expand Down
10 changes: 7 additions & 3 deletions ExpTracker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
* along with KillTrack. If not, see <http://www.gnu.org/licenses/>.
--]]

local _, KT = ...
---@class KillTrack
local KT = select(2, ...)

KT.ExpTracker = {
---@class KillTrackExpTracker
local ET = {
---@type string[]
Strings = {
---@diagnostic disable: undefined-field
_G.COMBATLOG_XPGAIN_EXHAUSTION1, -- %s dies, you gain %d experience. (%s exp %s bonus)
Expand All @@ -41,7 +44,7 @@ KT.ExpTracker = {
}
}

local ET = KT.ExpTracker
KT.ExpTracker = ET

local initialized = false

Expand All @@ -52,6 +55,7 @@ local function Initialize()
initialized = true
end

---@param message string
function ET:CheckMessage(message)
if not initialized then Initialize() end
local name, exp
Expand Down
12 changes: 7 additions & 5 deletions ImmediateFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
* along with KillTrack. If not, see <http://www.gnu.org/licenses/>.
--]]

local _, KT = ...
---@class KillTrack
local KT = select(2, ...)

KT.Immediate = {
---@class KillTrackImmediateFrame
local I = {
Active = false,
Kills = 0
}

local I = KT.Immediate
KT.Immediate = I

local frame

Expand Down Expand Up @@ -98,15 +100,15 @@ end
function I:Show()
if not frame then SetupFrame() end
self.Kills = 0
frame.killCount:SetText(self.Kills)
frame.killCount:SetText(tostring(self.Kills))
frame:Show()
self.Active = true
end

function I:Hide()
frame:Hide()
self.Kills = 0
frame.killCount:SetText(self.Kills)
frame.killCount:SetText(tostring(self.Kills))
self.Active = false
end

Expand Down
Loading

0 comments on commit 994cbc0

Please sign in to comment.