Skip to content

Commit ccc8c15

Browse files
committed
Fix module being a global variable and compare trade helpers into one file
1 parent 89eb71a commit ccc8c15

5 files changed

Lines changed: 58 additions & 94 deletions

File tree

src/Classes/CompareBuySimilar.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
local t_insert = table.insert
77
local m_floor = math.floor
88
local dkjson = require "dkjson"
9-
local tradeHelpers = LoadModule("Classes/CompareTradeHelpers")
10-
local tradeQueryHelpers = LoadModule("Classes/TradeQueryHelpers")
9+
local tradeHelpers = LoadModule("Classes/TradeHelpers")
1110

1211
local M = {}
1312

@@ -86,7 +85,7 @@ local function buildURL(item, slotName, controls, modEntries, defenceEntries, is
8685
end
8786
else
8887
-- Category filter
89-
local categoryStr, _ = tradeQueryHelpers.GetTradeCategory(slotName, item)
88+
local categoryStr, _ = tradeHelpers.getTradeCategory(slotName, item)
9089
if categoryStr then
9190
queryFilters.type_filters = {
9291
filters = {

src/Classes/CompareTab.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ local m_max = math.max
1010
local m_floor = math.floor
1111
local s_format = string.format
1212
local dkjson = require "dkjson"
13-
local tradeHelpers = LoadModule("Classes/CompareTradeHelpers")
13+
local tradeHelpers = LoadModule("Classes/TradeHelpers")
1414
local buySimilar = LoadModule("Classes/CompareBuySimilar")
1515
local calcsHelpers = LoadModule("Classes/CompareCalcsHelpers")
1616
local buildListHelpers = LoadModule("Modules/BuildListHelpers")
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,59 @@ function M.findTradeHash(item, modLine, modType, isDesecrated)
159159
end
160160
end
161161

162+
-- Map slot name + item type to (trade API category string, itemCategoryTags key).
163+
-- queryStr: e.g. "armour.shield", "weapon.onemace"
164+
-- categoryLabel: e.g. "Shield", "1HMace", "1HWeapon" (nil for flask / generic jewel / unsupported)
165+
--- @param slotName string
166+
--- @param item table
167+
function M.getTradeCategory(slotName, item)
168+
if not slotName then return nil, nil end
169+
local itemType = item and (item.type or (item.base and item.base.type))
170+
if slotName:find("^Weapon %d") then
171+
if not itemType then return "weapon.one", "1HWeapon" end
172+
if itemType == "Shield" then return "armour.shield", "Shield"
173+
elseif itemType == "Focus" then return "armour.focus", "Focus"
174+
elseif itemType == "Buckler" then return "armour.buckler", "Buckler"
175+
elseif itemType == "Quiver" then return "armour.quiver", "Quiver"
176+
elseif itemType == "Bow" then return "weapon.bow", "Bow"
177+
elseif itemType == "Crossbow" then return "weapon.crossbow", "Crossbow"
178+
elseif itemType == "Talisman" then return "weapon.talisman", "Talisman"
179+
elseif itemType == "Staff" and item.base.subType == "Warstaff" then return "weapon.warstaff", "Quarterstaff"
180+
elseif itemType == "Staff" then return "weapon.staff", "Staff"
181+
elseif itemType == "Two Hand Sword" then return "weapon.twosword", "2HSword"
182+
elseif itemType == "Two Hand Axe" then return "weapon.twoaxe", "2HAxe"
183+
elseif itemType == "Two Hand Mace" then return "weapon.twomace", "2HMace"
184+
elseif itemType == "Fishing Rod" then return "weapon.rod", "FishingRod"
185+
elseif itemType == "One Hand Sword" then return "weapon.onesword", "1HSword"
186+
elseif itemType == "Spear" then return "weapon.spear", "Spear"
187+
elseif itemType == "Flail" then return "weapon.flail", "weapon.flail"
188+
elseif itemType == "One Hand Axe" then return "weapon.oneaxe", "1HAxe"
189+
elseif itemType == "One Hand Mace" then return "weapon.onemace", "1HMace"
190+
elseif itemType == "Sceptre" then return "weapon.sceptre", "Sceptre"
191+
elseif itemType == "Wand" then return "weapon.wand", "Wand"
192+
elseif itemType == "Dagger" then return "weapon.dagger", "Dagger"
193+
elseif itemType == "Claw" then return "weapon.claw", "Claw"
194+
elseif itemType:find("Two Hand") then return "weapon.twomelee", "2HWeapon"
195+
elseif itemType:find("One Hand") then return "weapon.one", "1HWeapon"
196+
else
197+
return nil, nil
198+
end
199+
elseif slotName == "Body Armour" then return "armour.chest", "Chest"
200+
elseif slotName == "Helmet" then return "armour.helmet", "Helmet"
201+
elseif slotName == "Gloves" then return "armour.gloves", "Gloves"
202+
elseif slotName == "Boots" then return "armour.boots", "Boots"
203+
elseif slotName == "Amulet" then return "accessory.amulet", "Amulet"
204+
elseif slotName == "Ring 1" or slotName == "Ring 2" or slotName == "Ring 3" then return "accessory.ring", "Ring"
205+
elseif slotName == "Belt" then return "accessory.belt", "Belt"
206+
elseif slotName:find("Jewel") then return "jewel", "Jewel"
207+
elseif slotName:find("Flask 1") then return "flask.life", "Life Flask"
208+
elseif slotName:find("Flask 2") then return "flask.mana", "Mana Flask"
209+
-- these don't have a unique string so overlapping mods of the same benefit could interfere. , "Charm"
210+
elseif slotName:find("Charm") ~= nil then return "flask"
211+
else return nil, nil
212+
end
213+
end
214+
162215
-- Helper: get a display-friendly category name from slot name
163216
function M.getTradeCategoryLabel(slotName, item)
164217
if not item or not item.base then return "Item" end

src/Classes/TradeQueryGenerator.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local curl = require("lcurl.safe")
99
local m_max = math.max
1010
local s_format = string.format
1111
local t_insert = table.insert
12-
local tradeHelpers = LoadModule("Classes/TradeQueryHelpers")
12+
local tradeHelpers = LoadModule("Classes/TradeHelpers")
1313

1414
-- string are an any type while tables require all fields to be matched with type and subType require both to be matched exactly. [1] type, [2] subType, subType is optional and must be nil if not present.
1515
local tradeCategoryNames = {
@@ -690,7 +690,7 @@ function TradeQueryGeneratorClass:StartQuery(slot, options)
690690
}
691691
end
692692
else
693-
itemCategoryQueryStr, itemCategory = tradeHelpers.GetTradeCategory(slot.slotName, existingItem)
693+
itemCategoryQueryStr, itemCategory = tradeHelpers.getTradeCategory(slot.slotName, existingItem)
694694
if not itemCategory then
695695
logToFile("'%s' is not supported for weighted trade query generation", existingItem and existingItem.type or "n/a")
696696
return

src/Classes/TradeQueryHelpers.lua

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)