Skip to content

Commit 0425303

Browse files
Cidanclaude
andauthored
feat(sorting): add Expansion sort option for items (#890)
Add a new "Expansion" sort option to the Item Order dropdown, allowing users to sort items chronologically by the expansion they were introduced in (Classic -> TBC -> ... -> Midnight). Changes: - core/constants.lua:273: Add EXPANSION = 4 to ITEM_SORT_TYPE enum - config/config.lua:220-228: Add "Expansion" option to Item Order dropdown for both Backpack and Bank, mapping to const.ITEM_SORT_TYPE.EXPANSION - util/sort.lua:220-242: Implement SortItemsByExpansion function that: * Uses data.itemInfo.expacID for expansion ordering * Defaults to 0 (Classic) for items with missing expacID * Falls back to alphabetical sort when expansions are equal * Falls back to item count and GUID for stable sorting - util/sort.lua:61-76: Update GetItemSortFunction to return SortItemsByExpansion when EXPANSION sort type is selected The expansion ID is already populated by the WoW API via C_Item.GetItemInfo() and stored in itemInfo.expacID. Lower expansion IDs represent older content (0 = Classic, 11 = Midnight), providing chronological ordering. All luacheck validation passes with no warnings or errors. Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 06b076d commit 0425303

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

config/config.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,12 @@ function config:CreateConfig()
221221
["Alphabetically"] = const.ITEM_SORT_TYPE.ALPHABETICALLY_THEN_QUALITY,
222222
["Quality"] = const.ITEM_SORT_TYPE.QUALITY_THEN_ALPHABETICALLY,
223223
["Item Level"] = const.ITEM_SORT_TYPE.ITEM_LEVEL,
224+
["Expansion"] = const.ITEM_SORT_TYPE.EXPANSION,
224225
}
225226
f:AddDropdown({
226227
title = 'Item Order',
227228
description = 'The default order of items within each section.',
228-
items = {'Alphabetically', 'Quality', 'Item Level'},
229+
items = {'Alphabetically', 'Quality', 'Item Level', 'Expansion'},
229230
getValue = function(_, value)
230231
return itemOrders[value] == db:GetItemSortType(bagType.kind, db:GetBagView(bagType.kind))
231232
end,

core/constants.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ const.ITEM_SORT_TYPE = {
270270
ALPHABETICALLY_THEN_QUALITY = 1,
271271
QUALITY_THEN_ALPHABETICALLY = 2,
272272
ITEM_LEVEL = 3,
273+
EXPANSION = 4,
273274
}
274275

275276
---@enum ExpansionType

util/sort.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ function sort:GetItemSortFunction(kind, view)
6969
return self.SortItemsByQualityThenAlpha
7070
elseif sortType == const.ITEM_SORT_TYPE.ITEM_LEVEL then
7171
return self.SortItemsByItemLevel
72+
elseif sortType == const.ITEM_SORT_TYPE.EXPANSION then
73+
return self.SortItemsByExpansion
7274
end
7375
assert(false, "Unknown sort type: " .. sortType)
7476
return function() end
@@ -210,6 +212,32 @@ end
210212
---@param a Item
211213
---@param b Item
212214
---@return boolean
215+
function sort.SortItemsByExpansion(a, b)
216+
if a.isFreeSlot then return false end
217+
if b.isFreeSlot then return true end
218+
local aData, bData = a:GetItemData(), b:GetItemData()
219+
if invalidData(aData, bData) then return false end
220+
221+
-- Get expansion IDs, defaulting to 0 (Classic) if missing
222+
local aExpacID = aData.itemInfo.expacID or 0
223+
local bExpacID = bData.itemInfo.expacID or 0
224+
225+
-- Sort by expansion (chronological order)
226+
if aExpacID ~= bExpacID then
227+
return aExpacID < bExpacID
228+
-- If same expansion, fall back to alphabetical
229+
elseif aData.itemInfo.itemName ~= bData.itemInfo.itemName then
230+
return aData.itemInfo.itemName < bData.itemInfo.itemName
231+
-- If same name, fall back to item count
232+
elseif aData.itemInfo.currentItemCount ~= bData.itemInfo.currentItemCount then
233+
return aData.itemInfo.currentItemCount > bData.itemInfo.currentItemCount
234+
end
235+
-- Finally, fall back to GUID for stable sort
236+
return aData.itemInfo.itemGUID < bData.itemInfo.itemGUID
237+
end
238+
---@param a Item
239+
---@param b Item
240+
---@return boolean
213241
function sort.GetItemSortBySlot(a, b)
214242
local aData, bData = a:GetItemData(), b:GetItemData()
215243
if not aData then return false end

0 commit comments

Comments
 (0)