Module:Equipment: Difference between revisions
Jump to navigation
Jump to search
Rayolinels (talk | contribs) mNo edit summary |
Rayolinels (talk | contribs) (The module/template will now pluralize Materials and Zonai Devices.) |
||
Line 4: | Line 4: | ||
local File = require("Module:File") | local File = require("Module:File") | ||
local Franchise = require("Module:Franchise") | local Franchise = require("Module:Franchise") | ||
local term = require("Module:Term") | |||
local utilsArg = require("Module:UtilsArg") | local utilsArg = require("Module:UtilsArg") | ||
local utilsCargo = require("Module:UtilsCargo") | local utilsCargo = require("Module:UtilsCargo") | ||
function h.err(errMsg, warnMsg) | function h.err(errMsg, warnMsg) | ||
Line 19: | Line 19: | ||
end | 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", { | local equipmentTypeQuery = utilsCargo.query(tableName, "type", { | ||
Line 26: | Line 26: | ||
}) | }) | ||
local | local plural = false | ||
if #equipmentTypeQuery == 0 then | if #equipmentTypeQuery == 0 then | ||
if not string.find(args.equipment, "Arrow") then | if not string.find(args.equipment, "Arrow") then | ||
return h.err(" | return h.err("The specified equipment is not in " .. tableName .. ".") | ||
end | end | ||
-- Arrows are a special case, are classified as Bow even if | -- Arrows are a special case, are classified as Bow even if | ||
-- they are not in the Cargo table and have a pluralized link | -- they are not in the Cargo table, and have a pluralized link | ||
plural = true | |||
equipmentTypeQuery = { { type = "Bow" } } | equipmentTypeQuery = { { type = "Bow" } } | ||
end | end | ||
local equipmentType = equipmentTypeQuery[1].type | local equipmentType = equipmentTypeQuery[1].type | ||
local icon = File.gameImage(args.game, equipmentType, "Icon", { | |||
-- 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) | return tostring(html) | ||
end | end |
Revision as of 20:37, 5 May 2023
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