Module:Sprite: Difference between revisions

Change sections to use unique IDs.
Implement deprecated sprites, add tracking category for positions
Line 113: Line 113:
end
end
local category = ''
local categories = {}
if tonumber( args[1] ) then
if tonumber( args[1] ) then
args.pos = args[1]
args.pos = args[1]
table.insert( categories, '[[Category:Pages using sprite positions]]' )
else
else
local default = {}
local idData = args.iddata
if args.settings then
if not idData then
default = mw.loadData( 'Module:' .. args.settings )
local default = {}
if args.settings then
default = mw.loadData( 'Module:' .. args.settings )
end
local name = args.name or default.name
local ids = mw.loadData( 'Module:' .. ( args.ids or default.ids or name .. '/IDs' ) ).ids
local id = mw.text.trim( args[1] or '' )
idData = ids[id] or ids[mw.ustring.lower( id ):gsub( '[%s%+]', '-' )]
end
end
local name = args.name or default.name
local allowCats = not mw.title.getCurrentTitle().isSubpage
local ids = mw.loadData( 'Module:' .. ( args.ids or default.ids or name .. '/IDs' ) ).ids
if not idData and allowCats then
local id = mw.text.trim( args[1] or '' )
table.insert( categories, '[[Category:Pages with missing sprites]]' )
local pos = ( ids[id] or ids[mw.ustring.lower( id ):gsub( '[%s%+]', '-' )] or {} ).pos
else
if not pos and not mw.title.getCurrentTitle().isSubpage then
if idData.deprecated and allowCats then
category = '[[Category:Pages with missing sprites]]'
table.insert( categories, '[[Category:Pages using deprecated sprite names]]' )
end
args.pos = idData.pos
end
end
args.pos = pos
end
end
return p.base( args ) .. category
return p.base( args ), table.concat( categories, '' )
end
end


Line 199: Line 210:
for _, name in ipairs( nameKeys ) do
for _, name in ipairs( nameKeys ) do
local val = data.ids[name]
local idData = data.ids[name]
local pos = val.pos
local pos = idData.pos
local section = sections[val.section]
local section = sections[idData.section]
local names = section[pos]
local names = section[pos]
if not names then
if not names then
Line 211: Line 222:
section[pos] = names
section[pos] = names
end
end
names:tag( 'li' ):addClass( 'spritedoc-name' ):tag( 'code' ):wikitext( name )
local codeElem = names
:tag( 'li' ):addClass( 'spritedoc-name' )
:tag( 'code' ):wikitext( name )
if idData.deprecated then
codeElem:addClass( 'spritedoc-deprecated' )
end
end
end