Jump to content
Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
If you make an edit, a temporary account will be created for you.

Module:Item: Difference between revisions

From The Petit Planet Wiki
ReisuDesign (talk | contribs)
Created page with "local p = {} local lib = require('Module:Feature') function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { parentFirst = true, removeBlanks = false }) return p._main(args) end function p._main(args) local item = lib.nilIfEmpty(args[1]) or lib.nilIfEmpty(args.name) or 'Unknown' local size = lib.nilIfEmpty(args[2]) or lib.nilIfEmpty(args.size) or 30 local count = lib.nilIfEmpty(args.count) or lib.nilIfEmpty(args.x) or nil local n..."
 
Added automatic invert for icons listed in Module:Item/Invert
 
(4 intermediate revisions by 2 users 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 type = lib.nilIfEmpty(args['type']) or 'Item'
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 blueprint = tostring(args.blueprint) == '1'
local invert = lib.nilIfEmpty(args.invert)
local newline = tostring(args.newline) == '1'
local newline = tostring(args.newline) == '1'
local notext = tostring(args.notext) == '1'
local noText = tostring(args.no_text or args.notext) == '1'
local white = tostring(args.white) == '1'
local white = tostring(args.white) == '1'


local prefix = args.prefix and (args.prefix .. ' ') or (type .. ' ')
local prefix = ''
local suffix = args.suffix and (' ' .. args.suffix) or ''
local suffix = ' Icon'
if (type ~= 'Neighbor' and item == 'Unknown') then
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 filename = 'File:' .. prefix .. item .. suffix .. '.png'
local fileName = 'File:' .. prefix .. item .. suffix .. '.png'
local class = invertClass and ('|class=' .. invertClass) or ''
local file = '[[' .. filename .. '|' .. size .. 'x' .. size .. 'px|alt=' .. item .. '|link=' .. link .. ']]'
local file = '[[' .. fileName .. '|' .. size .. 'x' .. size .. 'px|alt=' .. item .. '|link=' .. link .. class .. ']]'
local mobile_file = '[[' .. filename .. '|30x30px|alt=' .. item .. '|link=' .. link .. ']]'


local icon = nil
local icon = nil
Line 48: Line 64:
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 58: Line 70:
end
end


local outerClass = lib.ternary(type:lower() == 'item', 'item', 'item ' .. type:lower())
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 64: Line 76:
:addClass('item-image')
:addClass('item-image')
:tag('span')
:tag('span')
:addClass('hidden')
:css({
:css({
width    = size .. 'px',
width    = size .. 'px',
Line 71: Line 82:
:attr('data-size', size)
:attr('data-size', size)
:wikitext(file)
:wikitext(file)
:done()
:tag('span')
:addClass('mobile-only')
:wikitext(mobile_file)
:done()
:done()


Line 99: Line 106:
function addPunct(var)
function addPunct(var)
if args.comma or args.commaspc then var = var .. ','
if args.comma or args.comma_spc then var = var .. ','
elseif args.dot or args.dotspc then var = var .. '.'
elseif args.dot or args.dot_spc then var = var .. '.'
end
end
var = var
var = var
Line 114: Line 121:
end
end
if args.commaspc or args.dotspc then b = b .. ' ' end -- space always on the very end
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 120: Line 127:


local item_text = result:tag('span'):addClass('item-text')
local item_text = result:tag('span'):addClass('item-text')
if (not notext) then
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 139: 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((notext and '' or ' ') .. '×' .. count)
item_text:wikitext((noText and '' or ' ') .. '×' .. count)
end
end
Line 145: 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(((notext and not count) and '' or ' '),'(', note, ')', after)
item_text:tag('small'):wikitext(((noText and not count) and '' or ' '),'(', note, ')', after)
end
end
if (ref) then
if (ref) then
local after = (args.commaspc or args.dotspc) and ' ' or '' -- avoid space between ref and punctuation  
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