Module:Inventory slot: Difference between revisions

m 1 revision imported
No edit summary
 
(20 intermediate revisions by the same user not shown)
Line 2: Line 2:


local i18n = {
local i18n = {
filename = 'Invicon $1',
modLink = '$1:$2',
legacyFilename = 'Grid $1.png',
modLink = 'Mods/$1/$2',
moduleAliases = [[Module:Inventory slot/Aliases]],
moduleAliases = [[Module:Inventory slot/Aliases]],
moduleRandom = [[Module:Random]],
moduleRandom = [[Module:Random]],
Line 100: Line 98:
local category
local category
local title = frame.title or mw.text.trim( args.title or '' )
local title = frame.title or mw.text.trim( args.title or '' )
local mod = frame.mod
local name = frame.name or ''
local num = frame.num
local num = frame.num
local description = frame.text
local description = frame.text
local img
local mod = frame.mod or 'Minecraft'
if mod then
local name = frame.name
img = i18n.legacyFilename:gsub( '%$1', name .. ' (' .. mod .. ')' )
elseif name:match( '%.gif$' ) or name:match( '%.png$' ) then
 
img = i18n.filename:gsub( '%$1', name )
if frame.name:match( '%.gif$' ) and frame.name:match( '%.png$' ) then
-- Remove file extension from name
name = frame.name
name = name:sub( 0, -5 )
mod = ''
else
end
-- Fall back to an individual image if the sprite is lacking
 
img = i18n.filename:gsub( '%$1', name .. '.png' )
local minecraft = mod == "Minecraft" or mod == "minecraft"
 
local img = frame.img
if not img then
if name:match( '%.gif$' ) or name:match( '%.png$' ) then
img = name
-- Remove file extension from name
name = name:sub( 0, -5 )
elseif minecraft then
img = 'Invicon ' .. name .. '.png'
elseif mod then
img = mod .. ' ' .. name .. '.png'
else
img = name
end
end
end


Line 123: Line 133:
local link = args.link or ''
local link = args.link or ''
if link == '' then
if link == '' then
if mod then
link = i18n.modLink:gsub( '%$1', mod ):gsub( '%$2', name )
link = i18n.modLink:gsub( '%$1', mod ):gsub( '%$2', name )
else
link = name:gsub( '^' .. i18n.prefixes.damaged .. ' ', '' )
for _, suffix in pairs( i18n.suffixes ) do
link = link:gsub( ' ' .. suffix .. '$', '' )
end
end
elseif link:lower() == 'none' then
elseif link:lower() == 'none' then
link = nil
link = nil
Line 181: Line 184:
altText = altText:gsub( '&[0-9a-jl-qs-wr]', '' )
altText = altText:gsub( '&[0-9a-jl-qs-wr]', '' )
end
end
item:addClass( 'invslot-item-image' )
item:addClass( 'invslot-item-image' )
:wikitext( '[[File:', img, '|32x32px|link=', link or '', '|alt=', altText, '|', escapedTitle, ']]' )
:wikitext( '[[File:', img, '|32x32px|link=', link or '', '|alt=', altText, '|', escapedTitle, ']]' )
if num and num > 1 and num < 1000 then
if num and num > 1 and num < 1000 then
if link then
if link then
Line 436: Line 441:
end
end
return string.format(
return string.format(
'[%s]%s:%s,%s[%s]',
'[%s]%s,%s[%s]',
frame.title or '',
frame.title or '',
frame.mod or 'Minecraft',
frame.name,
frame.name,
frame.num or '',
frame.num or '',