Modul:Organisation
Aus Star Citizen Wiki
Weitere Optionen
Diese Dokumentation wird von Modul:Organisation/doc aus übernommen. Änderungen können auf der Diskussionsseite vorgeschlagen werden.
| Function list |
|---|
| L 25 — getFromData L 47 — trimMarkers L 56 — item L 64 — pack L 78 — methodtable.addType L 97 — methodtable.getOrientation L 124 — methodtable.addObligation L 145 — methodtable.addBoolean L 166 — optionalRow L 174 — methodtable.getImage L 200 — methodtable.getEscapeRows L 223 — normalizeHandle L 229 — methodtable.infoBox L 352 — Organisation.infobox L 360 — Organisation.new |
Dieses Modul setzt die Vorlage:Organisation um. Anweisungen zur Verwendung findest du auf der Vorlagenseite.
require('strict')
--- Infobox for player organizations (Organisation namespace).
--- InfoboxLua port replacing the capiunto box; also picks up the .tools
--- PlayerOrg fields (timezone, headquarters, leaders, founder, founded,
--- explicit image). Invalid or unknown values render as plain rows.
--- Called by Vorlage:Organisation ({{#invoke:Organisation|infobox}}).
local Organisation = {}
local metatable = {}
local methodtable = {}
metatable.__index = methodtable
local yesno = require('Module:Yesno')
local data = mw.loadJsonData('Module:Organisation/data.json')
--- Maps a raw value through data.json (German key or alias).
--- Unknown input yields nil instead of an error.
---
--- @param haystack string
--- @param needle string
--- @return string|nil
local function getFromData(haystack, needle)
local low = mw.ustring.lower
for key, aliases in pairs(data[haystack]) do
if low(needle) == low(key) then
return key
end
for _, alias in pairs(aliases) do
if low(needle) == low(alias) then
return key
end
end
end
return nil
end
--- Strips capiunto cell markers ('<><>col2') from '!' escape rows.
---
--- @param value string
--- @return string
local function trimMarkers(value)
return mw.text.split(value, '<>', true)[1]
end
--- Row only for a present value; keeps the items array hole-free.
---
--- @param label string
--- @param content string|nil
--- @return table|nil
local function item(label, content)
if content == nil or content == '' then
return nil
end
return { label = label, content = content }
end
local function pack(...)
local out = {}
for i = 1, select('#', ...) do
local it = select(i, ...)
if it ~= nil then
table.insert(out, it)
end
end
return out
end
--- Form row; accepts organisation_type and form as argument names.
function methodtable.addType(self)
local raw = self.args.organisation_type or self.args.form
if raw == nil or raw == '' then
return nil
end
local mapped = getFromData('types', raw)
if mapped == nil then
return item('Form', raw)
end
return item('Form', mapped)
end
--- Orientation row from up to two values.
---
--- @return string|nil
function methodtable.getOrientation(self)
local parts = {}
for _, key in ipairs({ 'orientation_1', 'orientation_2' }) do
local raw = self.args[key]
if raw ~= nil and raw ~= '' then
local mapped = getFromData('orientations', raw)
if mapped == nil then
table.insert(parts, raw)
else
table.insert(parts, mapped)
end
end
end
if #parts == 0 then
return nil
end
return table.concat(parts, ', ')
end
--- Commitment (RSI: Gelegentlich/Regulaer/Hardcore in German).
---
--- @return table|nil
function methodtable.addObligation(self)
local raw = self.args.obligation
if raw == nil or raw == '' then
return nil
end
local mapped = getFromData('obligations', raw)
if mapped == nil then
return item('Verpflichtung', raw)
end
return item('Verpflichtung', mapped)
end
--- Yes/no row (role play, exclusive membership).
---
--- @param key string
--- @param label string
--- @return table|nil
function methodtable.addBoolean(self, key, label)
local raw = self.args[key]
if raw == nil or raw == '' then
return nil
end
local value = 'Nein'
if yesno(raw, false) then
value = 'Ja'
end
return item(label, value)
end
--- Fields whose absence just drops the row (no category).
---
--- @param label string
--- @param raw string|nil
--- @return table|nil
local function optionalRow(label, raw)
return item(label, raw)
end
--- Explicit image (logo or image) without the File: prefix.
---
--- @param self table
--- @return string|nil
function methodtable.getImage(self)
local raw = self.args.logo or self.args.image
if raw == nil or raw == '' then
return nil
end
local name = raw:gsub('^[Dd]atei%:[%s]*', ''):gsub('^[Ff]ile%:[%s]*', '')
-- Only honor the explicit file when it exists; otherwise the naming
-- convention or the placeholder applies. Phoenix Interstellar has
-- rendered its convention logo for years while its logo= parameter
-- names a file without the 'Organisation ' prefix that does not exist.
local ok, title = pcall(mw.title.makeTitle, 'File', name)
if ok and title ~= nil and title.file ~= nil and title.file.exists == true then
return name
end
return nil
end
--- '@'-Zeile? Nein: '!' escape rows from capiunto times, in sorted order.
---
--- @param self table
--- @return table
function methodtable.getEscapeRows(self)
local rows = {}
local keys = {}
for key, value in pairs(self.args) do
if type(key) == 'string' and key:sub(1, 1) == '!' and type(value) == 'string' and value ~= '' then
table.insert(keys, key)
end
end
table.sort(keys)
for _, key in ipairs(keys) do
table.insert(rows, item(key:sub(2), trimMarkers(self.args[key])))
end
return rows
end
--- RSI handle: bare ID or full URL (last path segment wins).
---
--- @param raw string
--- @return string
local function normalizeHandle(raw)
local handle = raw:gsub('^.*/', '')
return mw.ustring.upper(handle)
end
function methodtable.infoBox(self)
local name = mw.title.getCurrentTitle().subpageText
local items = {}
local formItem = self:addType()
local orientation = self:getOrientation()
local obligationItem = self:addObligation()
if self.args.member_count ~= nil and self.args.member_count ~= '' then
table.insert(items, item('Mitgliederanzahl', self.args.member_count))
end
local url = self.args.website
local websiteItem
if url ~= nil and url ~= '' then
if url:match('^https?://') then
websiteItem = item('Webseite', '[' .. url .. ' ' .. name .. ']')
self.smwData['Webseite'] = url
else
websiteItem = item('Webseite', url)
end
end
local handle = self.args.rsi_handle or self.args.spectrum_id
local rsiItem
if handle ~= nil and handle ~= '' then
local normalized = normalizeHandle(handle)
rsiItem =
item('RSI', '[https://robertsspaceindustries.com/orgs/' .. normalized .. ' ' .. normalized .. ' auf RSI]')
end
local teamspeak = self.args.teamspeak
local teamspeakItem
if teamspeak ~= nil and teamspeak ~= '' then
if teamspeak:match('^https?://') then
teamspeakItem = item('Teamspeak', teamspeak)
else
teamspeakItem = item('Teamspeak', '[ts3server://' .. teamspeak .. ' ' .. teamspeak .. ']')
end
end
local discord = self.args.discord
local discordItem
if discord ~= nil and discord ~= '' then
if discord:match('discord%.gg') then
discordItem = item('Discord', '[' .. discord .. ' ' .. name .. ']')
else
discordItem = item('Discord', discord)
end
end
local guilded = self.args.guilded
local guildedItem
if guilded ~= nil and guilded ~= '' then
if guilded:match('guilded%.gg') then
guildedItem = item('Guilded', '[' .. guilded .. ' ' .. name .. ']')
else
guildedItem = item('Guilded', guilded)
end
end
local information = pack(
formItem,
orientation ~= nil and item('Ausrichtung', orientation) or nil,
items[1],
obligationItem,
self:addBoolean('role_play', 'Rollenspiel'),
self:addBoolean('exclusive', 'Exklusive Mitgliedschaft'),
optionalRow('Sprache', self.args.language),
optionalRow('Zeitzone', self.args.timezone),
optionalRow('Hauptsitz', self.args.headquarters),
optionalRow('Leitung', self.args.leaders),
optionalRow('Gründer', self.args.founder or self.args.founders),
optionalRow('Gründung', self.args.founded),
websiteItem,
rsiItem,
teamspeakItem,
discordItem,
guildedItem,
optionalRow('Sonstiges', self.args.other)
)
for _, row in ipairs(self:getEscapeRows()) do
table.insert(information, row)
end
local infobox = require('Module:InfoboxLua')
local html = infobox.render({
title = name,
subtitle = self.args.slogan,
image = self:getImage(),
imageUploadName = 'Organisation ' .. name .. ' Logo',
sections = {
{
columns = 2,
items = information,
},
},
})
-- The category and the SMW write belong on real Organisation pages;
-- /doc or sandbox transclusions must not file into the player-org tree.
if not mw.title.getCurrentTitle():inNamespace(mw.site.namespaces.Organisation.id) then
return html
end
if next(self.smwData) ~= nil then
mw.smw.set(self.smwData)
end
return html .. table.concat(self.categories, '')
end
--- Template entry point.
---
--- @param frame table
--- @return string
function Organisation.infobox(frame)
local instance = Organisation:new()
instance.args = require('Module:Arguments').getArgs(frame)
return instance:infoBox()
end
--- New instance.
function Organisation.new(self)
local instance = {
categories = {
'[[Kategorie:Spielerorganisation]]',
},
smwData = {},
args = nil,
}
setmetatable(instance, metatable)
return instance
end
return Organisation
