Module:Vehicles

From Dune: Awakening Community Wiki
Jump to navigation Jump to search

Module:Vehicles

Provides structured access to vehicle data defined in Module:Vehicles/data.

This module provides two functions:

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}}

Safe category output

Vehicle types are validated against definitions in Module:Vehicles/data. If valid, the corresponding MediaWiki category is returned. Invalid or unknown types produce no output.

{{#invoke:Vehicles|category|Ground}}

Parameters

get

1
string
The vehicle key used in Module:Vehicles/data.

category

1
string
A valid vehicle type string used in Module:Vehicles/data.

Notes

get

  • If a vehicle key is not found in the dataset, a placeholder infobox is rendered using default values.

local p = {}

local dataModule = require("Module:Vehicles/data")

local data = dataModule.vehicles
local vehicleTypes = dataModule.vehicleTypes

-- ---------- Helpers ----------

local function escape(s)
    s = tostring(s or "")
    return s:gsub("|", "|")
end

-- ---------- Rendering ----------

local function renderInfobox(name, vehicle)
    local out = {}
 
    out[#out + 1] = "{{VehicleInfobox"
    out[#out + 1] = "|title=" .. escape(name)
    out[#out + 1] = "|type=" .. escape(vehicle.type)
    out[#out + 1] = "|category=" .. escape(vehicle.category)
    out[#out + 1] = "|minimum_tier={{Tier|" .. 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")

    out[#out + 1] = "}}"
    return table.concat(out, "\n")
end

function p.get(frame)
    local key = mw.text.trim(frame.args[1] or "")

    if key == "" then
            return "<span class='error'>⚠ No vehicle specified.</strong>"
    end

    local vehicle = data[key]

    if not vehicle then
        return "<span class='error'>⚠ Unknown vehicle: " .. key .. "</strong>"
    end

    return frame:preprocess(renderInfobox(key, vehicle))
end

function p.category(frame)
    local vehicleType = mw.text.trim(frame.args[1] or "")
    local cat = vehicleTypes[vehicleType]

    if cat then
        return "[[Category:" .. cat .. "]]"
    end

    return
end

return p