Module:Sandbox/One Bar: Difference between revisions

From The Deadlock Wiki
Jump to navigation Jump to search
One Bar (talk | contribs)
Add variable name
One Bar (talk | contribs)
keep variable as key
Line 3: Line 3:


local function get_disabled_items_array()
local function get_disabled_items_array()
local similarItems = {}
local disabledItems = {}
local hash = {}
for k, v in pairs(data) do
local noDuplicates = {}
for _, v in pairs(data) do
if (v["IsDisabled"] == true and v["Name"] ~= nil) then
if (v["IsDisabled"] == true and v["Name"] ~= nil) then
table.insert(similarItems, v)
disabledItems[k] = v
end
end
end
end
return disabledItems
-- 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



Revision as of 19:23, 10 May 2025

Documentation for this module may be created at Module:Sandbox/One Bar/doc

local p = {};
local data = mw.loadJsonData("Data:ItemData.json")

local function get_disabled_items_array()
	local disabledItems = {}
	for k, v in pairs(data) do
		if (v["IsDisabled"] == true and v["Name"] ~= nil) then
			disabledItems[k] = v
		end
	end
	return disabledItems
end

p.disabledItemsTable = function(frame)
	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('Variable'):done()
		: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 = itemName["Name"]
		
		listofItems = listofItems .. itemName["Name"] .. "<br/>"
		
		
		local categoryDisplay = itemName["Slot"]
		
		local description = itemName["Description"]
		
		local tableData = mw.html.create('tr')
		tableData
			:tag('td'):wikitext(internalName):done()
			: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 tostring(createTable)
end

return p