Module:ItemsByStat: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
local p = {}
local p = {}
local data = mw.loadJsonData("Data:ItemData.json")
local AllItemData = mw.loadJsonData("Data:ItemData.json")


local selectByStat = function(stat)
local selectByStat = function(stat)
local Item,Value = {},{}
local Name,Tier,Value = {},{},{}
local outData = {Name,Tier,Value}
local inKeys = {"Name","Tier",stat}
local i = 1
local i = 1
 
for m,v in pairs(data) do
for m,itemData in pairs(AllItemData) do
for n,w in pairs(v) do
for itemFieldName,n in pairs(itemData) do
if n == stat then  
if itemFieldName == stat then  
Item[i] = v["Name"]
for x = 1,#inKeys do
Value[i] = v[stat]
outData[x][i] = itemData[inKeys[x]]
i = i+1
i = i+1
break
break
end
end
end
end
end
end
end
local b = {Item, Value}
return outData
return b
end
end


Line 24: Line 26:
local tabledata = selectByStat(stat)
local tabledata = selectByStat(stat)
Item = tabledata[1]
Item = tabledata[1]
Value = tabledata[2]
Value = tabledata[3]
output = ""
output = ""
for i=1,#Item do
for i=1,#Item do

Revision as of 14:23, 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)
	local Name,Tier,Value = {},{},{}
	local outData = {Name,Tier,Value}
	local inKeys = {"Name","Tier",stat}
	local i = 1
	
	for m,itemData in pairs(AllItemData) do
		for itemFieldName,n in pairs(itemData) do
			if itemFieldName == stat then 
				for x = 1,#inKeys do
					outData[x][i] = itemData[inKeys[x]]
					i = i+1
					break
				end
			end
		end
	end
	return outData
end

p.tablefy = function(frame)
	local stat = frame.args[1]
	local tabledata = selectByStat(stat)
	Item = tabledata[1]
	Value = tabledata[3]
	output = ""
	for i=1,#Item do
		output = output.."Name: [["..Item[i].."]]	Increased Weapon Damage: "..Value[i].."\n\n"
	end
	return output
end

return p