Module:Sandbox/Sprite grid: Difference between revisions
From Downtime Wiki
MC>Cowbird mNo edit summary |
m 1 revision imported |
||
(No difference)
|
Latest revision as of 05:08, 25 April 2025
This module implements {{#if:{{#switch: yes
| y | yes | t | true | on | 1 = yes | n | no | f | false | off | 0 | = | = | #default = yes
}}|}}{{{{#if: |subst: }}[[{{#if: {{#pos: Sandbox/Sprite grid | : }} || Template: }}Sandbox/Sprite grid|{{ #ifeq: | Template | Sandbox/Sprite grid | Sandbox/Sprite grid }}]]{{ #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: Sandbox/Sprite grid | File: }}{{#pos: Sandbox/Sprite grid | Category: }} | }}.
Dependencies
de:Modul:BlockGrid es:Módulo:Sprite grid fr:Module:GrilleSprite pt:Módulo:Sprite grid ru:Модуль:БлокСетка
local p = {}
local text = require( [[Module:Text]] )
local sprite = require( [[Module:SpriteFile]] )
function p.grid( f )
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
end
local rows = {}
local scale = args.scale
local spacing = args.scale
local size = 16 * ( scale or 1 )
local categories = {}
local keys = args.keys or args
local baseSheet = args.sheet or 'BlockSprite'
-- local spacing = 0
for k, v in ipairs( args ) do
local row = {}
-- spacing = tonumber(args.spacing)
for v2 in text.gsplit( v:gsub( '^%s-\n+', '' ):gsub( '\n+%s-$', '' ), '' ) do
local spriteName = keys[v2]
if text.trim( v2 ) == '' or spriteName == 'air' then
row[#row + 1] = ' style="width:' .. size .. 'px;height:' .. size .. 'px" | '
else
local sheet = baseSheet
local css = ""
local link = nil
if spriteName then
-- Custom link
local linkPart = text.split(spriteName, '?', true)
spriteName = linkPart[1]
link = linkPart[2] -- Might be nil
-- Rotation
local spritePart = text.split( spriteName, '-rot' )
spriteName = spritePart[1]
if spritePart[2] then
css = css .. 'transform:rotate(' .. spritePart[2] .. 'deg)'
end
-- Alternate sheet
if spriteName:find(':') then
local sheetSplit = text.split( spriteName, ':')
sheet = sheetSplit[1]
spriteName = sheetSplit[2]
end
end
local includeLink = true
if spriteName and spriteName:sub(1, 1) == '+' then
includeLink = false
spriteName = spriteName:sub(2)
end
local image, spriteCat
local spriteData = {
name = sheet,
spriteName,
link = link,
scale = scale,
notext = 1,
nocat = args.nocat,
css = css
}
if includeLink then
image, spriteCat = sprite.link(spriteData)
else
image, spriteCat = sprite.sprite(spriteData)
end
row[#row + 1] = image
categories[#categories + 1] = spriteCat
end
end
rows[k] = table.concat( row, ' || ' )
end
return '{| cellspacing="' .. spacing .. '" cellpadding="0" style="margin:0; line-height:0"\n| ' ..
table.concat( rows, '\n|-\n| ' ) ..
'\n|}' .. table.concat( categories )
end
return p