Module:Alternatives: Difference between revisions
Jump to navigation
Jump to search
Erin Umbreon (talk | contribs) aaa |
Erin Umbreon (talk | contribs) make iteration over possible conditions better |
||
| Line 3: | Line 3: | ||
local conditionDescriptions = { | local conditionDescriptions = { | ||
-- genders | -- genders | ||
m | {"m", "If player character is male"}, | ||
f | {"f", "If player character is female"}, | ||
-- races | -- races | ||
hyur | {"hyur", "If player character is a Hyur"}, | ||
elezen | {"elezen", "If player character is an Elezen"}, | ||
lalafell | {"lalafell", "If player character is a Lalafell"}, | ||
miqote | {"miqote", "If player character is a Miqo'te"}, | ||
roegadyn | {"roegadyn", "If player character is a Roegadyn"}, | ||
aura | {"aura", "If player character is an Au Ra"}, | ||
viera | {"viera", "If player character is a Viera"}, | ||
hrothgar | {"hrothgar", "If player character is a Hrothgar"}, | ||
} | } | ||
| Line 25: | Line 25: | ||
local first = true | local first = true | ||
for | for _, possibleCondition in pairs(conditionDescriptions) do | ||
local alternative = args[possibleCondition[0]] | |||
if | if alternative then | ||
if first then | |||
if | -- skip adding the separator before the first alternative | ||
first = false | |||
else | else | ||
-- add the separator | |||
result:node(separator) | |||
end | |||
result:node(mw.html.create("span") | |||
:addClass("alternatives__alternative") | |||
:attr("title", possibleCondition[1]) | |||
:wikitext(alternative) | |||
) | |||
end | end | ||
end | end | ||
Revision as of 21:19, 21 February 2026
Documentation for Module:Alternatives does not exist yet [create] (How does this work?)
local getArgs = require("Module:Arguments").getArgs
local conditionDescriptions = {
-- genders
{"m", "If player character is male"},
{"f", "If player character is female"},
-- races
{"hyur", "If player character is a Hyur"},
{"elezen", "If player character is an Elezen"},
{"lalafell", "If player character is a Lalafell"},
{"miqote", "If player character is a Miqo'te"},
{"roegadyn", "If player character is a Roegadyn"},
{"aura", "If player character is an Au Ra"},
{"viera", "If player character is a Viera"},
{"hrothgar", "If player character is a Hrothgar"},
}
local separator = [[<span class="alternatives__separator">/</span>]]
local p = {}
function p.main(frame)
local args = getArgs(frame, {parentOnly = true})
local result = mw.html.create("span"):addClass("alternatives")
local first = true
for _, possibleCondition in pairs(conditionDescriptions) do
local alternative = args[possibleCondition[0]]
if alternative then
if first then
-- skip adding the separator before the first alternative
first = false
else
-- add the separator
result:node(separator)
end
result:node(mw.html.create("span")
:addClass("alternatives__alternative")
:attr("title", possibleCondition[1])
:wikitext(alternative)
)
end
end
for _, alternative in ipairs(args) do
if first then
-- skip adding the separator before the first alternative
first = false
else
-- add the separator
result:node(separator)
end
-- add the alternative after the separator
result:node(mw.html.create("span")
:addClass("alternatives__alternative")
:wikitext(alternative)
)
end
return result
end
return p