From Dark and Darker Wiki
Documentation for this module may be created at Module:GenerateClassGearTables/doc
local p = {}
local WD = mw.loadJsonData("Data:Weapon.json")
local AD = mw.loadJsonData("Data:Armor.json")
local concat = table.concat
local function get_list_from_label(wt, label, class, table_type)
local handtype, slottype
if label == "Main Hand + Two Handed" then
handtype = "Two Handed"
slottype = "Main-Hand"
elseif label == "Main Hand + One Handed" then
handtype = "One Handed"
slottype = "Main-Hand"
elseif label == "Off Hand" then
handtype = "One Handed"
slottype = "Off-Hand"
end
for _, weapon_name in ipairs(WD.Weapon.order) do
weapon = WD.Weapon[weapon_name]
-- Check if weapon is for the given class, weapons that don't specify a class are for all classes so by default we have "found" the class until we see otherwise
local found_class = true
if weapon.classes then
for _, c in ipairs(weapon.classes) do
found_class = false
if string.match(c, class) then
found_class = true
break
end
end
end
-- Weapon is for this class, check if handtype and slottype match and if the table_type matches (Uncraftable, Craftable, etc.)
if weapon.handtype == handtype and weapon.slottype == slottype then
local first_weapon_type = weapon.types.order[1]
local type_list
if WD[first_weapon_type] and WD[first_weapon_type][table_type] then
type_list = WD[first_weapon_type][table_type]
local found_type = false
for _, t in ipairs(type_list) do
if t == weapon.name then
found_type = true
break
end
end
if found_class and found_type then
wt[#wt+1] = string.format("[[%s]]", weapon.name)
wt[#wt+1] = " • "
end
end
end
end
table.remove(wt) -- remove the   from the last element
end
function p.gear_table(frame)
local class = frame.args[1]
local table_type = frame.args[2]
local column_labels = {"Main Hand + Two Handed", "Main Hand + One Handed", "Off Hand", "Utility"}
local wt = {}
wt[#wt+1] = '<table class="wikitable sortable jquery-tablesorter" cellspacing="0" style="width:60%; color:#eee; background:transparent; text-align:center; vertical-align:middle;">'
wt[#wt+1] = [[<tr>
<th style="font-weight:bold; background-color: rgb(220,220,220,0.2); width:15%" class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Hand/Slot Type</th>
<th style="font-weight:bold; background-color: rgb(220,220,220,0.2); width:50%" class="headerSort" tabindex="0" role="columnheader button" title="Sort ascending">Weapons</th>
</tr>]]
for _, label in ipairs(column_labels) do
wt[#wt+1] = '<tr style="height:100px">'
wt[#wt+1] = string.format('<td style="font-weight:bold; background-color: rgb(220,220,220,0.2); text-align:middle">%s</td>', label)
wt[#wt+1] = "<td>"
get_list_from_label(wt, label, class, table_type)
wt[#wt+1] = "</td>"
wt[#wt+1] = "</tr>"
end
wt[#wt+1] = "</table>"
return concat(wt)
end
return p
-- mw.log(p.gear_table({args={"Rogue", "Uncraftable"}}))
-- mw.log(p.gear_table({args={"Rogue", "Craftable"}}))
-- mw.log(p.gear_table({args={"Rogue", "Artifact"}}))