Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 17: | Zeile 17: | ||
]] | ]] | ||
["small"] = "x10px", | ["small"] = "x10px", | ||
["klein"] = "x10px", | |||
["medium"] = "x14px", | ["medium"] = "x14px", | ||
["mittel"] = "x14px", | |||
["normal"] = "x14px", | ["normal"] = "x14px", | ||
["big"] = "x20px", | ["big"] = "x20px", | ||
["gross"] = "x20px", | |||
} | } | ||
| Zeile 136: | Zeile 139: | ||
a consistent line height | a consistent line height | ||
]] | ]] | ||
["klein"] = "x10px", | |||
["small"] = "x10px", | ["small"] = "x10px", | ||
["medium"] = "x14px", | ["medium"] = "x14px", | ||
["normal"] = "x14px", | ["mittel"] = "x14px", | ||
["normal"] = "x14px", | |||
["gross"] = "x20px", | |||
["big"] = "x20px" | ["big"] = "x20px" | ||
} | } | ||
| Zeile 216: | Zeile 222: | ||
table.sort(keys) | table.sort(keys) | ||
result = '{| class="va-table va-table-full"\n|-\n ! | result = '{| class="va-table va-table-full"\n|-\n !Präfix!!Symbol!!Präfix!!Symbol!!Präfix!!Symbol\n|-\n' | ||
set = 1 | set = 1 | ||
for k,v in ipairs(keys) do | for k,v in ipairs(keys) do | ||
Aktuelle Version vom 17. August 2023, 09:38 Uhr
Eine Bibliothek von Funktionen für die Anzeige von Symbolen auf Seiten oder in anderen Vorlagen. Für beste Leistung, eine Kette von Symbolen (in einer Reihe sitzen, ohne dass dazwischen etwas ist)sollte mit einem einzigen Anruf erledigt werden.
Funktionen
Dieses Modul basiert auf exists() und trim(), die in Module:Util2 enthalten sind. Allen Funktionsaufrufen von diesem Modul wird util vorangestellt, z. B. util.exists().
_generate()
Diese Funktion ist nur intern und das Hauptarbeitspferd für p.Icons() und p.innerIcon(). Diese Funktion erstellt die Funktionsliste. Die erste Aufgabe besteht darin, die Größe der Symbole zu bestimmen.
if util.exists(iconSetting) then
iconSetting = util.trim(iconSetting)
if util.exists(iconSize[iconSetting]) then
iconSetting = iconSize[iconSetting]
end
else
iconSetting = iconSize["medium"]
end
-- This is for calls from other Lua modules as the above will result in nil
if util.exists(iconSetting) == false then
if util.exists(iconSize) then
iconSetting = iconSize
else
iconSetting = iconSize["medium"]
end
endIn WikiText Markup währe das equivalent zu:
{{#ifeq:{{{iconSetting}}}|medium|{{#switch:{{{iconSetting}}}|a = x14px |b = 16px| c= 20px|...|#default = {{{iconSize|x14px}}}}}}}
Der nächste Schritt besteht darin, die durch Kommas getrennten Listen in eine Tabelle aufzuteilen:
if util.exists(iconLinks) then
iconLinks = mw.text.split(iconLinks, ",")
end
if util.exists(tipOverride) then
tipOverride = mw.text.split(tipOverride, ",")
end
if util.exists(iconClass)then
iconClass = "|class=" .. tostring(iconClass);
else
iconClass = ""
endDies wäre gleichbedeutend mit der Verwendung mehrerer {{#explode:}}-Funktionen und -Variablen, um jedes Element als eigenes zu speichern.
Sobald die Daten vorverarbeitet wurden, wird eine Schleife verwendet, um jedes Element in der Liste zu durchlaufen und die Symbolsammlung zu generieren:
for k, v in ipairs(iconList) do
newIcon = iconData[util.trim(v)]
if util.exists(newIcon) then
currentIcon = newIcon.icon
if util.exists(tipOverride, k) then
currentTip = tipOverride[k]
else
if util.exists(iconLinks, k) then
currentTip = iconLinks[k]
else
currentTip = newIcon.tip
end
end
else
currentIcon = "Icon question.png"
currentTip = "Unbekannter Symbolname"
result = result .. "[[Kategorue:Module mit ungültigen Parametern]]"
end
--Create wikitext icon
dataLine = '[[File:' .. currentIcon .. '|' .. iconSetting
if util.exists(iconLinks, k) then
dataLine = dataLine .. '|link=' .. iconLinks[k]
else
dataLine = dataLine .. '|link='
end
if currentTip ~= nil then
dataLine = dataLine .. '|' .. currentTip
end
dataLine = dataLine .. iconClass .. ']]'
createTip = mw.html.create('span')
createTip:addClass( 'va-icon' )
:attr('title', currentTip)
:wikitext(dataLine)
result = result .. tostring(createTip)
if k < table.getn(iconList) then
result = result .. " "
end
endZeile 2 überprüft die Datenliste unter Module:Symbole/daten auf die Daten, die sich auf den Symbol-Shortcode beziehen, und gibt ein Ergebnis oder nil (existiert nicht) zurück, je nachdem, ob ein Ergebnis gefunden wurde Der Code wird fortgesetzt. Wenn es keine Übereinstimmung gibt, wird in den Zeilen 14/15 ein Dummy-Symbol bereitgestellt und in Zeile 16 eine Wartungskategorie hinzugefügt.
Wenn eine Übereinstimmung gefunden wird, besteht die nächste Aufgabe darin, zu prüfen, ob der Tooltip überschrieben wird. Wenn er nicht überschrieben wird, wird geprüft, ob ein alternativer Seitenlink bereitgestellt wurde. Andernfalls wird auf den Standard-Tooltip zurückgegriffen.
Das Wikitext-Äquivalent wäre:
{{{tipOverride|{{{iconLinks|default}}}}}}
Nachdem nun das richtige Symbol, der richtige Tooltip und der richtige Link vorliegen, erstellen die Zeilen 21-31 die Bilddatei im Format
[[File:<icon>|<size>|link=<link>|<tooltip>|class=<class>]].
Die Zeilen 33–37 erstellen den <span />, der das Symbol enthält und das Symbol darin einfügt. Beim Rendern wird dies als <nowik><span class="va-icon" title="<tooltip>">Symbol</nowiki> angezeigt.
Schließlich prüfen die Zeilen 39–41, ob das zu erstellende Element das letzte in der Liste ist, das erstellt wird. Andernfalls wird am Ende der Zeichenfolge ein Leerzeichen eingefügt, sodass zwischen den Symbolen auf der Seite nach Fertigstellung Platz bleibt.
Aufrufparameter
Die Aufrufparameter werden von p.Icons(frame) oder p.innerIcon(iconList, iconSetting, iconLinks, tipOverride, iconClass, iconSize) übergeben. Die Variablen stimmen zwischen diesen drei Funktionen überein und das Folgende sollte als Erklärung für alle drei verstanden werden.
| Name | Parameter | Variable | Beschreibung | Erforderlich | Beispiel |
|---|---|---|---|---|---|
| Icons | 1 | iconList | Eine Zeichenfolgenliste mit Symbol-Funktionscodes, die an das Modul weitergeleitet werden. Wenn mehrere Codes übergeben werden, sollten diese durch ein Komma (,) getrennt werden. | fo76,ww | |
| Icon Size | 2 | iconSetting | Die Bildgröße, die an alle Symbole in der Liste übergeben werden soll. Es kann eine benutzerdefinierte Größe eingestellt werden (z. B. x26px) oder eine der Standardgrößen angewendet werden:
Um sicherzustellen, dass alle Symbole eine einheitliche Größe haben, wird empfohlen, die Höhe (z. B. „x“ 14 Pixel) und nicht die Breite (z. B. 14 Pixel) zu steuern. |
- Standardeinstellungen sind integriert | |
| Link | 3 | iconLinks | Die Seite(n), auf die das/die Symbol(e) verlinkt. Bei mehreren Seiten werden Artikelnamen durch ein Komma (,) getrennt. | Fallout 76,Wild Wasteland | |
| Tooltip | 4 | tipOverride | Die Tooltips, die angezeigt werden, wenn Sie mit der Maus über das/die Symbol(e) fahren. Bei mehreren Symbolen können die Tooltips durch ein Komma (') getrennt werden. | - Defaults are built in | Fire, EMP |
| CSS Class | 4 | iconClass | CSS-Klassen, die auf die Symbole angewendet werden sollen. Wenn dies festgelegt ist, gilt es für alle Symbole in der Gruppe. Klassen werden ohne die Komponente class= geschrieben. |
va-icon va-icon-blue |
p.Icons() und p.innerIcon()
Diese beiden Funktionen sind Durchleitungsfunktionen an _generate(). Vor dem Durchlaufen wird die Liste der mitgelieferten Icons geteilt.
Der Unterschied zwischen den Funktionen besteht darin, wo sie verwendet werden sollten und dass p.innerIcon() keine Tabelle mit Symbolgrößen durchläuft, sondern nur eine vorgegebene Größe und nur von anderen Lua-Modulen aufgerufen werden kann. p.Icons() gilt für alle anderen Namespaces und kann nicht von einem anderen Modul aufgerufen werden.
Aufrufparameter
Aufgrund der Nähe dieser beiden Funktionen und _generate() sind die Aufrufparameter dieselben wie oben aufgeführt.
p.platforms()
p.platforms() verwendet denselben Datensatz wie die anderen Funktionen, gibt jedoch nur Ergebnisse für Symbole zurück, die im Datensatz als Plattform markiert wurden. Darüber hinaus wird auch Semantic Mediawiki verwendet, sodass die zurückgegebenen Daten in Special:Ask abgefragt werden können.
Sobald die Funktion bestätigt hat, dass das Symbol in der Liste eine gültige Plattform ist, erstellt sie einen versteckten <span /> mit dem semantischen Tag, der die standardmäßig zugewiesene Plattform angibt Tooltip [[Hat Plattform::<Plattform>]]. Der Code folgt dann weitgehend dem von _generate(), um das Symbol zu erstellen, mit einem leeren Link-Attribut. Anschließend werden die beiden Spannweiten zusammengefügt, bevor nach der nächsten Plattform gesucht wird.
Wenn keine Plattformen gefunden werden, gibt der Code <sup>[Plattformen benötigt]</sup>[[Kategorie:Plattformen benötigt]] zurück.
Aufrufparameter
Der einzige Parameter, den diese Funktion übernimmt, ist der iconList-Parameter, der die Zeichenfolge der Funktionscodes enthält.
p.documentation()
p.documentation() ist eine selbstgenerierende Dokumentation, um das von jedem Funktionscode erzeugte Symbol anzuzeigen. Zunächst werden alle verfügbaren Datensätze in alphabetischer Reihenfolge sortiert und eine Tabellenüberschrift erstellt, die drei Symbole hintereinander zulässt. Für jeden Funktionscode wird der Funktionscode in die erste, dritte oder fünfte Spalte und das Symbol in die zweite, vierte oder sechste Spalte eingefügt, je nachdem, wo im sortierten Datensatz es sich befindet.
Aufgrund der ständig wachsenden Symbolliste besteht die Gefahr, dass diese Funktion mit der Zeit überdimensioniert wird. Wenn die Zeichengröße überschritten wird, ist möglicherweise eine Aufteilung in zwei Funktionen erforderlich.
Invocation parameters
As a self contained function, there are not parameters that can be passed through.
Verfügbare Symbole
Darüber hinaus können alle von {{Abb}} unterstützten Abkürzungen verwendet werden, um ein Symbol für das entsprechende Spiel zu erstellen.
local p = {}
local util = require( 'Module:Util2' )
--[[
Icon data is now stored on the sub page /data to seperate functional code
for the dataset users will often need to update. This reduces the risk of
breaking the code by entering data in the wrong place and makes it easier to
manage the code itself by not having to pass through the large dataset at
the top.
]]
require( 'Module:Symbole/daten' )
local iconSize = {
--[[
All sizes are controlled on the height to ensure a string of icons maintain
a consistent line height
]]
["small"] = "x10px",
["klein"] = "x10px",
["medium"] = "x14px",
["mittel"] = "x14px",
["normal"] = "x14px",
["big"] = "x20px",
["gross"] = "x20px",
}
--[[ 28/Oct/2021 Added class control table to array as to handle light/dark
themes. This was originally put into the frontend template, when class
handling should be back end. Adding the ['class'] = 'light' or
['class'] = 'dark' parameter to a icon's dataset on /data will enable it to
access a class if needed.
]]
--[[ 08/Nov/2021 Remove the class definition as to be able to just pass straight through
local class = {
['light'] = 'lighticon',
['dark'] = 'darkicon',
['general'] = 'generalicon'
}
]]
function _generate(iconList, iconSetting, iconLinks, tipOverride, iconClass, iconSize)
if util.exists(iconSetting) then
iconSetting = util.trim(iconSetting)
if util.exists(iconSize[iconSetting]) then
iconSetting = iconSize[iconSetting]
end
else
iconSetting = iconSize["medium"]
end
-- This is for calls from other Lua modules as the above will result in nil
if util.exists(iconSetting) == false then
if util.exists(iconSize) then
iconSetting = iconSize
else
iconSetting = 'x14px'
end
end
if util.exists(iconLinks) then
iconLinks = mw.text.split(iconLinks, ",")
end
if util.exists(tipOverride) then
tipOverride = mw.text.split(tipOverride, ",")
end
if util.exists(iconClass)then
iconClass = "|class=" .. tostring(iconClass);
else
iconClass = ""
end
local result = ""
for k, v in ipairs(iconList) do
newIcon = iconData[util.trim(v)]
if util.exists(newIcon) then
currentIcon = newIcon.icon
if util.exists(tipOverride, k) then
currentTip = tipOverride[k]
else
if util.exists(iconLinks, k) then
currentTip = iconLinks[k]
else
currentTip = newIcon.tip
end
end
else
currentIcon = "Icon question.png"
currentTip = "Unbekannter Symbolname"
result = result .. "[[Kategorie:Modulee mit ungültigen Parametern]]"
end
--Create wikitext icon
dataLine = '[[File:' .. currentIcon .. '|' .. iconSetting
if util.exists(iconLinks, k) then
dataLine = dataLine .. '|link=' .. iconLinks[k]
else
dataLine = dataLine .. '|link='
end
if currentTip ~= nil then
dataLine = dataLine .. '|' .. currentTip
end
dataLine = dataLine .. iconClass .. ']]'
createTip = mw.html.create('span')
createTip:addClass( 'va-icon' )
:attr('title', currentTip)
:wikitext(dataLine)
result = result .. tostring(createTip)
if k < table.getn(iconList) then
result = result .. " "
end
end
return result
end
-- Calls from other modules
function p.innerIcon(iconList, iconSetting, iconLinks, tipOverride, iconClass, iconSize)
iconList = mw.text.split(iconList, ',')
return _generate(iconList, iconSetting, iconLinks, tipOverride, iconClass, iconSize)
end
function p.Icons(frame)
--[[All icons are now lower case to reduce script errors from
incorrectly entering the icon code in a different case to the list]]
local iconList = mw.text.split(string.lower(frame.args[1]), ",")
local iconSetting = frame.args[2]
local iconLinks = frame.args[3]
local tipOverride = frame.args[4]
local iconClass = frame.args[5]
local iconSize = {
--[[
All sizes are controlled on the height to ensure a string of icons maintain
a consistent line height
]]
["klein"] = "x10px",
["small"] = "x10px",
["medium"] = "x14px",
["mittel"] = "x14px",
["normal"] = "x14px",
["gross"] = "x20px",
["big"] = "x20px"
}
return _generate(iconList, iconSetting, iconLinks, tipOverride, iconClass, iconSize)
end
function p.platforms(frame)
--[[All icons are now lower case to reduce script errors from
incorrectly entering the icon code in a different case to the list]]
local icons = mw.text.split(string.lower(frame.args[1]), ",")
local result = ""
for k, v in ipairs(icons) do
currentIcon = iconData[util.trim(v)]
if util.exists(currentIcon, 'plattform') == true then
createSM = mw.html.create('span')
createSM:css('display', 'none')
:wikitext('[[Hat Plattform::' .. currentIcon.tip .. ']]')
:allDone()
createPlatform = mw.html.create('span')
if (util.exists(currentIcon.class)) then
iconClass = "|class=" .. tostring(currentIcon.class);
else
iconClass = ""
end
createPlatform:addClass('va-icon')
:attr('title', currentIcon.tip)
:wikitext('[[File:'
.. currentIcon.icon
.. '|alt='
.. currentIcon.tip
.. '|x14px|link='
.. iconClass..']]')
:allDone()
if (util.exists(iconData[util.trim(v)..' dark'])) then
currentDarkIcon = iconData[util.trim(v)..' dark']
createPlatformDark = mw.html.create('span')
if (util.exists(currentDarkIcon.class)) then
iconClass = "|class=" .. tostring(currentDarkIcon.class);
else
iconClass = ""
end
createPlatformDark:addClass('va-icon')
:attr('title', currentDarkIcon.tip)
:wikitext('[[File:'
.. currentDarkIcon.icon
.. '|alt='
.. currentDarkIcon.tip
.. '|x14px|link='
.. iconClass..']]')
:allDone()
createPlatform = tostring(createPlatform)..tostring(createPlatformDark)
end
--[[ Uncommenting tostring(createSM) below will enable
Semantic Mediawiki data tracking]]
result = result .. tostring(createSM)
.. tostring(createPlatform)
if k < table.getn(icons) then
result = result .. " "
end
end
end
if result == '' then
result = '<sup>[Plattform erforderlich]</sup>[[Kategorie:Plattform erforderlich]]'
end
return result
end
function p.documentation()
keys = {}
for k in pairs(iconData) do
table.insert(keys, k)
end
table.sort(keys)
result = '{| class="va-table va-table-full"\n|-\n !Präfix!!Symbol!!Präfix!!Symbol!!Präfix!!Symbol\n|-\n'
set = 1
for k,v in ipairs(keys) do
i = iconData[v]
result = result .. "||'''" .. v .. "'''"
if util.exists(i) == true and i.class ~= nil then
newFile = mw.html.create(span)
--:addClass(class[i.class])
:wikitext('[[File:' .. iconData[v].icon .. '|25px]]')
else
newFile = mw.html.create(span)
:wikitext('[[File:' .. iconData[v].icon .. '|25px]]')
end
result = result .. '||' .. tostring(newFile)
if set == 3 then
result = result .. '\n|-\n'
end
if set < 3 then
set = set + 1
else
set = 1
end
end
result = result .. '\n|}'
return result
end
function p.Test(frame)
--Please empty when done debugging so other users know it is free to use
end
return p