Modul:Spectrum Dispatch
Aus Star Citizen Wiki
Weitere Optionen
Diese Dokumentation wird von Modul:Spectrum Dispatch/doc aus übernommen. Änderungen können auf der Diskussionsseite vorgeschlagen werden.
| Function list |
|---|
| L 25 — methodtable.setSemanticProperties L 35 — methodtable.getShowType L 55 — methodtable.getShowName L 72 — methodtable.setMainCategory L 90 — methodtable.getHeaderTitle L 105 — methodtable.getTitle L 116 — methodtable.getTitleImage L 138 — methodtable.getPageTitle L 161 — methodtable.init L 198 — toLinkLines L 215 — methodtable.getInfobox L 277 — SpectrumDispatch.infoBox L 286 — SpectrumDispatch.new |
Modulinfo
Dieses Modul setzt mehrere Vorlagen wie z.B. Vorlage:News Update um. Anweisungen zur Verwendung findest du auf der Vorlagenseite.
require('strict')
--- Spectrum-Dispatch-Infobox für Lore-/Serienartikel (Orbital Supermax,
--- Advocacy Archive, News Updates, ...). Ordnet Seitentitel über
--- Module:Spectrum_Dispatch/data.json einer Serie und ihrem Typ zu, speichert
--- die Fakten nach SMW und rendert über Module:InfoboxLua.
--- Aufrufer: Vorlage:Spectrum Dispatch ({{#invoke:Spectrum_Dispatch|infoBox}}),
--- Vorlage:Literatur leitet dorthin weiter.
local SpectrumDispatch = {}
local metatable = {}
local methodtable = {}
metatable.__index = methodtable
-- Data about series name and type. Space form: matches the mirror path and
-- the canonical page title; underscore form resolves to the same page on-wiki.
local showData = mw.loadJsonData('Module:Spectrum Dispatch/data.json')
-- Needed Extensions
local common = require('Module:Common')
--- Write the semantic properties
function methodtable.setSemanticProperties(self)
local result = mw.smw.set(self.smwData)
common.checkSmwResult(result)
end
--- Parses the shows type
--- Adds a maintenance category if an invalid type was passed
---
--- @return string
function methodtable.getShowType(self)
local title = mw.title.getCurrentTitle().text
for name, type in pairs(showData.name) do
if string.match(title, name) then
return type
end
end
if self.args['show_type'] ~= nil then
return self.args['show_type']
end
table.insert(self.categories, '[[Category:Spectrum Artikel mit fehlerhaftem Serientyp]]')
end
--- Parses the shows name
--- Adds a maintenance category if an invalid name was passed
---
--- @return string
function methodtable.getShowName(self)
local title = mw.title.getCurrentTitle().text
for name, _ in pairs(showData.name) do
if string.match(title, name) then
return name
end
end
if self.args['show_name'] ~= nil then
return self.args['show_name']
end
table.insert(self.categories, '[[Category:Spectrum Artikel mit fehlerhaftem Seriennamen]]')
end
--- Adds the main category
function methodtable.setMainCategory(self)
local cat = ''
local showType = self.smwData['Serientyp']
if self.smwData['Episode'] ~= nil or showType == 'Time Capsule' or showType == 'News Update' then
cat = self.smwData['Serienname']
else
cat = self.smwData['Serientyp']
end
if cat ~= nil then
table.insert(self.categories, '[[Category:' .. cat .. ']]')
end
end
--- Get the infobox header title
---
--- @return string
function methodtable.getHeaderTitle(self)
local output = ''
if self.smwData['Serienname'] then
if self.args['show_name'] == nil then
output = self.smwData['Serienname'] .. ': '
end
end
return output .. mw.title.getCurrentTitle().subpageText
end
--- Infobox title
---
--- @return string
function methodtable.getTitle(self)
if self.smwData['Serientyp'] == 'Galactic Guide' then
return 'Galactic Guide / Portfolio'
end
return self.smwData['Serientyp']
end
--- Tries to retrieve the infobox image
---
--- @return string|boolean Prefixed filename or false
function methodtable.getTitleImage(self)
local suffix = '_Titelbild'
local names = {
self.args['image'],
}
if self.smwData['Serienname'] ~= nil then
table.insert(names, self.smwData['Serienname'] .. '_' .. mw.title.getCurrentTitle().subpageText .. suffix)
table.insert(names, self.smwData['Serienname'] .. suffix)
if self.smwData['Serientyp'] ~= nil then
table.insert(names, self.smwData['Serientyp'] .. '_' .. self.smwData['Serienname'] .. suffix)
end
end
return common.getImage(names)
end
--- Build the display title
---
--- @return string
function methodtable.getPageTitle(self)
local title = ''
if self.smwData['Serientyp'] == 'Time Capsule' or self.smwData['Serientyp'] == 'News Update' then
title = self.smwData['Serienname'] .. ' - '
if self.smwData['Episode'] ~= nil and self.smwData['Serientyp'] ~= 'Time Capsule' then
title = title .. 'Episode ' .. self.smwData['Episode']
else
title = title .. mw.title.getCurrentTitle().subpageText
end
else
title = self.smwData['Serienname']
if self.smwData['Episode'] ~= nil then
title = title .. ' - Episode ' .. self.smwData['Episode']
end
end
return title
end
--- Extracts args and sets up the module
---
--- @param frame table The current frame
function methodtable.init(self, frame)
self.frame = frame
self.args = require('Module:Arguments').getArgs(frame)
self.smwData['Serientyp'] = self:getShowType()
self.smwData['Serienname'] = self:getShowName()
self.smwData['Veröffentlichung'] = self.args['release']
self.smwData['Episode'] = tonumber(self.args['episode'])
self.smwData['Thema'] = common.extractDataFromPrefix('topic', self.args)
self.smwData['Besetzung'] = common.extractDataFromPrefix('cast', self.args)
self.smwData['Quelle'] = {
self.args['source_url_rsi'] or nil,
self.args['source_url_translation'] or nil,
}
local commLinkIds = common.extractDataFromPrefix('comm_link_id', self.args)
for _, id in pairs(commLinkIds) do
table.insert(self.commLinks, 'Comm-Link:' .. id)
end
if #self.commLinks > 0 then
self.smwData['Comm-Link'] = self.commLinks
end
if not require('Module:Localized').isLanguagePage() then
self:setSemanticProperties()
end
self:setMainCategory()
end
--- Row content for a link list: one linked entry per line.
---
--- @param values string[]
--- @param link boolean Wrap each value in [[...]]
--- @return string
local function toLinkLines(values, link)
local parts = {}
for _, v in pairs(values) do
if link then
table.insert(parts, '[[' .. v .. ']]')
else
table.insert(parts, v)
end
end
return table.concat(parts, '<br>')
end
--- Builds the infobox
---
--- @return string
function methodtable.getInfobox(self)
local infobox = require('Module:InfoboxLua')
common.setDisplayTitle(self.frame, self:getPageTitle())
-- Unresolved title image falls through to InfoboxLua's image discovery
-- and, failing that, the native placeholder plus QuantumUpload contract.
local image = self:getTitleImage()
if image == false then
image = nil
end
local items = {}
if self.smwData['Episode'] then
-- smwData['Episode'] is a number; the item schema wants strings
table.insert(items, { label = 'Episode', content = tostring(self.smwData['Episode']) })
end
if self.smwData['Veröffentlichung'] then
table.insert(items, { label = 'Veröffentlichung', content = self.smwData['Veröffentlichung'] })
end
if #self.smwData['Besetzung'] > 0 then
table.insert(items, { label = 'Personenliste', content = toLinkLines(self.smwData['Besetzung'], true) })
end
if #self.smwData['Thema'] > 0 then
table.insert(items, { label = 'Themenliste', content = toLinkLines(self.smwData['Thema'], false) })
end
if #self.commLinks > 0 then
table.insert(items, { label = 'Comm-Link', content = toLinkLines(self.commLinks, true) })
end
if self.args['source_url_rsi'] ~= nil then
table.insert(items, { label = 'RSI', content = '[' .. self.args['source_url_rsi'] .. ' RSI]' })
end
if self.args['source_url_translation'] ~= nil then
table.insert(
items,
{ label = 'Übersetzung', content = '[' .. self.args['source_url_translation'] .. ' Übersetzung]' }
)
end
return infobox.render({
title = self:getTitle(),
subtitle = self:getHeaderTitle(),
image = image,
sections = {
{
columns = 2,
items = items,
},
},
}) .. table.concat(self.categories, '')
end
--- Template entry
---
--- @return string
function SpectrumDispatch.infoBox(frame)
local instance = SpectrumDispatch:new()
instance:init(frame)
return instance:getInfobox()
end
--- New Instance
--- Library entrance
function SpectrumDispatch.new(self)
local instance = {
frame = {},
args = {},
smwData = {
['Serientyp'] = nil,
['Serienname'] = nil,
['Veröffentlichung'] = nil,
['Episode'] = nil,
['Thema'] = {},
['Besetzung'] = {},
},
categories = {},
commLinks = {},
}
setmetatable(instance, metatable)
return instance
end
return SpectrumDispatch
