Module:Sandbox/One Bar: Difference between revisions

From The Deadlock Wiki
Jump to navigation Jump to search
One Bar (talk | contribs)
Remove unneeded function for demonstration
One Bar (talk | contribs)
disabled items list
Line 2: Line 2:
local data = mw.loadJsonData("Data:ItemData.json")
local data = mw.loadJsonData("Data:ItemData.json")


local function get_json_item(name)
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"] == name) then
if (v["IsDisabled"] == true and v["Name"] ~= nil) then
return v
table.insert(similarItems, v)
end
end
end
end
return nil
-- 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 function get_cost(item_name)
p.disabledItemsTable = function(frame)
local item = get_json_item(item_name)
local requirements = {}
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end
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 item["Cost"]
return tostring(createTable)
end
 
p.get_cost = function(frame)
local item_name = frame.args[1]
return get_cost(item_name)
end
 
-- Module access point
function p._get_cost(a)
a = tostring(a) or '0'
return get_cost(a)
end
end


return p
return p

Revision as of 19:05, 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 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 = 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 tostring(createTable)
end

return p