Module:ItemsByStat: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(44 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local AllItemData = mw.loadJsonData("Data:ItemData.json")
local AllItemData = mw.loadJsonData("Data:ItemData.json")
local Lang = require("Module:Lang")
-- Grab items from item data (has "upgrade" in item key and is not marked as disabled)
InGameItemData = {}
for ItemKey, ItemData in pairs(AllItemData) do
if string.find(ItemKey, "upgrade") ~= nil and ItemData["Disabled"] == false then
table.insert(InGameItemData, ItemData)
end
end
-- I truly have no better idea of how to sort by cost within slot, so I'm gonna multiply the costs of slots I want lower in the table
local multBySlot = {}
multBySlot["Weapon"] = 1
multBySlot["Armor"] = 10000
multBySlot["Tech"] = 100000000
-- For coloring the table by slot
local colorBySlot = {}
colorBySlot["Weapon"] = "#FCAC4D"
colorBySlot["Armor"] = "#86C921"
colorBySlot["Tech"] = "#DE9CFF"


local selectByStat = function(stat)
local selectByStat = function(stat)
local Name,Tier,Value = {},{},{}
-- List properties to grab, extend as necessary
local outData = {Name,Tier,Value}
-- Probably not wise to move or remove elements because there's some hard-coded indexing later
local inKeys = {"Name","Tier",stat};
local inKeys = {"Name","Tier","Cost","Slot",stat,"Components"}
local outData = {}
local i = 1
local i = 1
for itemKey,itemData in pairs(InGameItemData) do
for m,itemData in pairs(AllItemData) do
if itemData[stat] ~= nil and itemData[stat] ~= "0" then -- If Item has non-zero stat in its keys,
for itemFieldName,n in pairs(itemData) do
outData[i] = {} -- start a new record of data and
if itemFieldName == stat then
for x = 1,#inKeys do
for x = 1,3 do
outData[i][x] = itemData[inKeys[x]] -- grab stat and other values
outData[x][i] = itemData[inKeys[x]]
i = i+1;
end
break
end
end
outData[i]['itemKey'] = itemKey -- Throw item key in there for good measure
outData[i]['multCost'] = itemData['Cost'] * multBySlot[itemData['Slot']]
i = i+1
end
end
end
end
return outData
-- Sort by cost within slot
table.sort(outData, function(a,b) return a['multCost']<b['multCost'] end)
return outData -- outData is a table of tables, one for each Item that has the specified stat, where each inner table has the data specified with inKeys, in order
end
end


--{{#invoke:ItemsByStat|tablefy|stat|statName|suffix}}
--stat: Name of statistic to look for in ItemData.json. Must match the actual key, e.g. TechPower for Spirit Power
--statName: Column header in final table. TechPower isn't the name for the stat in-game, so change it here
--suffix: String to append to numeric value to indicate units. As of now only % and m/s are used in-game and in fact this is left blank for most stats
p.tablefy = function(frame)
p.tablefy = function(frame)
local stat = frame.args[1]
local stat = frame.args[1]
local statName = frame.args[2]
local suffix = frame.args[3]
local tableData = selectByStat(stat)
local tableData = selectByStat(stat)
local outString = ""
local outString = '{| class="wikitable sortable"\n|-\n!Item!!Cost!!'..statName..'\n'
return tableData[2][1]
for i=1,#tableData do -- Very ugly wikitable code
-- for i=1,#Item do
outString = outString..
-- outString = outString.."Name: [["..Item[i].."]] Increased Weapon Damage: "..Value[i].."\n\n"
'|-style="background:'..colorBySlot[tableData[i][4]]..'"\n|'..
-- end
frame:expandTemplate{title="Item", args={tableData[i][1]}}.."||"..
-- return outString
-- frame:expandTemplate{title="Item", args={tableData[i][1],Lang.get_string(tableData[i]['itemKey'])}}.."||"..
frame:expandTemplate{title="Souls", args={tableData[i][3]}}.."||"..
'style="text-align:center;"|+'..tableData[i][5]..suffix.."\n"
end
return outString.."|}"
end
end


return p
return p

Latest revision as of 05:52, 11 October 2024

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

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

-- Grab items from item data (has "upgrade" in item key and is not marked as disabled)
InGameItemData = {}

for ItemKey, ItemData in pairs(AllItemData) do
	if string.find(ItemKey, "upgrade") ~= nil and ItemData["Disabled"] == false then
		table.insert(InGameItemData, ItemData)
	end
end

-- I truly have no better idea of how to sort by cost within slot, so I'm gonna multiply the costs of slots I want lower in the table
local multBySlot = {}
multBySlot["Weapon"] = 1
multBySlot["Armor"] = 10000
multBySlot["Tech"] = 100000000

-- For coloring the table by slot
local colorBySlot = {}
colorBySlot["Weapon"] = "#FCAC4D"
colorBySlot["Armor"] = "#86C921"
colorBySlot["Tech"] = "#DE9CFF"

local selectByStat = function(stat)
	-- List properties to grab, extend as necessary
	-- Probably not wise to move or remove elements because there's some hard-coded indexing later
	local inKeys = {"Name","Tier","Cost","Slot",stat,"Components"}
	
	local outData = {}
	local i = 1
	for itemKey,itemData in pairs(InGameItemData) do
		if itemData[stat] ~= nil and itemData[stat] ~= "0" then -- If Item has non-zero stat in its keys,
			outData[i] = {}							-- start a new record of data and
			for x = 1,#inKeys do
				outData[i][x] = itemData[inKeys[x]] -- grab stat and other values
			end
			outData[i]['itemKey'] = itemKey -- Throw item key in there for good measure
			outData[i]['multCost'] = itemData['Cost'] * multBySlot[itemData['Slot']]
			i = i+1
		end
	end
	
	-- Sort by cost within slot
	table.sort(outData, function(a,b) return a['multCost']<b['multCost'] end)
	return outData -- outData is a table of tables, one for each Item that has the specified stat, where each inner table has the data specified with inKeys, in order
end

--{{#invoke:ItemsByStat|tablefy|stat|statName|suffix}}
--stat: Name of statistic to look for in ItemData.json. Must match the actual key, e.g. TechPower for Spirit Power
--statName: Column header in final table. TechPower isn't the name for the stat in-game, so change it here
--suffix: String to append to numeric value to indicate units. As of now only % and m/s are used in-game and in fact this is left blank for most stats
p.tablefy = function(frame)
	local stat = frame.args[1]
	local statName = frame.args[2]
	local suffix = frame.args[3]
	
	local tableData = selectByStat(stat)
	local outString = '{| class="wikitable sortable"\n|-\n!Item!!Cost!!'..statName..'\n'
	for i=1,#tableData do -- Very ugly wikitable code
		outString = outString..
			'|-style="background:'..colorBySlot[tableData[i][4]]..'"\n|'..
			frame:expandTemplate{title="Item", args={tableData[i][1]}}.."||"..
		--	frame:expandTemplate{title="Item", args={tableData[i][1],Lang.get_string(tableData[i]['itemKey'])}}.."||"..
			frame:expandTemplate{title="Souls", args={tableData[i][3]}}.."||"..
			'style="text-align:center;"|+'..tableData[i][5]..suffix.."\n"
	end
	return outString.."|}"
end

return p