Module:Animate

local table = require('Module:Table') local string = require('Module:String') local getArgs = require('Module:Arguments').getArgs local itemVariants = mw.loadData('Module:Item/Variants')

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 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 '' if size ~= '' then size = '|' .. size end

if link ~= '' then link = '|link=' .. link end if class ~= '' then class = '|class=' .. class end local images = {} files = table.concat(table.map(string.split(files, '%s*;%s*'), function(s) return table.concat(itemVariants[s] or {s},';') 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 }, 'span')) end end images[1] = images[1]:gsub('^ ', ' ') return string.wrapHtml(images, ' ', {class="animated"}) end

function p._infoboxAI(img, t, inst) local inst = inst or error('No inst object passed to _infoboxAI.') if img:match( ';' ) or not not itemVariants[img] then local aImg = string.wrapTag(p.animate({ img, class="pi-image-thumbnail" }), 'center') inst = inst:tag('data') :attr({			name=t.name,		}) :tag('default') :wikitext(aImg) :done else inst = inst:tag('image') :attr({			source=t.source or "image",			name=t.name,		}) :tag('default') :wikitext('') :done end return inst end

return p