Module:ItemTables: Difference between revisions

setup default sorting
add alphabetical sort
Line 118: Line 118:
sortByWeapon["Armor"] = 10000
sortByWeapon["Armor"] = 10000
sortByWeapon["Tech"] = 100000000
sortByWeapon["Tech"] = 100000000
-- Sort the order of items in a preset as it appears when no filtered ordering is applied. Ordered first by slot and cost increasing, then alphabetical within same slot and cost.
function defaultSort()
    return function(a, b)
    if (get_cost(a["Name"]) == get_cost(b["Name"]) and sortByWeapon[a["Slot"]] == sortByWeapon[b["Slot"]]) then return a["Name"] < b["Name"] end
        return get_cost(a["Name"]) * sortByWeapon[a["Slot"]] < get_cost(b["Name"]) * sortByWeapon[b["Slot"]]
    end
end


-- Outputs a wikitable of items that increase a specified stat. Invoked by {{Item stat table}}
-- Outputs a wikitable of items that increase a specified stat. Invoked by {{Item stat table}}
Line 133: Line 141:
local filteredData = {}
local filteredData = {}
filteredData = get_similar_items_array(listofKeysTable)
filteredData = get_similar_items_array(listofKeysTable)
table.sort(filteredData, function(a,b) return get_cost(a["Name"]) * sortByWeapon[a["Slot"]] < get_cost(b["Name"]) * sortByWeapon[b["Slot"]] end)
table.sort(filteredData, defaultSort())
local createTable = mw.html.create('table')
local createTable = mw.html.create('table')