Editing Module:ItemsByStatGive feedback
Jump to navigation
Jump to search
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local AllItemData = mw.loadJsonData("Data:ItemData.json") | local AllItemData = mw.loadJsonData("Data:ItemData.json") | ||
-- I truly have no better idea of how to sort by cost within slot, so I'm gonna multiply the costs of slots I want lower in the table | -- I truly have no better idea of how to sort by cost within slot, so I'm gonna multiply the costs of slots I want lower in the table | ||
| Line 17: | Line 7: | ||
multBySlot["Armor"] = 10000 | multBySlot["Armor"] = 10000 | ||
multBySlot["Tech"] = 100000000 | multBySlot["Tech"] = 100000000 | ||
local selectByStat = function(stat) | local selectByStat = function(stat) | ||
-- List properties to grab | -- List properties to grab and set up data structure to hold values | ||
local inKeys = {"Name","Tier","Cost","Slot",stat,"Components"} | local inKeys = {"Name","Tier","Cost","Slot",stat,"Components"} | ||
local outData = {} | local outData = {} | ||
local i = 1 | local i = 1 | ||
for | for m,itemData in pairs(AllItemData) do | ||
if itemData[stat] ~= nil and itemData[stat] ~= "0" then -- If Item has | if itemData[stat] ~= nil and itemData[stat] ~= "0" then -- If Item has given stat in its keys, | ||
outData[i] = {} | outData[i] = {} | ||
for x = 1,#inKeys do | for x = 1,#inKeys do | ||
outData[i][x] = itemData[inKeys[x]] -- grab stat and other values | outData[i][x] = itemData[inKeys[x]] -- grab stat and other values | ||
end | end | ||
i = i+1 | i = i+1 | ||
end | end | ||
| Line 44: | Line 25: | ||
-- Sort by cost within slot | -- Sort by cost within slot | ||
table.sort(outData, function(a,b) return a[ | table.sort(outData, function(a,b) return a[3]*multBySlot[a[4]]<b[3]*multBySlot[b[4]] end) | ||
return outData | return outData | ||
end | end | ||
local colorBySlot = {} | |||
colorBySlot["Weapon"] = "#FCAC4D" | |||
colorBySlot["Armor"] = "#86C921" | |||
colorBySlot["Tech"] = "#DE9CFF" | |||
p.tablefy = function(frame) | p.tablefy = function(frame) | ||
local stat = frame.args[1] | local stat = frame.args[1] | ||
local tableData = selectByStat(stat) | local tableData = selectByStat(stat) | ||
local outString = '{| class="wikitable sortable"\n|-\n!Item!!Cost!! | local outString = '{| class="wikitable sortable"\n|-\n!Item!!Cost!!Value\n' | ||
for i=1,#tableData do | for i=1,#tableData do | ||
outString = outString.. | outString = outString.. | ||
'|-style="background:'..colorBySlot[tableData[i][4]]..'"\n|'.. | '|-style="background:'..colorBySlot[tableData[i][4]]..'"\n|'.. | ||
frame:expandTemplate{title="Item", args={tableData[i][1]}}.."||".. | frame:expandTemplate{title="Item", args={tableData[i][1]}}.."||".. | ||
frame:expandTemplate{title="Souls", args={tableData[i][3]}}.."||".. | frame:expandTemplate{title="Souls", args={tableData[i][3]}}.."||".. | ||
tableData[i][5].."\n" | |||
end | end | ||
return outString.."|}" | return outString.."|}" | ||