Module:ItemsByStat: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 3: Line 3:


local selectByStat = function(stat)
local selectByStat = function(stat)
-- List properties to grab and set up data structure to hold values
local inKeys = {"Name","Tier","Cost","Slot",stat}
local inKeys = {"Name","Tier","Cost","Slot",stat}
local outData = {}
local outData = {}
Line 8: Line 9:
outData[x] = {}
outData[x] = {}
end
end
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
for itemFieldName,n in pairs(itemData) do
if itemFieldName == stat then  
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]]
outData[x][i] = itemData[inKeys[x]] -- grab stat and other values
end
end
i = i+1
i = i+1
Line 27: Line 28:
local stat = frame.args[1]
local stat = frame.args[1]
local tableData = selectByStat(stat)
local tableData = selectByStat(stat)
local outString = ""
local outString = '{| class="wikitable sortable"|-!Item!!Tier!!Cost!!Slot!!Value|-'
for i=1,#tableData[1] do
for i=1,#tableData[1] do
outString = outString..tableData[1][i]..tableData[2][i]..tableData[3][i]..tableData[4][i]..tableData[5][i].."\n\n"
outString = outString.."|"..tableData[1][i].."||"..tableData[2][i].."||"..tableData[3][i].."||"..tableData[4][i].."||"..tableData[5][i]
end
end
return outString
return outString.."|}"
end
end


return p
return p

Revision as of 14:56, 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
		for itemFieldName,n in pairs(itemData) do
			if itemFieldName == stat 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
	end
	return outData
end

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

return p