Module:Equipment
Jump to navigation
Jump to search
This is the main module for the following templates:
local p = {}
local h = {}
local File = require("Module:File")
local Franchise = require("Module:Franchise")
local term = require("Module:Term")
local utilsArg = require("Module:UtilsArg")
local utilsCargo = require("Module:UtilsCargo")
function h.err(errMsg, warnMsg)
local utilsError = require("Module:UtilsError")
return utilsError.error(errMsg, warnMsg)
end
function p.Main(frame)
local args, err = utilsArg.parse(frame:getParent().args, p.Templates["Equipment"])
if err then
return "", err.categoryText
end
-- For now, there are different Cargo tables per game, e.g. one for BotW, one for TotK
local tableName = args.game .. "ItemProperties"
local equipmentTypeQuery = utilsCargo.query(tableName, "type", {
where = "_pageName = '" .. utilsCargo.escape(args.equipment) .. "'",
})
local plural = false
if #equipmentTypeQuery == 0 then
if not string.find(args.equipment, "Arrow") then
return h.err("The specified equipment is not in " .. tableName .. ".")
end
-- Arrows are a special case, are classified as Bow even if
-- they are not in the Cargo table, and have a pluralized link
plural = true
equipmentTypeQuery = { { type = "Bow" } }
end
local equipmentType = equipmentTypeQuery[1].type
-- Every Material or Zonai Device is pluralized for this template
if equipmentType == "Material" or equipmentType == "Zonai Device" then
plural = true
end
local icon = File.gameImage(args.game, equipmentType, "Icon", { size = "x18px" })
local equipmentLink = term.printTerm(
args.equipment, args.game, {
plural = plural,
link = true
}
)
local html = mw.html.create("small")
:wikitext(icon .. " " .. equipmentLink)
return tostring(html)
end
p.Templates = {
["Equipment"] = {
description = "Displays a piece of equipment alongside its type icon.",
purpose = "Displays a piece of equipment alongside its type icon.",
params = {
[1] = {
name = "game",
required = true,
enum = Franchise.enum(),
type = "string",
desc = "A game code.",
trim = true,
nilIfEmpty= true,
},
[2] = {
name = "equipment",
required = true,
type = "string",
desc = "The equipment's name.",
tim = true,
nilIfEmpty = true,
},
},
examples = {
{
desc = "Blue Boko Reaper",
args = {"TotK", "Blue Boko Reaper"},
},
{
desc = "Master Sword",
args = {"BotW", "Master Sword"}
},
},
},
}
return p