Module:Sandbox/One Bar

From The Deadlock Wiki
Revision as of 19:09, 10 May 2025 by One Bar (talk | contribs) (remove flare)
Jump to navigation Jump to search

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

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('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(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