Moduł:Sprite: Różnice pomiędzy wersjami
Przejdź do nawigacji
Przejdź do wyszukiwania
| [wersja nieprzejrzana] | [wersja nieprzejrzana] |
Przetłumaczenie kategorii |
Część dalsza eksperymentowania. Przywrócenie starego kodu i sprawdzenie czy po zaaplikowaniu poprzednich zmian to coś da |
||
| Linia 4: | Linia 4: | ||
if f == mw.getCurrentFrame() then | if f == mw.getCurrentFrame() then | ||
args = require( 'Moduł:ProcessArgs' ).merge( true ) | args = require( 'Moduł:ProcessArgs' ).merge( true ) | ||
end | end | ||
| Linia 14: | Linia 12: | ||
size = 16, | size = 16, | ||
pos = 1, | pos = 1, | ||
align = 'text-top' | link = '', | ||
align = 'text-top', | |||
class = '', | |||
text = '', | |||
title = '' | |||
} | } | ||
local defaultStyle = default | local defaultStyle = mw.clone( default ) | ||
if args.settings then | if args.settings then | ||
local settings = mw.loadData( 'Moduł:' .. args.settings ) | local settings = mw.loadData( 'Moduł:' .. args.settings ) | ||
for k, v in pairs( settings ) do | for k, v in pairs( settings ) do | ||
default[k] = v | default[k] = v | ||
if settings.stylesheet then | |||
defaultStyle[k] = v | |||
end | |||
end | end | ||
end | end | ||
local | local name = args.name or default.name | ||
local scale = args.scale or default.scale | |||
local autoScale = args.autoscale or default.autoscale | |||
local sheetWidth = args.sheetsize or default.sheetsize | |||
local size = args.size or default.size | |||
local pos = math.abs( args.pos or default.pos ) - 1 | |||
local link = args.link or default.link | |||
local align = args.align or default.align | |||
local class = args.class or default.class | |||
local text = args.text or default.text | |||
local title = args.title or default.title | |||
local css = args.css or default.css | |||
local className = args.classname or default.classname | |||
local tiles = sheetWidth / size | |||
local left = pos % tiles * size | |||
local top = math.floor( pos / tiles ) * size | |||
local styles = {} | local styles = {} | ||
if args.stylesheet or default.stylesheet then | |||
if | class = ( className or mw.ustring.lower( name:gsub( ' ', '-' ) ) .. '-sprite ' ) .. class | ||
else | else | ||
table.insert( styles, 'background-image:{{FileUrl|' .. ( | table.insert( styles, 'background-image:{{FileUrl|' .. ( args.image or default.image or name .. 'Sprite.png' ) .. '}}' ) | ||
end | end | ||
if left > 0 or top > 0 then | if left > 0 or top > 0 then | ||
table.insert( styles, 'background-position:-' .. left * scale .. 'px -' .. top * scale .. 'px' ) | table.insert( styles, 'background-position:-' .. left * scale .. 'px -' .. top * scale .. 'px' ) | ||
| Linia 72: | Linia 61: | ||
end | end | ||
if size ~= defaultStyle.size or ( not autoScale and scale ~= defaultStyle.scale ) then | if size ~= defaultStyle.size or ( not autoScale and scale ~= defaultStyle.scale ) then | ||
table.insert( styles, 'height:' .. size * scale .. 'px | table.insert( styles, 'height:' .. size * scale .. 'px;width:' .. size * scale .. 'px' ) | ||
end | end | ||
if align ~= defaultStyle.align then | if align ~= defaultStyle.align then | ||
table.insert( styles, 'vertical-align:' .. align ) | table.insert( styles, 'vertical-align:' .. align ) | ||
end | end | ||
table.insert( styles, | if css then | ||
table.insert( styles, css ) | |||
end | |||
if title ~= '' then | |||
title = ' title="' .. title .. '"' | |||
end | end | ||
local | local sprite = table.concat( { | ||
'<span', | |||
'class="sprite ' .. class .. '"', | |||
'style="' .. table.concat( styles, ';' ) .. '"', | |||
title, | |||
'><br></span>' | |||
}, ' ' ) | |||
sprite = sprite:gsub( '%s+([">])', '%1' ) | |||
if | if text ~= '' then | ||
text = '<span class="sprite-text"' .. title .. '>' .. text .. '</span>' | |||
end | end | ||
local | local content = '<span class="nowrap">' .. sprite .. text .. '</span>' | ||
if link ~= '' and mw.ustring.lower( link ) ~= 'none' then | if link ~= '' and mw.ustring.lower( link ) ~= 'none' then | ||
if link:find( '//' ) then | if link:find( '//' ) then | ||
return '[' .. link .. ' ' .. | -- External link | ||
return '[' .. link .. ' ' .. content .. ']' | |||
else | |||
-- Internal link | |||
local linkPrefix = args.linkprefix or default.linkprefix or '' | |||
return '[[' .. linkPrefix .. link .. '|' .. content .. ']]' | |||
end | end | ||
else | |||
return content | |||
return | |||
end | end | ||
end | end | ||
| Linia 124: | Linia 107: | ||
end | end | ||
local | local category = '' | ||
if tonumber( args[1] ) then | |||
args.pos = args[1] | |||
else | |||
local default = {} | local default = {} | ||
if args.settings then | if args.settings then | ||
| Linia 133: | Linia 117: | ||
local name = args.name or default.name | local name = args.name or default.name | ||
local ids = mw.loadData( 'Moduł:' .. ( args.ids or default.ids or | local ids = mw.loadData( 'Moduł:' .. ( args.ids or default.ids or 'Sprite/' .. name ) ) | ||
local id = mw.text.trim( args[1] or '' ) | |||
local id = mw.text.trim | local pos = ids[id] or ids[mw.ustring.lower( id ):gsub( '[%s%+]', '-' )] | ||
if not pos and not mw.title.getCurrentTitle().isSubpage then | |||
category = '[[Category:Strony z brakującymi spritami]]' | |||
end | end | ||
args.pos = pos | |||
end | end | ||
return p.base( args ) | return p.base( args ) .. category | ||
end | end | ||
| Linia 179: | Linia 149: | ||
function p.doc( f ) | function p.doc( f ) | ||
local | local settings = mw.loadData( 'Moduł:' .. f.args[1] ) | ||
local idTable = mw.title.new( 'Moduł:' .. ( settings.ids or 'Sprite/' .. settings.name ) ):getContent() | |||
idTable = idTable:gsub( '(\n%s*%-%-%s*.-%s*%-%-%s*\n)', '%1,' ):gsub( '^return {', '' ):gsub( '}$', '' ) | |||
local | |||
local | local html = {} | ||
local ids = {} | |||
local posKeys = {} | |||
local section = '' | |||
for line in mw.text.gsplit( idTable, ',' ) do | |||
line = mw.text.trim( line ) | |||
id = line:match( '^%[[\'"](.+)[\'"]%]' ) or line:match( '^%w+' ) or '' | |||
pos = line:match( '=%s*(%d+)%s*,?$' ) or '' | |||
section = line:match( '^%-%-%s*(.+)%s*%-%-$' ) or section | |||
if id ~= '' and pos ~= '' then | |||
if | if ids[pos] then | ||
if type( ids[pos].id ) == 'table' then | |||
table.insert( ids[pos].id, id ) | |||
else | |||
ids[pos].id = { ids[pos].id, id } | |||
end | |||
else | |||
ids[pos] = { id = id, section = section } | |||
table.insert( posKeys, pos ) | |||
end | end | ||
end | end | ||
end | |||
local list = {} | |||
local listHead = '<ul class="spritedoc-multicolumn">' | |||
local listFoot = '</ul>' | |||
local lastSection = '' | |||
for i, pos in ipairs( posKeys ) do | |||
local id = ids[pos].id | |||
local newSection = mw.text.trim( ids[pos].section ) | |||
if newSection ~= lastSection or i == 1 then | |||
if newSection ~= lastSection then | |||
if lastSection ~= '' then | |||
table.insert( list, listFoot ) | |||
end | |||
table.insert( list, '\n===' .. newSection .. '===\n' ) | |||
lastSection = newSection | |||
end | |||
table.insert( list, listHead ) | |||
end | end | ||
if | table.insert( list, '<li><table><tr><td data-pos="' .. pos .. '">' ) | ||
if type( id ) == 'table' then | |||
for i, id2 in ipairs( id ) do | |||
table.insert( | if i == 1 then | ||
table.insert( list, p.sprite{ id2, settings = f.args[1] } .. '</td><td><div class="sprite-id"><code>' .. id2 .. '</code></div>' ) | |||
else | |||
table.insert( list, '<div class="sprite-id"><code>' .. id2 .. '</code></div>' ) | |||
end | |||
end | end | ||
else | |||
table.insert( list, p.sprite{ id, settings = f.args[1] } .. '</td><td><div class="sprite-id"><code>' .. id .. '</code></div>' ) | |||
end | end | ||
table.insert( list, '</td></tr></table></li>' ) | |||
if i == #posKeys then | |||
table.insert( list, listFoot ) | |||
end | |||
end | end | ||
local | local out = table.concat( list ) | ||
if not f.args.refresh then | |||
out = f:preprocess( '{{#widget:stylesheet|page=Sprite doc}}' ) .. '<div id="sprite-doc" data-settings="' .. f.args[1] .. '">' .. out .. '</div>' | |||
end | end | ||
return out | |||
end | end | ||
return p | return p | ||
Wersja z 02:01, 26 lut 2016
W tym module nie ma dokumentacji. Jeśli wiesz jak używać tego modułu, proszę, podaj odpowiednie informacje.
local p = {}
function p.base( f )
local args = f
if f == mw.getCurrentFrame() then
args = require( 'Moduł:ProcessArgs' ).merge( true )
end
-- Default settings
local default = {
scale = 1,
sheetsize = 256,
size = 16,
pos = 1,
link = '',
align = 'text-top',
class = '',
text = '',
title = ''
}
local defaultStyle = mw.clone( default )
if args.settings then
local settings = mw.loadData( 'Moduł:' .. args.settings )
for k, v in pairs( settings ) do
default[k] = v
if settings.stylesheet then
defaultStyle[k] = v
end
end
end
local name = args.name or default.name
local scale = args.scale or default.scale
local autoScale = args.autoscale or default.autoscale
local sheetWidth = args.sheetsize or default.sheetsize
local size = args.size or default.size
local pos = math.abs( args.pos or default.pos ) - 1
local link = args.link or default.link
local align = args.align or default.align
local class = args.class or default.class
local text = args.text or default.text
local title = args.title or default.title
local css = args.css or default.css
local className = args.classname or default.classname
local tiles = sheetWidth / size
local left = pos % tiles * size
local top = math.floor( pos / tiles ) * size
local styles = {}
if args.stylesheet or default.stylesheet then
class = ( className or mw.ustring.lower( name:gsub( ' ', '-' ) ) .. '-sprite ' ) .. class
else
table.insert( styles, 'background-image:{{FileUrl|' .. ( args.image or default.image or name .. 'Sprite.png' ) .. '}}' )
end
if left > 0 or top > 0 then
table.insert( styles, 'background-position:-' .. left * scale .. 'px -' .. top * scale .. 'px' )
end
if not autoScale and scale ~= defaultStyle.scale then
table.insert( styles, 'background-size:' .. sheetWidth * scale .. 'px auto' )
end
if size ~= defaultStyle.size or ( not autoScale and scale ~= defaultStyle.scale ) then
table.insert( styles, 'height:' .. size * scale .. 'px;width:' .. size * scale .. 'px' )
end
if align ~= defaultStyle.align then
table.insert( styles, 'vertical-align:' .. align )
end
if css then
table.insert( styles, css )
end
if title ~= '' then
title = ' title="' .. title .. '"'
end
local sprite = table.concat( {
'<span',
'class="sprite ' .. class .. '"',
'style="' .. table.concat( styles, ';' ) .. '"',
title,
'><br></span>'
}, ' ' )
sprite = sprite:gsub( '%s+([">])', '%1' )
if text ~= '' then
text = '<span class="sprite-text"' .. title .. '>' .. text .. '</span>'
end
local content = '<span class="nowrap">' .. sprite .. text .. '</span>'
if link ~= '' and mw.ustring.lower( link ) ~= 'none' then
if link:find( '//' ) then
-- External link
return '[' .. link .. ' ' .. content .. ']'
else
-- Internal link
local linkPrefix = args.linkprefix or default.linkprefix or ''
return '[[' .. linkPrefix .. link .. '|' .. content .. ']]'
end
else
return content
end
end
function p.sprite( f )
local args = f
if f == mw.getCurrentFrame() then
args = require( 'Moduł:ProcessArgs' ).merge( true )
end
local category = ''
if tonumber( args[1] ) then
args.pos = args[1]
else
local default = {}
if args.settings then
default = mw.loadData( 'Moduł:' .. args.settings )
end
local name = args.name or default.name
local ids = mw.loadData( 'Moduł:' .. ( args.ids or default.ids or 'Sprite/' .. name ) )
local id = mw.text.trim( args[1] or '' )
local pos = ids[id] or ids[mw.ustring.lower( id ):gsub( '[%s%+]', '-' )]
if not pos and not mw.title.getCurrentTitle().isSubpage then
category = '[[Category:Strony z brakującymi spritami]]'
end
args.pos = pos
end
return p.base( args ) .. category
end
function p.link( f )
local args = f
if f == mw.getCurrentFrame() then
args = require( 'Moduł:ProcessArgs' ).merge( true )
end
local link = args[1]
if args[1] and not args.id then
link = args[1]:match( '^(.-)%+' ) or args[1]
end
local text = args.text or args[2] or link
args[1] = args.id or args[1]
args.link = args.link or link
args.text = text
return p.sprite( args )
end
function p.doc( f )
local settings = mw.loadData( 'Moduł:' .. f.args[1] )
local idTable = mw.title.new( 'Moduł:' .. ( settings.ids or 'Sprite/' .. settings.name ) ):getContent()
idTable = idTable:gsub( '(\n%s*%-%-%s*.-%s*%-%-%s*\n)', '%1,' ):gsub( '^return {', '' ):gsub( '}$', '' )
local html = {}
local ids = {}
local posKeys = {}
local section = ''
for line in mw.text.gsplit( idTable, ',' ) do
line = mw.text.trim( line )
id = line:match( '^%[[\'"](.+)[\'"]%]' ) or line:match( '^%w+' ) or ''
pos = line:match( '=%s*(%d+)%s*,?$' ) or ''
section = line:match( '^%-%-%s*(.+)%s*%-%-$' ) or section
if id ~= '' and pos ~= '' then
if ids[pos] then
if type( ids[pos].id ) == 'table' then
table.insert( ids[pos].id, id )
else
ids[pos].id = { ids[pos].id, id }
end
else
ids[pos] = { id = id, section = section }
table.insert( posKeys, pos )
end
end
end
local list = {}
local listHead = '<ul class="spritedoc-multicolumn">'
local listFoot = '</ul>'
local lastSection = ''
for i, pos in ipairs( posKeys ) do
local id = ids[pos].id
local newSection = mw.text.trim( ids[pos].section )
if newSection ~= lastSection or i == 1 then
if newSection ~= lastSection then
if lastSection ~= '' then
table.insert( list, listFoot )
end
table.insert( list, '\n===' .. newSection .. '===\n' )
lastSection = newSection
end
table.insert( list, listHead )
end
table.insert( list, '<li><table><tr><td data-pos="' .. pos .. '">' )
if type( id ) == 'table' then
for i, id2 in ipairs( id ) do
if i == 1 then
table.insert( list, p.sprite{ id2, settings = f.args[1] } .. '</td><td><div class="sprite-id"><code>' .. id2 .. '</code></div>' )
else
table.insert( list, '<div class="sprite-id"><code>' .. id2 .. '</code></div>' )
end
end
else
table.insert( list, p.sprite{ id, settings = f.args[1] } .. '</td><td><div class="sprite-id"><code>' .. id .. '</code></div>' )
end
table.insert( list, '</td></tr></table></li>' )
if i == #posKeys then
table.insert( list, listFoot )
end
end
local out = table.concat( list )
if not f.args.refresh then
out = f:preprocess( '{{#widget:stylesheet|page=Sprite doc}}' ) .. '<div id="sprite-doc" data-settings="' .. f.args[1] .. '">' .. out .. '</div>'
end
return out
end
return p