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") | ||
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 = {} | |||
for x=1,#inKeys do | |||
outData[x] = {} | |||
end | |||
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, | ||
for x = 1,#inKeys do | for x = 1,#inKeys do | ||
outData[ | outData[x][i] = itemData[inKeys[x]] -- grab stat and other values | ||
end | end | ||
i = i+1 | i = i+1 | ||
end | end | ||
end | end | ||
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!!Tier!!Cost!!Slot!!Value\n' | ||
for i=1,#tableData do | local display = frame:ExpandTemplate{title='ItemIcon',args = {tableData[1][i]}} | ||
outString = outString.. | for i=1,#tableData[1] do | ||
outString = outString..'|-style="background:'..colorBySlot[tableData[4][i]]..'"\n|'..display.."||"..tableData[2][i].."||"..tableData[3][i].."||"..tableData[5][i].."\n" | |||
end | end | ||
return outString.."|}" | return outString.."|}" | ||