Module:Animate

-- Attribution: Minecraft Wiki -- https://minecraft.fandom.com/wiki/Module:Animate

local loader = require('Module:Loader') local getArgs = require('Module:Arguments').getArgs local string, table, yesno, cache = loader.require('String', 'Table', 'Yesno', 'Cache')

local itemVariantsCache = cache.itemVariantsCache

local p = {}

- -- Template: Animate -- -- Creates a cycling animation. - local function appendPNG(image) if not(image:match('%.%a%a%a?%a?')) then image = image..".png" end image = image:gsub('^File:','') return image end

function p.animate(frame) local args = getArgs(frame) local files = args[1] or '' local size = args[2] or '' local link = args.link or args[3] or '' local class = args.class or '' local fixed = yesno(args.fixed, true) local caption = args.caption if files:match("UNIQ%-%-gallery") then return files end if size ~= '' then size = '|' .. size end if link ~= '' then link = '|link=' .. (link ~= 'none' and link or '') end if class ~= '' then class = '|class=' .. class end local images = {} local firstimg files = table.concat(table.map(string.split(files, '%s*;%s*'), function(s) local trimmed = s:gsub('^%?', ):gsub('^%*', ) local t = itemVariantsCache:get(trimmed) or {s} return table.concat(t,';') end),';') for image in string.gsplit(files, '%s*;%s*') do		if image == '' then table.insert(images, string.wrapTag(' ', 'span')) else table.insert(images, string.wrapTag(string.makeLink{ "File:", appendPNG(image), size, link, class, '|'..appendPNG(image) }, 'span')) end if not firstimg then firstimg = string.wrapHtml(string.makeLink{ "File:", appendPNG(image), size, link, class, '|'..appendPNG(image) }, 'span', { class = 'animated-fakeimage' }) end end local ret if files:match( ';' ) then images[1] = images[1]:gsub('^ ', ' ') ret = string.wrapHtml( images, ' ', { class = 'animated' }) if fixed then ret = firstimg .. ret -- firstimg is a ghost image, it expands the box to a fixed size when there is momentarily no image end ret = string.wrapHtml( ret, 'div', { class = 'animated-wrapper' }) else ret = table.concat(images) end if caption then ret = ret .. string.wrapHtml(caption, 'div', { class = 'pi-item-spacing pi-caption' }) end return ret end

return p