Module:SpriteFile: Difference between revisions

Reinstate support for custom Parallel items
No edit summary
Tag: Reverted
(Reinstate support for custom Parallel items)
 
(46 intermediate revisions by 2 users not shown)
Line 39: Line 39:
-- end
-- end
-- Edited to turn regular links into vanilla: prefixes and to turn parallel: prefixes into regular links
-- Edited to turn regular links into links with ' (Vanilla)' at the end and to turn parallel: prefixes into regular links
local link = ( args.link or '' )
local link = ( args.link or '' )
if mw.ustring.lower( link ) == 'none' then
if mw.ustring.lower( link ) == 'none' then
Line 45: Line 45:
elseif link ~= '' then
elseif link ~= '' then
local linkPrefix = ( not link:find( '//' ) and args.linkprefix ) or ''
local linkPrefix = ( not link:find( '//' ) and args.linkprefix ) or ''
if linkprefix == 'parallel:' then  -- <- these are the added bits here
if linkPrefix == "parallel:" then  -- <- these are the added bits here
linkprefix = ''   
linkprefix = ''   
end
if string.find(link, "[Pp]arallel:") then
link = mw.ustring.gsub( link, "[Pp]arallel:", "" )
else
if mw.title.new(link).exists == false then
linkPrefix = 'mcwiki:'
end
-- link = link .. ' (Vanilla)'
end
end
link = linkPrefix .. link
link = linkPrefix .. link
end
end
local scale = args.scale or default.scale
local scale = args.scale or default.scale
Line 64: Line 72:
end
end
local name = args.name
local name = args.name or ''
if name == 'InvSprite' then
if name == 'InvSprite' then
name = 'Invicon'
name = 'Invicon'
end
end
-- local file = name .. ' ' .. id .. '.png'
local extension = name == 'Dungeons2AchievementSprite' and '.jpg' or name == '' and '' or '.png'
local file = idPrefix .. name .. ' ' .. id .. '.png'
-- local file = name .. ' ' .. id .. extension
local altText = file .. ': Sprite image for ' .. id .. ' in Minecraft'
local file = idPrefix .. name .. ' ' .. id .. extension
if link ~= '' then
local altText = ''
altText = altText .. ' linking to ' .. link
if link == '' then
altText = file .. ': Sprite image for ' .. id .. ' in Minecraft'
end
end
if id == '' then
if id == '' then
Line 79: Line 88:
end
end
local sprite = mw.html.create( 'span' ):addClass( 'sprite-file' )
local sprite = mw.html.create( 'span' ):addClass( 'sprite-file' )
if args.title ~= nil then  -- <------ this part is new
local img = '[[File:' .. file .. '|' .. size .. '|link=' .. link .. '|alt=' .. altText .. '|class=pixel-image|' .. ( args.title or '' ) .. ']]'
if string.find(args.title, "parallel:") then
args.title = mw.ustring.gsub( args.title, "[Pp]arallel:", "" )
else
args.title = args.title .. ' (Vanilla)'
end
local img = '[[File:' .. file .. '|' .. size .. '|link=' .. link .. '|alt=' .. altText .. '|class=pixel-image|' .. ( args.title ) .. ']]'
else
local img = '[[File:' .. file .. '|' .. size .. '|link=' .. link .. '|alt=' .. altText .. '|class=pixel-image|' .. ( '' ) .. ']]'
end
sprite:node( img )
sprite:node( img )
Line 113: Line 113:
if link:find( '//' ) then
if link:find( '//' ) then
spriteText = '[' .. link .. ' ' .. tostring( spriteText ) .. ']'
spriteText = '[' .. link .. ' ' .. tostring( spriteText ) .. ']'
-- else
-- spriteText = '[[' .. link .. '|' .. tostring( spriteText ) .. ']]'
-- end
else
else
if string.find(link, "parallel:") then   -- <---- this sub-if/else statement is new
-- if string.find(link, " (Vanilla)") then -- <-- this inner if/else statement is added
-- have to do this weird inner tostring here bc something about converting the spriteText table causes the text indentation to be correct
-- spriteText = '[[' .. link .. '|' .. tostring( spriteText ):gsub(" (Vanilla)", "") .. ']]'
spriteText = '[[' .. mw.ustring.gsub( link, "[Pp]arallel:", "" ):gsub("^%l", string.upper) .. '|' .. mw.ustring.gsub( tostring(spriteText), "[Pp]arallel:", "" ):gsub("^%l", string.upper) .. ']]'  
if string.find(tostring(spriteText), "[Pp]arallel:") then
text = tostring(spriteText):gsub(":%l", string.upper)
text = text:gsub("[Pp]arallel:", "")
spriteText = '[[' .. link .. '|' .. text .. ']]'
else
else
spriteText = '[[' .. link .. ' (Vanilla)' .. '|' .. tostring( spriteText ) .. ']]'
spriteText = '[[' .. link .. '|' .. tostring( spriteText ) .. ']]'
end
end
end
end
end
end