Module:Vehicles
Jump to navigation
Jump to search
Module:Vehicles
Retrieves a vehicle's data from Module:Vehicles/data and renders it using Template:VehicleInfobox.
Usage
Render infobox for current vehicle page
On a vehicle page, where the page title matches a vehicle key in the dataset:
{{#invoke:Vehicles|get|{{PAGENAME}}}}
Render infobox for a specific vehicle
A specific vehicle key can also be provided manually:
{{#invoke:Vehicles|get|Sandbike}}
Render infobox without adding categories
An optional parameter can be used to prevent the infobox from adding the page to categories:
{{#invoke:Vehicles|get|Sandbike|omit=yes}}
Parameters
- 1
- The vehicle key used in Module:Vehicles/data.
- omit (optional)
- If set to
true,yes, or1, the module will passomit_categories=yesto Template:VehicleInfobox.
Notes
- If a vehicle key is not found in the dataset, a placeholder infobox is rendered using default values.
local p = {}
local data = require("Module:Vehicles/data")
local function escape(s)
s = tostring(s or "")
return s:gsub("|", "|")
end
local function isTrue(s)
s = tostring(s or ""):lower()
return s == "true" or s == "yes" or s == "1"
end
local function renderInfobox(name, vehicle, omit)
local out = {}
local type = tostring(vehicle.type or "")
out[#out + 1] = "{{VehicleInfobox"
out[#out + 1] = "|title=" .. escape(name)
out[#out + 1] = "|image=" .. escape(vehicle.image or "Placeholder.png")
out[#out + 1] = "|type=" .. escape(type)
out[#out + 1] = "|category=" .. escape(vehicle.category)
out[#out + 1] = "|minimum_tier={{MetalIcon|" .. escape(vehicle.minimum_tier) .. "}}"
out[#out + 1] = "|crew_capacity=" .. escape(vehicle.crew_capacity)
out[#out + 1] = "|backup_compatible=" .. (vehicle.backup_compatible and "Yes" or "No")
if omit or (type ~= "Ground" and type ~= "Aerial") then
out[#out + 1] = "|omit_categories=true"
end
out[#out + 1] = "}}"
return table.concat(out, "\n")
end
function p.get(frame)
local key = frame.args[1]
local omit = frame.args.omit
if not key or key == "" then
return "<strong class='error'>No vehicle specified.</strong>"
end
local vehicle = data[key]
return frame:preprocess(renderInfobox(key, vehicle, isTrue(omit)))
end
return p