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 | 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 not idData then | |||
default = mw.loadData( 'Module:' .. args. | 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 | local allowCats = not mw.title.getCurrentTitle().isSubpage | ||
if not idData and allowCats then | |||
table.insert( categories, '[[Category:Pages with missing sprites]]' ) | |||
else | |||
if | if idData.deprecated and allowCats then | ||
table.insert( categories, '[[Category:Pages using deprecated sprite names]]' ) | |||
end | |||
args.pos = idData.pos | |||
end | end | ||
end | end | ||
return p.base( args ) . | 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 | local idData = data.ids[name] | ||
local pos = | local pos = idData.pos | ||
local section = sections[ | 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 | ||