Module:Item: Difference between revisions
mNo edit summary |
Added automatic invert for icons listed in Module:Item/Invert |
||
| (One intermediate revision by the same user not shown) | |||
| Line 18: | 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 28: | 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 54: | 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 111: | 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 130: | 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 136: | 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 | ||