Module:ItemsByStat: Difference between revisions

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


local colorBySlot = {}
local colorBySlot = {}
colorBySlot["Weapon"] = "#A36202"
colorBySlot["Weapon"] = "#FCAC4D"
colorBySlot["Vitality"] = "#507A11"
colorBySlot["Armor"] = "#86C921"
colorBySlot["Spirit"] = "#704491"
colorBySlot["Tech"] = "#DE9CFF"


p.tablefy = function(frame)
p.tablefy = function(frame)
Line 32: Line 32:
local outString = '{| class="wikitable sortable"\n|-\n!Item!!Tier!!Cost!!Slot!!Value\n'
local outString = '{| class="wikitable sortable"\n|-\n!Item!!Tier!!Cost!!Slot!!Value\n'
for i=1,#tableData[1] do
for i=1,#tableData[1] do
outString = outString..'|-style="background: #A36202;"\n|{{ItemIcon|'..tableData[1][i].."}}||"..tableData[2][i].."||"..tableData[3][i].."||"..tableData[4][i].."||"..tableData[5][i].."\n"
outString = outString..'|-style="background: '..colorBySlot[tableData[4][i]]..'"\n|{{ItemIcon|'..tableData[1][i].."}}||"..tableData[2][i].."||"..tableData[3][i].."||"..tableData[5][i].."\n"
end
end
return outString.."|}"
return outString.."|}"

Revision as of 17:29, 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,"Components"}
	local outData = {}
	for x=1,#inKeys do
		outData[x] = {}
	end
	
	local i = 1
	for m,itemData in pairs(AllItemData) do
		if itemData[stat] ~= nil and itemData[stat] ~= "0" 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
		end
	end
	return outData
end

local colorBySlot = {}
colorBySlot["Weapon"] = "#FCAC4D"
colorBySlot["Armor"] = "#86C921"
colorBySlot["Tech"] = "#DE9CFF"

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'
	for i=1,#tableData[1] do
		outString = outString..'|-style="background: '..colorBySlot[tableData[4][i]]..'"\n|{{ItemIcon|'..tableData[1][i].."}}||"..tableData[2][i].."||"..tableData[3][i].."||"..tableData[5][i].."\n"
	end
	return outString.."|}"
end

return p