Skip to content

Commit ac331b2

Browse files
committed
Add more type hints and corrections
1 parent aaad3bf commit ac331b2

14 files changed

Lines changed: 56 additions & 10 deletions

src/Classes/CalcsTab.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ local buffModeDropList = {
1717
}
1818

1919
---@class CalcsTab: UndoHandler, ControlHost, Control
20+
---@field powerStat PowerStat?
21+
---@field nodePowerMaxDepth integer? Maximum distance for power report
2022
local CalcsTabClass = newClass("CalcsTab", "UndoHandler", "ControlHost", "Control")
2123

2224
---@param build Build
@@ -163,7 +165,7 @@ function CalcsTabClass:Load(xml, dbFileName)
163165
if type(node) == "table" then
164166
if node.elem == "Input" then
165167
if not node.attrib.name then
166-
launch:ShowErrMsg("^1Error parsing '%s': 'Input' element missing name attribute", fileName)
168+
launch:ShowErrMsg("^1Error parsing '%s': 'Input' element missing name attribute", dbFileName)
167169
return true
168170
end
169171
if node.attrib.number then
@@ -173,12 +175,12 @@ function CalcsTabClass:Load(xml, dbFileName)
173175
elseif node.attrib.boolean then
174176
self.input[node.attrib.name] = node.attrib.boolean == "true"
175177
else
176-
launch:ShowErrMsg("^1Error parsing '%s': 'Input' element missing number, string or boolean attribute", fileName)
178+
launch:ShowErrMsg("^1Error parsing '%s': 'Input' element missing number, string or boolean attribute", dbFileName)
177179
return true
178180
end
179181
elseif node.elem == "Section" then
180182
if not node.attrib.id then
181-
launch:ShowErrMsg("^1Error parsing '%s': 'Section' element missing id attribute", fileName)
183+
launch:ShowErrMsg("^1Error parsing '%s': 'Section' element missing id attribute", dbFileName)
182184
return true
183185
end
184186
for _, section in ipairs(self.sectionList) do

src/Classes/DraggerControl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-- Class: Dragger Button Control
44
-- Dragger button control.
55
--
6-
---@type DraggerControl: Control, TooltipHost
6+
---@class DraggerControl: Control, TooltipHost
77
local DraggerClass = newClass("DraggerControl", "Control", "TooltipHost")
88

99
function DraggerClass:DraggerControl(anchor, rect, label, onKeyDown, onKeyUp, onRightClick, onHover, forceTooltip)

src/Classes/EditControl.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ local function newlineCount(str)
3737
end
3838

3939
---@class EditControl: ControlHost, Control, UndoHandler, TooltipHost
40+
---@field inactiveText (fun(buf: string?): string)|string
4041
local EditClass = newClass("EditControl", "ControlHost", "Control", "UndoHandler", "TooltipHost")
4142

