Module:Sandbox/One Bar: Difference between revisionsGive feedback
Remove unneeded function for demonstration |
disabled items list |
||
| Line 2: | Line 2: | ||
local data = mw.loadJsonData("Data:ItemData.json") | local data = mw.loadJsonData("Data:ItemData.json") | ||
local function | local function get_disabled_items_array() | ||
local similarItems = {} | |||
local hash = {} | |||
local noDuplicates = {} | |||
for _, v in pairs(data) do | for _, v in pairs(data) do | ||
if (v["Name"] = | if (v["IsDisabled"] == true and v["Name"] ~= nil) then | ||
table.insert(similarItems, v) | |||
end | end | ||
end | end | ||
return | |||
-- remove duplicate items if that item contains multiple keys of the same stat increase (eg. Fleetfoot has both "BonusMoveSpeed", "ActiveBonusMoveSpeed" in move speed). | |||
-- there might be a more efficient way to prevent adding duplicate items in the first place in the above for loop | |||
for _, v in pairs(similarItems) do | |||
if (not hash[v]) then | |||
noDuplicates[#noDuplicates+1] = v | |||
hash[v] = true | |||
end | |||
end | |||
return noDuplicates | |||
end | end | ||
local | p.disabledItemsTable = function(frame) | ||
local | local requirements = {} | ||
local listofItems = "" | |||
local filteredData = {} | |||
filteredData = get_disabled_items_array() | |||
local createTable = mw.html.create('table') | |||
:addClass('wikitable sortable') | |||
:tag('caption'):wikitext("List of items"):done() | |||
local createTableHeader = mw.html.create('tr') | |||
createTableHeader | |||
:tag('th'):wikitext('Name'):done() | |||
:tag('th'):wikitext('Category'):done() | |||
:tag('th'):wikitext('Description'):done() | |||
createTable:node(createTableHeader) | |||
-- query all the filtered items. itemName is the item table. | |||
for internalName, itemName in ipairs(filteredData) do | |||
local display = frame:expandTemplate{ | |||
title = 'ItemIcon', | |||
args = { | |||
itemName["Name"] | |||
} | |||
} | |||
listofItems = listofItems .. itemName["Name"] .. "<br/>" | |||
-- Get category display using ItemType template with appropriate parameters | |||
local categoryDisplay | |||
if itemName["Slot"] == "Armor" then | |||
categoryDisplay = frame:expandTemplate{ | |||
title = 'ItemType', | |||
args = { "Armor", "Vitality" } | |||
} | |||
elseif itemName["Slot"] == "Tech" then | |||
categoryDisplay = frame:expandTemplate{ | |||
title = 'ItemType', | |||
args = { "Tech", "Spirit" } | |||
} | |||
else -- Weapon | |||
categoryDisplay = frame:expandTemplate{ | |||
title = 'ItemType', | |||
args = { "Weapon", "Weapon" } | |||
} | |||
end | |||
local description = frame:expandTemplate{ | |||
title = 'ItemDescription', | |||
args = { | |||
itemName["Description"] | |||
} | |||
} | |||
local tableData = mw.html.create('tr') | |||
tableData | |||
:tag('td'):wikitext(display):done() | |||
:tag('td'):wikitext(categoryDisplay):done() | |||
:tag('td'):wikitext(description):done() | |||
table.insert(requirements, tableData) | |||
end | |||
for _, row in ipairs(requirements) do | |||
createTable:node(row) | |||
end | |||
return | return tostring(createTable) | ||
end | end | ||
return p | return p | ||