Module:Test
From The Walkscape Walkthrough
Documentation for this module may be created at Module:Test/doc
local p = {}
local utilities = require('Module:Utilities')
local materials = utilities.getPageJson('Data:Material')
local collectables = utilities.getPageJson('Data:Collectable')
local consumables = utilities.getPageJson('Data:Consumable')
local containers = utilities.getPageJson('Data:Container')
function p.getMaterialsTable()
local materialsTable = {}
table.insert(
materialsTable,
"{| class=\"wikitable sortable\"\n! colspan=\"2\" | Item || Value || Fine Value || Rarity || Keywords")
for _, material in pairs(materials) do
local keywords = {}
if material.keywords ~= nil then
for _, keyword in pairs(material.keywords) do
table.insert(keywords, "[[" .. keyword:gsub("^%l", string.upper) .. "]]")
end
end
table.insert(
materialsTable,
string.format(
"|-\n| [[File:%s|25px]] || [[%s]] || [[Image:Money icon.png|link=Coins]] %s || [[Image:Money icon.png|link=Coins]] %s || %s || %s",
utilities.getImageName(material.itemIcon),
utilities.getReadableName(material.name),
utilities.getFormattedValue({material.itemValue, material.itemValueMultiplier}),
utilities.getFormattedValue({material.itemValue, material.itemValueMultiplier}), -- figure out calculating fine materials value
utilities.getRarityImage(material.quality:gsub("^%l", string.upper)),
table.concat(keywords, ", ")))
end
table.insert(materialsTable, "|}")
return table.concat(materialsTable, "\n")
end
function p.getCollectablesTable()
local coltable = {}
table.insert(
coltable,
"{| class=\"wikitable sortable\"\n! colspan=\"2\" | Item || Value || Rarity || Requirements")
for _, col in pairs(collectables) do
local requirements = {}
if col.requirements ~= nil then
for _, keyword in pairs(col.requirements) do
table.insert(requirements, "[[" .. keyword:gsub("^%l", string.upper) .. "]]")
end
end
if next(requirements) == nil then
table.insert(requirements, "\'\'None\'\'")
end
table.insert(
coltable,
string.format(
"|-\n| [[File:%s|25px]] || [[%s]] || [[Image:Money icon.png|link=Coins]] %s || %s || %s",
utilities.getImageName(col.itemIcon),
utilities.getReadableName(col.name),
utilities.getFormattedValue({col.itemValue, col.itemValueMultiplier}),
utilities.getRarityImage(col.quality:gsub("^%l", string.upper)),
table.concat(requirements, ", ")))
end
table.insert(coltable, "|}")
return table.concat(coltable, "\n")
end
function p.getConsumablesTable()
local contable = {}
table.insert(
contable,
"{| class=\"wikitable sortable\"\n! colspan=\"2\" | Item || Value || Fine Value || Rarity")
for _, col in pairs(consumables) do
table.insert(
contable,
string.format(
"|-\n| [[File:%s|25px]] || [[%s]] || [[Image:Money icon.png|link=Coins]] %s || [[Image:Money icon.png|link=Coins]] %s || %s",
utilities.getImageName(col.itemIcon),
utilities.getReadableName(col.name),
utilities.getFormattedValue({col.itemValue, col.itemValueMultiplier}),
utilities.getFormattedValue({col.itemValue, col.itemValueMultiplier}), -- figure out how to get the fine value
utilities.getRarityImage(col.quality:gsub("^%l", string.upper))))
end
table.insert(contable, "|}")
return table.concat(contable, "\n")
end
function p.getContainersTable()
local contable = {}
table.insert(
contable,
"{| class=\"wikitable sortable\"\n! colspan=\"2\" | Item || Value || Rarity || Number of Item Roles")
for _, con in pairs(containers) do
local lootRoles = {}
local function processRoles()
for _, roles in pairs(con.tables) do
if next(roles) == nil then
table.insert(requirements, "\'\'None\'\'")
return -- Exit the function, which also exits the loop
end
local result = roles.tables[1]:gsub("loottable%-([%w_]+)_table%-.+", function(match)
-- Replace underscores with spaces and make the first letter of each word lowercase
local formatted = match:gsub("_", " "):gsub("(%a)([%w_]*)", function(first, rest)
return first:lower() .. rest:lower()
end)
-- Capitalize the first letter of the entire string
formatted = formatted:gsub("^%l", string.upper)
return "[[" .. formatted .. "]]"
end)
table.insert(lootRoles.rollAmount .. ": " .. result)
end
end
processRoles() -- Call the function
table.insert(
contable,
string.format(
"|-\n| [[File:%s|25px]] || [[%s]] || [[Image:Money icon.png|link=Coins]] %s || %s || %s",
utilities.getImageName(con.itemIcon),
utilities.getReadableName(con.name),
utilities.getFormattedValue({con.itemValue, con.itemValueMultiplier}),
utilities.getRarityImage(con.quality:gsub("^%l", string.upper)),
table.concat(lootRoles, ", ")))
end
table.insert(contable, "|}")
return table.concat(contable, "\n")
end
return p