No edit summary |
Fadyblok240 (talk | contribs) (Undo revision 1836229 by Fadyblok240 (talk)) Tag: Undo |
||
(40 intermediate revisions by 4 users not shown) | |||
Line 12: | Line 12: | ||
local style = args.style or '' |
local style = args.style or '' |
||
local tablestyle = args.tablestyle or '' |
local tablestyle = args.tablestyle or '' |
||
− | local sprite = require( 'Module:Sprite' ). |
+ | local sprite = require( 'Module:Sprite' ).sprite |
− | local ids = mw.loadData( 'Module: |
+ | local ids = mw.loadData( 'Module:Schematic/data' ).ids |
− | local titles = mw.loadData( 'Module:Schematic/ |
+ | local titles = mw.loadData( 'Module:Schematic/titles' ) |
local isTable = false |
local isTable = false |
||
if args[2] or '' ~= '' then |
if args[2] or '' ~= '' then |
||
isTable = true |
isTable = true |
||
end |
end |
||
+ | local categories = {} |
||
if size ~= 32 then |
if size ~= 32 then |
||
Line 29: | Line 30: | ||
local title = '' |
local title = '' |
||
for _, cell in ipairs( args ) do |
for _, cell in ipairs( args ) do |
||
− | + | cell = mw.text.trim( cell ) |
|
+ | if isTable and cell ~= '-' then |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
cols = cols + 1 |
cols = cols + 1 |
||
if cols > maxcols then |
if cols > maxcols then |
||
maxcols = cols |
maxcols = cols |
||
end |
end |
||
+ | end |
||
⚫ | |||
+ | if cell == '' or cell == 'air' then |
||
+ | if isTable then |
||
+ | table.insert( schematic, '|' ) |
||
+ | else |
||
+ | table.insert( schematic, '<br>' ) |
||
+ | end |
||
+ | elseif isTable and cell == '-' then |
||
⚫ | |||
⚫ | |||
⚫ | |||
local layers = {} |
local layers = {} |
||
title = {} |
title = {} |
||
for layer in mw.text.gsplit( cell, '%s*+%s*' ) do |
for layer in mw.text.gsplit( cell, '%s*+%s*' ) do |
||
− | + | local idData = ids[layer] |
|
− | if |
+ | if idData then |
− | local |
+ | local image, spriteCat = sprite{ |
− | + | data = 'Schematic/data', |
|
− | + | iddata = idData, |
|
− | + | scale = size / 16 |
|
− | + | } |
|
− | + | table.insert( layers, image ) |
|
+ | table.insert( categories, spriteCat ) |
||
⚫ | |||
− | + | ||
− | + | if titles[layer] then |
|
− | table.insert( title, 1, titles[layer] |
+ | table.insert( title, 1, titles[layer] ) |
⚫ | |||
⚫ | |||
end |
end |
||
⚫ | |||
⚫ | |||
end |
end |
||
end |
end |
||
Line 76: | Line 86: | ||
end |
end |
||
end |
end |
||
+ | |||
− | |||
− | local |
+ | local captionwidth = maxcols * ( size + 1 ) + 1 |
+ | |||
if isTable then |
if isTable then |
||
− | table.insert( schematic, 1, ' |
+ | table.insert( schematic, 1, '{|' .. 'class="schematic" style="min-width:' .. captionwidth .. 'px;' .. tablestyle .. '"' ) |
table.insert( schematic, '|}' ) |
table.insert( schematic, '|}' ) |
||
else |
else |
||
+ | if #schematic == 0 then |
||
⚫ | |||
⚫ | |||
+ | end |
||
⚫ | |||
table.insert( schematic, '</span>' ) |
table.insert( schematic, '</span>' ) |
||
end |
end |
||
Line 94: | Line 108: | ||
clear = 'none' |
clear = 'none' |
||
end |
end |
||
+ | |||
− | local captionwidth = maxcols * ( size + 1 ) + 1 |
||
if captionwidth < 182 then |
if captionwidth < 182 then |
||
captionwidth = 182 |
captionwidth = 182 |
||
end |
end |
||
+ | |||
+ | if not args.nohelp and mw.title.getCurrentTitle().prefixedText ~= 'Help:Schematic' then |
||
+ | caption = '<span style="float:right;padding-left:0.5em">' .. |
||
+ | f:expandTemplate{ |
||
+ | title = 'CommentSprite', |
||
⚫ | |||
+ | '1', |
||
+ | link = 'Help:Schematic', |
||
+ | title = 'Schematic help' |
||
+ | } |
||
+ | } .. |
||
+ | '</span>' .. caption |
||
+ | end |
||
+ | |||
out = { |
out = { |
||
− | '<div class="thumb t' .. float .. '" style="clear:' .. clear .. ';' .. style .. '">', |
+ | '<div class="thumb t' .. float .. '" style="overflow: auto; clear:' .. clear .. ';' .. style .. '">', |
− | '<div class="thumbinner" style=" |
+ | '<div class="thumbinner" style="display:inline-block;min-width:' .. captionwidth .. 'px">\n', |
table.concat( schematic, '\n' ), |
table.concat( schematic, '\n' ), |
||
− | '<div class="thumbcaption" style="' .. captionstyle .. '">' .. caption .. '</div>', |
+ | '\n<div class="thumbcaption" style="max-width:' .. captionwidth .. 'px;' .. captionstyle .. '">\n' .. caption .. '</div>', |
'</div>', |
'</div>', |
||
'</div>' |
'</div>' |
||
} |
} |
||
− | out = table.concat( out |
+ | out = table.concat( out ) |
else |
else |
||
+ | if isTable then |
||
⚫ | |||
+ | out = table.concat( schematic, '\n' ) |
||
+ | else |
||
+ | -- Inline schematic should be a single line |
||
+ | out = table.concat( schematic ) |
||
+ | end |
||
end |
end |
||
− | out = out:gsub( ' style=""', '' ):gsub( ' title="" |
+ | out = out:gsub( ' style=""', '' ):gsub( ' title=""%s*|?', '' ) |
− | return out |
+ | return out .. table.concat( categories ) |
end |
end |
||
return p |
return p |
Latest revision as of 21:38, 8 February 2021
local p = {}
function p.table( f )
local args = f.args
if args[1] == nil then
args = f:getParent().args
end
local caption = args.caption or ''
local captionstyle = args.captionstyle or ''
local clear = args.clear or ''
local float = args.float or ''
local size = tonumber( args.size ) or 32
local style = args.style or ''
local tablestyle = args.tablestyle or ''
local sprite = require( 'Module:Sprite' ).sprite
local ids = mw.loadData( 'Module:Schematic/data' ).ids
local titles = mw.loadData( 'Module:Schematic/titles' )
local isTable = false
if args[2] or '' ~= '' then
isTable = true
end
local categories = {}
if size ~= 32 then
tablestyle = 'font-size:' .. size .. 'px;' .. tablestyle
end
local cols = 0
local maxcols = 0
local schematic = {}
local title = ''
for _, cell in ipairs( args ) do
cell = mw.text.trim( cell )
if isTable and cell ~= '-' then
cols = cols + 1
if cols > maxcols then
maxcols = cols
end
end
if cell == '' or cell == 'air' then
if isTable then
table.insert( schematic, '|' )
else
table.insert( schematic, '<br>' )
end
elseif isTable and cell == '-' then
cols = 0
table.insert( schematic, '|-' )
else
local layers = {}
title = {}
for layer in mw.text.gsplit( cell, '%s*+%s*' ) do
local idData = ids[layer]
if idData then
local image, spriteCat = sprite{
data = 'Schematic/data',
iddata = idData,
scale = size / 16
}
table.insert( layers, image )
table.insert( categories, spriteCat )
if titles[layer] then
table.insert( title, 1, titles[layer] )
end
else
table.insert( layers, '<span class="text">' .. layer .. '</span>' )
end
end
if args.text then
table.insert( layers, '<span class="text">' .. args.text .. '</span>' )
end
title = table.concat( title, ' over ' )
layers = table.concat( layers, '' )
if isTable then
if layers ~= '' then
layers = '| title="' .. title .. '" | <div>' .. layers .. '</div>'
else
layers = '|'
end
end
table.insert( schematic, layers )
end
end
local captionwidth = maxcols * ( size + 1 ) + 1
if isTable then
table.insert( schematic, 1, '{|' .. 'class="schematic" style="min-width:' .. captionwidth .. 'px;' .. tablestyle .. '"' )
table.insert( schematic, '|}' )
else
if #schematic == 0 then
table.insert( schematic, '<br>' )
end
table.insert( schematic, 1, '<span class="schematic" style="' .. tablestyle .. '" title="' .. title .. '">' )
table.insert( schematic, '</span>' )
end
local out
if caption ~= '' or float ~= '' then
if float == '' then
float = 'right'
end
if clear == '' then
clear = 'none'
end
if captionwidth < 182 then
captionwidth = 182
end
if not args.nohelp and mw.title.getCurrentTitle().prefixedText ~= 'Help:Schematic' then
caption = '<span style="float:right;padding-left:0.5em">' ..
f:expandTemplate{
title = 'CommentSprite',
args = {
'1',
link = 'Help:Schematic',
title = 'Schematic help'
}
} ..
'</span>' .. caption
end
out = {
'<div class="thumb t' .. float .. '" style="overflow: auto; clear:' .. clear .. ';' .. style .. '">',
'<div class="thumbinner" style="display:inline-block;min-width:' .. captionwidth .. 'px">\n',
table.concat( schematic, '\n' ),
'\n<div class="thumbcaption" style="max-width:' .. captionwidth .. 'px;' .. captionstyle .. '">\n' .. caption .. '</div>',
'</div>',
'</div>'
}
out = table.concat( out )
else
if isTable then
out = table.concat( schematic, '\n' )
else
-- Inline schematic should be a single line
out = table.concat( schematic )
end
end
out = out:gsub( ' style=""', '' ):gsub( ' title=""%s*|?', '' )
return out .. table.concat( categories )
end
return p