Module:AnimateSprite

From Downtime Wiki
Revision as of 05:08, 25 April 2025 by Orashgle (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Usage

Implement {{#if:{{#switch: yes

| y | yes | t | true  | on  | 1 = yes
| n | no  | f | false | off | 0 | = 
| =  
| #default = yes

}}|}}{{{{#if: |subst: }}[[{{#if: {{#pos: AnimateSprite | : }} || Template: }}AnimateSprite|{{ #ifeq: | Template | AnimateSprite | AnimateSprite }}]]{{ #if: | | }}{{ #if: | | }}{{ #if: | | }}{{ #if: | | }}{{ #if: | | }}{{ #if: | | }}{{ #if: | | }}{{ #if: | | }}}}{{#if:{{#switch: yes

| y | yes | t | true  | on  | 1 = yes
| n | no  | f | false | off | 0 | = 
| =  
| #default = yes

}}|}}{{#if: {{#pos: AnimateSprite | File: }}{{#pos: AnimateSprite | Category: }} | }}.

fr:Module:AnimateSprite uk:Модуль:AnimateSprite



local p = {}

function p.animate( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end
	
	local icons = {}
	local sprite = require( 'Module:SpriteFile' ).sprite
	local name = args.name or 'InvSprite'
	
	local function image( icon )
		return sprite({
				name = name,
				icon,
				size = args.size or 32,
				align = args.align or 'middle',
				keepcase = true
			}) or ''
	end
	
	for icon in mw.text.gsplit( args[1], '%s*;%s*' ) do
		icons[#icons+1] = '<span>' .. (#icon > 0 and image( icon ) or '<br>') .. '</span>'
	end
	
	icons[1] = icons[1]:gsub( '^<span>', '<span class="animated-active">' )
	
	return '<span class="animated">' .. table.concat( icons ) .. '</span>'
end

return p