Jump to content

Module:AnimateSprite: Difference between revisions

From Joyful's Civilization
w>Magiczocker
m Some optimizations to match the spritename capitlization of module sprite
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 8: Line 8:
local icons = {}
local icons = {}
local sprite = require( 'Module:Sprite' ).sprite
local sprite = require( 'Module:SpriteFile' ).sprite
local sheet = args.sheet or 'InvSprite'
local name = args.name or 'InvSprite'
local ids = mw.loadData( 'Module:' .. sheet ).ids
local function image( icon )
local function image( icon )
local idData = ids[icon] or ids[mw.ustring.lower( icon ):gsub( '[%s%+]', '-' )]
args.name = name
return idData and sprite({
args[1] = icon
iddata = idData,
args.size = args.size or 32
data = sheet
args.align = args.align or 'middle'
}) or ''
args.keepcase = true
return sprite(args) or ''
end
end

Latest revision as of 20:16, 16 October 2025

This is the documentation page. It will be transcluded into the main module page. See Template:Documentation for more information

Usage

Implement {{AnimateSprite}}.


fr:Module: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 )
		args.name = name
		args[1] = icon
		args.size = args.size or 32
		args.align = args.align or 'middle'
		args.keepcase = true
		return sprite(args) 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