Module:DLC
Jump to navigation
Jump to search
Module:DLC
Renders a DLC infobox using Template:DLCInfobox, sourced from Module:DLC/data with translatable display strings from MessageBundle:DLC.
This module provides the following function(s):
get- renders an infobox for a single DLC.
Usage
Render infobox for current DLC page
On a DLC page, where the page title matches (via slugification) a DLC key in the dataset:
{{#invoke:DLC|get|{{BASEPAGENAME}}}}
Render infobox for a specific DLC
A specific DLC name can also be provided manually:
{{#invoke:DLC|get|Wildlife of Arrakis}}
Include contents list
An optional contents parameter can be passed through to the infobox, typically a bulleted list:
{{#invoke:DLC|get|Wildlife of Arrakis
|contents =
* [[Wildlife]]-themed Decorations
}}
Parameters
get
- 1 (required)
- string
- The DLC name. This is slugified before lookup, so it does not need to exactly match the key casing/formatting used in Module:DLC/data.
- Returns an error message if no DLC is specified, or if the slugified name has no match in the dataset.
- contents (optional)
- string
- Wikitext passed through to the infobox's
Contentsfield. Omitted entirely if not provided.
Notes
get
- Display strings (name and DLC type label) are resolved via MessageBundle:DLC using the page's current language, with the English source also resolved separately for use as internal/category-facing values.
local p = {}
local common = require("Module:Common")
local data = require("Module:DLC/data")
-- ---------- Data ----------
local FLAT_DATA = {}
for dlcType, items in pairs(data) do
for id, item in pairs(items) do
item.type = dlcType
FLAT_DATA[id] = item
end
end
-- ---------- Rendering ----------
local function renderInfobox(id, item, contents)
local displayName = common.translate("DLC", id .. "-name")
local englishName = common.translate("DLC", id .. "-name", "en")
local displayType = common.translate("DLC", "type-" .. item.type)
local englishType = common.translate("DLC", "type-" .. item.type, "en")
local out = {}
out[#out + 1] = "{{DLCInfobox"
out[#out + 1] = "|title=" .. englishName
out[#out + 1] = "|display_title=" .. displayName
out[#out + 1] = "|type=" .. englishType
out[#out + 1] = "|display_type=" .. displayType
out[#out + 1] = "|release_date=" .. item.date
if item.steam then out[#out + 1] = "|steam=" .. item.steam end
if item.xbox then out[#out + 1] = "|xbox=" .. item.xbox end
if item.ps then out[#out + 1] = "|ps=" .. item.ps end
if contents then out[#out + 1] = "|contents=" .. contents end
out[#out + 1] = "}}"
return table.concat(out, "\n")
end
-- ---------- Interface ----------
function p.get(frame)
local raw = common.trim(frame.args[1])
if raw == "" then return common.error("No DLC specified.") end
local key = common.slugify(raw)
local item = FLAT_DATA[key]
if not item then return common.error("Unknown DLC: %s", raw) end
local contents = frame.args.contents
return frame:preprocess(renderInfobox(key, item, contents))
end
return p