Module:ItemsByStat: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 12: Line 12:
local i = 1
local i = 1
for m,itemData in pairs(AllItemData) do
for m,itemData in pairs(AllItemData) do
for itemFieldName,n in pairs(itemData) do
if itemData[stat] ~= nil then -- If Item has given stat in its keys,
if itemFieldName == stat then -- If Item has given stat in its keys,
for x = 1,#inKeys do
for x = 1,#inKeys do
outData[x][i] = itemData[inKeys[x]] -- grab stat and other values
outData[x][i] = itemData[inKeys[x]] -- grab stat and other values
end
i = i+1
break
end
end
i = i+1
break
end
end
end
end

Revision as of 16:45, 27 September 2024

Documentation for this module may be created at Module:ItemsByStat/doc

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

local selectByStat = function(stat)
	-- List properties to grab and set up data structure to hold values
	local inKeys = {"Name","Tier","Cost","Slot",stat}
	local outData = {}
	for x=1,#inKeys do
		outData[x] = {}
	end
	
	local i = 1
	for m,itemData in pairs(AllItemData) do
		if itemData[stat] ~= nil then -- If Item has given stat in its keys,
			for x = 1,#inKeys do
				outData[x][i] = itemData[inKeys[x]] -- grab stat and other values
			end
			i = i+1
			break
		end
	end
	return outData
end

p.tablefy = function(frame)
	local stat = frame.args[1]
	local tableData = selectByStat(stat)
	local outString = '{| class="wikitable sortable"\n|-\n!Item!!Tier!!Cost!!Slot!!Value\n|-\n'
	for i=1,#tableData[1] do
		outString = outString.."|-\n|[["..tableData[1][i].."]]||"..tableData[2][i].."||"..tableData[3][i].."||"..tableData[4][i].."||"..tableData[5][i].."\n"
	end
	return outString.."|}"
end

return p