Module:Item: Difference between revisions
Removed mobile specific classes and unused parameters. Standardizing parameter naming convention to snake_case Tags: Mobile edit Mobile web edit |
Added automatic invert for icons listed in Module:Item/Invert |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
-- Adapted from: https://genshin-impact.fandom.com/wiki/Module:Item | |||
local p = {} | local p = {} | ||
local lib = require('Module:Feature') | local lib = require('Module:Feature') | ||
| Line 16: | Line 18: | ||
local note = lib.nilIfEmpty(args.note) or nil | local note = lib.nilIfEmpty(args.note) or nil | ||
local ref = lib.nilIfEmpty(args.ref) or nil | local ref = lib.nilIfEmpty(args.ref) or nil | ||
local | local typeInput = lib.nilIfEmpty(args['type']) or 'Item' | ||
local text = lib.nilIfEmpty(args.text) or item | local text = lib.nilIfEmpty(args.text) or item | ||
local link = args.link or lib.ternary(item == 'Unknown', '', item) | local link = args.link or lib.ternary(item == 'Unknown', '', item) | ||
local invert = lib.nilIfEmpty(args.invert) | |||
local newline = tostring(args.newline) == '1' | local newline = tostring(args.newline) == '1' | ||
local | local noText = tostring(args.no_text or args.notext) == '1' | ||
local white = tostring(args.white) == '1' | local white = tostring(args.white) == '1' | ||
| Line 26: | Line 29: | ||
local suffix = ' Icon' | local suffix = ' Icon' | ||
if ( | if (typeInput ~= 'Neighbor' and item == 'Unknown') then | ||
prefix = '' | prefix = '' | ||
suffix = ' Icon' | suffix = ' Icon' | ||
end | |||
local invertIcon = require('Module:Item/Invert') | |||
if not invert then | |||
invert = invertIcon[item] | |||
end | |||
local invertClass = nil | |||
if invert then | |||
invert = invert:lower() | |||
if invert == 'day' or invert == 'light' then | |||
invertClass = 'day-invert-image' | |||
elseif invert == 'night' or invert == 'dark' then | |||
invertClass = 'night-invert-image' | |||
end | |||
end | end | ||
if (white) then suffix = suffix .. ' White' end | if (white) then suffix = suffix .. ' White' end | ||
local | local fileName = 'File:' .. prefix .. item .. suffix .. '.png' | ||
local class = invertClass and ('|class=' .. invertClass) or '' | |||
local file = '[[' .. | local file = '[[' .. fileName .. '|' .. size .. 'x' .. size .. 'px|alt=' .. item .. '|link=' .. link .. class .. ']]' | ||
local icon = nil | local icon = nil | ||
| Line 52: | Line 70: | ||
end | end | ||
local outerClass = lib.ternary( | local outerClass = lib.ternary(typeInput:lower() == 'item', 'item', 'item ' .. typeInput:lower()) | ||
local result = mw.html.create():tag('span'):addClass(outerClass) | local result = mw.html.create():tag('span'):addClass(outerClass) | ||
| Line 88: | Line 106: | ||
function addPunct(var) | function addPunct(var) | ||
if args.comma or args. | if args.comma or args.comma_spc then var = var .. ',' | ||
elseif args.dot or args. | elseif args.dot or args.dot_spc then var = var .. '.' | ||
end | end | ||
var = var | var = var | ||
| Line 103: | Line 121: | ||
end | end | ||
if args. | if args.comma_spc or args.dot_spc then b = b .. ' ' end -- space always on the very end | ||
return {a, b} | return {a, b} | ||
| Line 109: | Line 127: | ||
local item_text = result:tag('span'):addClass('item-text') | local item_text = result:tag('span'):addClass('item-text') | ||
if (not | if (not noText) then | ||
local before = newline and '' or ' ' | local before = newline and '' or ' ' | ||
local ame = ((count or note) and {text, ''} or parseAmE(text, '')) | local ame = ((count or note) and {text, ''} or parseAmE(text, '')) | ||
| Line 128: | Line 146: | ||
count = table.concat(note and {count, ''} or parseAmE(count, ''), '') | count = table.concat(note and {count, ''} or parseAmE(count, ''), '') | ||
if (ref and not note) then count:gsub('%s*$', '') end | if (ref and not note) then count:gsub('%s*$', '') end | ||
item_text:wikitext(( | item_text:wikitext((noText and '' or ' ') .. '×' .. count) | ||
end | end | ||
| Line 134: | Line 152: | ||
local after = table.concat(parseAmE('', ''), '') | local after = table.concat(parseAmE('', ''), '') | ||
if (ref) then after:gsub('%s*$', '') end | if (ref) then after:gsub('%s*$', '') end | ||
item_text:tag('small'):wikitext((( | item_text:tag('small'):wikitext(((noText and not count) and '' or ' '),'(', note, ')', after) | ||
end | end | ||
if (ref) then | if (ref) then | ||
local after = (args. | local after = (args.comma_spc or args.dot_spc) and ' ' or '' -- avoid space between ref and punctuation | ||
item_text:wikitext(ref, after) | item_text:wikitext(ref, after) | ||
end | end | ||