« Module:Monnaie » : différence entre les versions
De Nefald
Autres actions
Aucun résumé des modifications Balise : Révocation manuelle |
Aucun résumé des modifications |
||
| Ligne 12 : | Ligne 12 : | ||
local ICON_SIZE = "24px" | local ICON_SIZE = "24px" | ||
local ALIASES = { | local ALIASES = { | ||
ecu = { "écu", "ecu", "écus", "ecus", "e" }, | ecu = { "écu", "ecu", "écus", "ecus", "e" }, | ||
| Ligne 21 : | Ligne 18 : | ||
} | } | ||
local function buildTooltip(ecus, oboles, sols, total) | local function buildTooltip(ecus, oboles, sols, total) | ||
local parts = {} | local parts = {} | ||
| Ligne 33 : | Ligne 27 : | ||
end | end | ||
local function buildIcon(amount, imageFile, altText, frame) | |||
-- Les pipes dans [[Fichier:...]] cassent le parsing | |||
-- On utilise {{!}} + preprocess pour les injecter proprement | |||
local function buildIcon(amount, imageFile, altText) | local wikilink = "[[Fichier:" .. imageFile | ||
local | .. "{{!}}" .. ICON_SIZE | ||
.. " | .. "{{!}}link={{!}}alt=" .. altText .. "]]" | ||
.. " | local img = frame:preprocess(wikilink) | ||
return '<span class="monnaie__groupe">' | return '<span class="monnaie__groupe">' | ||
.. '<span class="monnaie__valeur">' .. amount .. "</span>" | .. '<span class="monnaie__valeur">' .. amount .. "</span>" | ||
| Ligne 46 : | Ligne 40 : | ||
end | end | ||
local function parseString(input) | local function parseString(input) | ||
local n = tonumber(input) | local n = tonumber(input) | ||
if n then return math.floor(n) end | if n then return math.floor(n) end | ||
| Ligne 62 : | Ligne 51 : | ||
local amount = tonumber(amount_str) or 0 | local amount = tonumber(amount_str) or 0 | ||
unit = mw.text.trim(unit) | unit = mw.text.trim(unit) | ||
for monnaie, aliases in pairs(ALIASES) do | for monnaie, aliases in pairs(ALIASES) do | ||
for _, alias in ipairs(aliases) do | for _, alias in ipairs(aliases) do | ||
| Ligne 80 : | Ligne 68 : | ||
end | end | ||
function p.afficher(frame) | function p.afficher(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local total | local total | ||
if args[2] ~= nil or args[3] ~= nil then | if args[2] ~= nil or args[3] ~= nil then | ||
local ecus = tonumber(mw.text.trim(args[1] or "")) or 0 | local ecus = tonumber(mw.text.trim(args[1] or "")) or 0 | ||
| Ligne 95 : | Ligne 78 : | ||
total = (ecus * ECU_VALUE) + (oboles * OBOLE_VALUE) + sols | total = (ecus * ECU_VALUE) + (oboles * OBOLE_VALUE) + sols | ||
elseif args[1] ~= nil then | elseif args[1] ~= nil then | ||
local arg1 = mw.text.trim(args[1]) | local arg1 = mw.text.trim(args[1]) | ||
| Ligne 111 : | Ligne 93 : | ||
end | end | ||
local ecus = math.floor(total / ECU_VALUE) | local ecus = math.floor(total / ECU_VALUE) | ||
local reste = total % ECU_VALUE | local reste = total % ECU_VALUE | ||
| Ligne 117 : | Ligne 98 : | ||
local sols = reste % OBOLE_VALUE | local sols = reste % OBOLE_VALUE | ||
local tooltip = buildTooltip(ecus, oboles, sols, total) | local tooltip = buildTooltip(ecus, oboles, sols, total) | ||
local parts = {} | local parts = {} | ||
if ecus > 0 then parts[#parts+1] = buildIcon(ecus, IMAGES.ecu, "écu") | if ecus > 0 then parts[#parts+1] = buildIcon(ecus, IMAGES.ecu, "écu", frame) end | ||
if oboles > 0 then parts[#parts+1] = buildIcon(oboles, IMAGES.obole, "obole") end | if oboles > 0 then parts[#parts+1] = buildIcon(oboles, IMAGES.obole, "obole", frame) end | ||
if sols > 0 then parts[#parts+1] = buildIcon(sols, IMAGES.sol, "sol") | if sols > 0 then parts[#parts+1] = buildIcon(sols, IMAGES.sol, "sol", frame) end | ||
if #parts == 0 then | if #parts == 0 then | ||
parts[#parts+1] = buildIcon(0, IMAGES.sol, "sol") | parts[#parts+1] = buildIcon(0, IMAGES.sol, "sol", frame) | ||
end | end | ||
local styles = frame:extensionTag("templatestyles", "", { src = "Modèle:Monnaie/styles.css" }) | local styles = frame:extensionTag("templatestyles", "", { src = "Modèle:Monnaie/styles.css" }) | ||