Editing Module:Item
Appearance
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local lib = require('Module:Feature') | local lib = require('Module:Feature') | ||
| Line 18: | Line 16: | ||
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 type = 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 | local blueprint = tostring(args.blueprint) == '1' | ||
local newline = tostring(args.newline) == '1' | local newline = tostring(args.newline) == '1' | ||
local | local notext = tostring(args.notext) == '1' | ||
local white = tostring(args.white) == '1' | local white = tostring(args.white) == '1' | ||
local prefix = '' | local prefix = args.prefix and (args.prefix .. ' ') or (type .. ' ') | ||
local suffix = ' | local suffix = args.suffix and (' ' .. args.suffix) or '' | ||
if ( | if (type ~= 'Neighbor' and item == 'Unknown') then | ||
prefix = '' | prefix = '' | ||
suffix = ' Icon' | suffix = ' Icon' | ||
end | end | ||
if (white) then suffix = suffix .. ' White' end | |||
if | |||
local filename = 'File:' .. prefix .. item .. suffix .. '.png' | |||
local | local file = '[[' .. filename .. '|' .. size .. 'x' .. size .. 'px|alt=' .. item .. '|link=' .. link .. ']]' | ||
local mobile_file = '[[' .. filename .. '|30x30px|alt=' .. item .. '|link=' .. link .. ']]' | |||
local | |||
local icon = nil | local icon = nil | ||
| Line 64: | Line 48: | ||
else | else | ||
offset = -6 | offset = -6 | ||
end | |||
if (blueprint) then | |||
icon = '[[File:Icon Furnishing Blueprint.png|' .. corner_size .. 'x' .. corner_size .. 'px|link=' .. link .. ']]' | |||
end | end | ||
| Line 70: | Line 58: | ||
end | end | ||
local outerClass = lib.ternary( | local outerClass = lib.ternary(type:lower() == 'item', 'item', 'item ' .. type:lower()) | ||
local result = mw.html.create():tag('span'):addClass(outerClass) | local result = mw.html.create():tag('span'):addClass(outerClass) | ||
| Line 76: | Line 64: | ||
:addClass('item-image') | :addClass('item-image') | ||
:tag('span') | :tag('span') | ||
:addClass('hidden') | |||
:css({ | :css({ | ||
width = size .. 'px', | width = size .. 'px', | ||
| Line 82: | Line 71: | ||
:attr('data-size', size) | :attr('data-size', size) | ||
:wikitext(file) | :wikitext(file) | ||
:done() | |||
:tag('span') | |||
:addClass('mobile-only') | |||
:wikitext(mobile_file) | |||
:done() | :done() | ||
| Line 106: | Line 99: | ||
function addPunct(var) | function addPunct(var) | ||
if args.comma or args. | if args.comma or args.commaspc then var = var .. ',' | ||
elseif args.dot or args. | elseif args.dot or args.dotspc then var = var .. '.' | ||
end | end | ||
var = var | var = var | ||
| Line 121: | Line 114: | ||
end | end | ||
if args. | if args.commaspc or args.dotspc then b = b .. ' ' end -- space always on the very end | ||
return {a, b} | return {a, b} | ||
| Line 127: | Line 120: | ||
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 146: | Line 139: | ||
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 152: | Line 145: | ||
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.commaspc or args.dotspc) and ' ' or '' -- avoid space between ref and punctuation | ||
item_text:wikitext(ref, after) | item_text:wikitext(ref, after) | ||
end | end | ||