2734
правки
Изменения
Новая страница: «local p = {} local getLayerSize = function( data ) local width = 0 local height = #data for _, v in ipairs( data ) do width = math.max( #v, width ) end r…»
local p = {}
local getLayerSize = function( data )
local width = 0
local height = #data
for _, v in ipairs( data ) do
width = math.max( #v, width )
end
return width, height
end
p.main = function( f )
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local blockGrid = require( [[Модуль:БлокСетка]] ).grid
local keys = {}
for k, v in pairs( args ) do
if type( k ) == 'string' and #k == 1 then
keys[k] = v
end
end
local layerNames = {}
local layers = {}
local width = 0
local height = 0
local scale = args.scale or 1
for _, v in ipairs( args ) do
if v:match( '%-%-%-%-' ) then
table.insert( layerNames, mw.text.trim( string.sub( v, 5 ) ) )
else
local data = mw.text.split( mw.text.trim( v, '\n' ), '\n' )
local layerWidth, layerHeight = getLayerSize( data )
width = math.max( layerWidth, width )
height = math.max( layerHeight, height )
data.keys = keys
data.scale = scale
table.insert( layers, blockGrid( data ) )
end
end
local name = args.name:gsub( ' ', '_' )
local defaultLayer = args.default
local body = mw.html.create( 'div' ):addClass( 'layered-blueprint' ):css( {
width = width * 16 * scale .. 'px',
['min-height'] = height * 16 * scale .. 'px'
} )
for i, v in ipairs( layerNames ) do
body:wikitext(
f:callParserFunction( '#widget:radio button', {
radioClass = 'layered-blueprint-radio',
labelClass = 'layered-blueprint-tab',
name = name,
id = name .. '-layer' .. i,
label = v,
checked = v == defaultLayer or not defaultLayer and i == 1
} )
)
body:tag( 'div' ):addClass( 'layered-blueprint-layer' ):newline():wikitext( layers[i] )
end
return body
end
return p
local getLayerSize = function( data )
local width = 0
local height = #data
for _, v in ipairs( data ) do
width = math.max( #v, width )
end
return width, height
end
p.main = function( f )
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
else
f = mw.getCurrentFrame()
end
local blockGrid = require( [[Модуль:БлокСетка]] ).grid
local keys = {}
for k, v in pairs( args ) do
if type( k ) == 'string' and #k == 1 then
keys[k] = v
end
end
local layerNames = {}
local layers = {}
local width = 0
local height = 0
local scale = args.scale or 1
for _, v in ipairs( args ) do
if v:match( '%-%-%-%-' ) then
table.insert( layerNames, mw.text.trim( string.sub( v, 5 ) ) )
else
local data = mw.text.split( mw.text.trim( v, '\n' ), '\n' )
local layerWidth, layerHeight = getLayerSize( data )
width = math.max( layerWidth, width )
height = math.max( layerHeight, height )
data.keys = keys
data.scale = scale
table.insert( layers, blockGrid( data ) )
end
end
local name = args.name:gsub( ' ', '_' )
local defaultLayer = args.default
local body = mw.html.create( 'div' ):addClass( 'layered-blueprint' ):css( {
width = width * 16 * scale .. 'px',
['min-height'] = height * 16 * scale .. 'px'
} )
for i, v in ipairs( layerNames ) do
body:wikitext(
f:callParserFunction( '#widget:radio button', {
radioClass = 'layered-blueprint-radio',
labelClass = 'layered-blueprint-tab',
name = name,
id = name .. '-layer' .. i,
label = v,
checked = v == defaultLayer or not defaultLayer and i == 1
} )
)
body:tag( 'div' ):addClass( 'layered-blueprint-layer' ):newline():wikitext( layers[i] )
end
return body
end
return p