4243
function EditClass:EditControl(anchor, rect, init, prompt, filter, limit, changeFunc, lineHeight, allowZoom, clearable)
@@ -301,7 +302,8 @@ function EditClass:Draw(viewPort, noTooltip)
301302
else
302303
SetDrawColor(self.inactiveCol)
303304
if self.inactiveText then
304-
local inactiveText = type(inactiveText) == "string" and self.inactiveText or self.inactiveText(self.buf)
305+
local inactiveText = type(self.inactiveText) == "string" and self.inactiveText or self.inactiveText(self.buf)
306+
---@cast inactiveText string
305307
DrawString(-self.controls.scrollBarH.offset, -self.controls.scrollBarV.offset, "LEFT", textHeight, self.font, inactiveText)
306308
elseif self.protected then
307309
DrawString(-self.controls.scrollBarH.offset, -self.controls.scrollBarV.offset, "LEFT", textHeight, self.font, string.rep(protected_replace, #self.buf))

src/Classes/PassiveTree.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,26 @@ local function getFile(URL)
4949
return #page > 0 and page
5050
end
5151

52+
---@class PassiveTreeGroup
53+
---@field x number
54+
---@field y number
55+
---@field orbits integer[]
56+
---@field nodes string[]
57+
---@field background any
58+
---@field isProxy boolean?
5259
---@class PassiveTree
60+
---@field classes any[] A list of classes on the tree
61+
---@field alternate_ascendancies any[]?
62+
---@field tree "Default"|"DefaultAltAscendancies"
63+
---@field groups PassiveTreeGroup[]
64+
---@field nodes table<"root"|integer, any>
65+
---@field jewelSlots integer[]
66+
---@field min_x integer
67+
---@field min_y integer
68+
---@field max_x integer
69+
---@field max_y integer
70+
---@field constants table<string, any>
71+
---@field points table<string, integer>
5372
local PassiveTreeClass = newClass("PassiveTree")
5473

5574
function PassiveTreeClass:PassiveTree(treeVersion)

src/Classes/PassiveTreeView.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ local band = bit.band
1515
local b_rshift = bit.rshift
1616

1717
---@class PassiveTreeView
18+
---@field compareSpec? PassiveSpec
1819
local PassiveTreeViewClass = newClass("PassiveTreeView")
1920

2021
function PassiveTreeViewClass:PassiveTreeView()
@@ -171,6 +172,7 @@ function PassiveTreeViewClass:GetCompareNodeColor(node, compareNode, spec, build
171172
return nodeDefaultColor
172173
end
173174

175+
---@param build Build
174176
function PassiveTreeViewClass:Draw(build, viewPort, inputEvents)
175177
local spec = build.spec
176178
local tree = spec.tree

src/Classes/UndoHandler.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ local t_insert = table.insert
1010
local t_remove = table.remove
1111

1212
---@class UndoHandler
13+
---@field CreateUndoState fun() Must be manually defined. Creates a state that can be restored
14+
---@field RestoreUndoState fun(state: any) Must be manually defined. Restores a state created by calling CreateUndoState()
1315
local UndoHandlerClass = newClass("UndoHandler")
1416

1517
function UndoHandlerClass:UndoHandler()
@@ -28,6 +30,7 @@ end
2830

2931
-- Adds a new undo state to the undo buffer, and also clears the redo buffer
3032
-- Should be called after the user makes a change to the current state
33+
---@param noClearRedo boolean?
3134
function UndoHandlerClass:AddUndoState(noClearRedo)
3235
t_insert(self.undo, 1, self:CreateUndoState())
3336
self.undo[102] = nil

src/Modules/Build.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local s_format = string.format
1616

1717
---@class Build: ControlHost
1818
---@field spec PassiveSpec added by TreeTab
19+
---@field powerBuilderCallback fun()
1920
local buildMode = new("ControlHost"):ControlHost()
2021

2122
local function InsertIfNew(t, val)

src/Modules/CalcDefence.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ end
5454
-- Based on code from FR and BS found in act_*.txt
5555
---@param activeSkill any /output/breakdown references table passed in from calc offence
5656
---@param sourceType string type of incoming damage - it will be converted (taken as) from this type if applicable
57-
---@param baseDmg for which to calculate the damage
57+
---@param baseDmg number for which to calculate the damage
5858
---@return table of taken damage parts, and number, sum of damages
5959
function calcs.applyDmgTakenConversion(activeSkill, output, breakdown, sourceType, baseDmg)
6060
local damageBreakdown = { }

src/Modules/CalcTools.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ end
244244
--- Correct the tags on conversion with multipliers so they carry over correctly
245245
--- @param mod table
246246
--- @param multiplier number
247-
--- @param minionMods bool @convert ActorConditions pointing at parent to normal Conditions
247+
--- @param minionMods boolean @convert ActorConditions pointing at parent to normal Conditions
248248
--- @return table @converted multipliers
249249
function calcLib.getConvertedModTags(mod, multiplier, minionMods)
250250
local modifiers = { }
@@ -284,7 +284,7 @@ end
284284

285285
--- Use getGameIdFromGemName to get gameId from the gemName and passed in type. Return true if they're the same and not nil
286286
--- @param gemName string
287-
--- @param type string
287+
--- @param typeName string
288288
--- @param dropVaal boolean
289289
--- @return boolean
290290
function calcLib.isGemIdSame(gemName, typeName, dropVaal)

src/Modules/Common.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,10 @@ function writeLuaTable(out, t, indent)
437437
end
438438

439439
-- Make a copy of a table and all subtables
440+
---@generic T
441+
---@param tbl T
442+
---@param noRecurse boolean?
443+
---@return T copy Note that this type can be misleading if noRecurse is set to true. Type hint explicitly if necessary.
440444
function copyTable(tbl, noRecurse)
441445
local out = {}
442446
for k, v in pairs(tbl) do

0 commit comments

Comments
 (0)