Module:KnightBot4/SpriteSub

local p = {}

function p.sub( f ) local args = f	if mw.getCurrentFrame == f then args = f:getParent.args end local name = args.name local name2 if name:find( 'Sprite' ) then name2 = name:gsub( '^(.-)Sprite.*$', '%1' ) else name2 = name:gsub( '^(.-)Link.*$', '%1' ) end local ids = mw.loadData( 'Module:' .. name2 .. 'Sprite' .. '/IDs' ).ids

-- Inverting the table into a "number = name" format local names = {} for id, data in pairs( ids ) do		local num = data.pos if not names[num] and not data.deprecated then names[num] = id		end end -- Replace the ID with name if args.id and names[tonumber(args.id)] then args.id = names[tonumber(args.id)] elseif args[1] and names[tonumber(args[1])] then args[1] = names[tonumber(args[1])] end -- Return the added args local outArgs = { '' } local argTypes = { 'id', 'link', 1, 2, 'text' } for _, arg in ipairs( argTypes ) do		if args[arg] then if arg == 1 or arg == 2 then table.insert( outArgs, args[arg] ) else table.insert( outArgs, arg .. '=' .. args[arg] ) end end end

return '' end

return p