Module:Sprite

-- local p = {}

local loader = require('Module:Loader') local getArgs = require('Module:Arguments').getArgs local string, yesno = loader.require('String', 'Yesno')

local mobSprites = loader.require('./Mobs/Sprites') local mobAliases = loader.require('./Mobs/Aliases')

local npcSprites = loader.require('./NPCs/Sprites') local npcAliases = loader.require('./NPCs/Aliases') local npcGifs = loader.require('./NPCs/Gifs')

local locationSprites = loader.require('./Locations/Sprites') local locationAliases = loader.require('./Locations/Aliases')

-- -- Template:MobSprite -- -- Creates a link to a mob with an option for sprites and images -- function p.mobSprite(frame) local args = getArgs(frame) local mob = args[1] local showName = yesno(args[2] or args["showName"] or args["show_name"] or args["sn"], true) return p._mobSprite(mob, nil, showName) end -- -- Template:MobSprite Module access point -- -- @TODO: Add dungeon mob support -- @TODO: Add dungeon boss mobs support -- @TODO: Add dungeon watcher mobs support -- function p._mobSprite(mob, alt, showName) local sprites, aliases = mobAliases, mobSprites if showName == nil then showName = true end --check for errors if not mob then error('No sprite mob provided') end --leave only text if mob:find('[^%a%s;]') then mob = mob:gsub('[^%a%s;]', '') end --alternate text if not alt and mob:find(';') then local str_storage = mw.text.split(mob, ";") mob = str_storage[1] alt = str_storage[2] end --go through sprites and apply correct image if sprites.mobs[mob:lower] then alt = alt and alt or aliases.mobs[mob:lower] mob = sprites.mobs[mob:lower] elseif sprites.sea_creatures[mob:lower] then alt = alt and alt or aliases.sea_creatures[mob:lower] mob = sprites.sea_creatures[mob:lower] elseif sprites.slayer_mobs[mob:lower] then alt = alt and alt or aliases.slayer_mobs[mob:lower] mob = sprites.slayer_mobs[mob:lower] elseif sprites.passive_mobs[mob:lower] then alt = alt and alt or aliases.passive_mobs[mob:lower] mob = sprites.passive_mobs[mob:lower] --elseif sprites.dungeon_mobs[mob:lower] then        alt = alt and alt or aliases.dungeon_mobs[mob:lower]        mob = sprites.dungeon_mobs[mob:lower]    --coming soon    --elseif sprites.dungeon_bosses[mob:lower] then         alt = alt and alt or aliases.dungeon_bosses[mob:lower]        mob = sprites.dungeon_bosses[mob:lower]    --coming soon    --elseif sprites.dungeon_boss_mobs[mob:lower] then         alt = alt and alt or aliases.dungeon_boss_mobs[mob:lower]        mob = sprites.dungeon_boss_mobs[mob:lower]    --coming soon    --elseif sprites.dungeon_watcher_mobs[mob:lower] then         alt = alt and alt or aliases.dungeon_watcher_mobs[mob:lower]        mob = sprites.dungeon_watcher_mobs[mob:lower] else error('Invalid mob name: "'..mob..'"', 2) end return table.concat{ string.makeImage({mob, ' Sprite.png'}, { size=16, link=mob }), showName and (' '..string.makeLink(mob, alt)) or '', } end

-- -- Template:NPCSprite -- -- Creates a link to an NPC with an option for sprites and images -- function p.npcSprite(frame) local args = getArgs(frame) local npc = args[1] local showName = yesno(args[2] or args["showName"] or args["show_name"] or args["sn"], true) local noErr = yesno(args['noerr'] or args['noe'], false) return p._npcSprite(npc, nil, showName, noErr) end -- -- Template:NPCSprite Module access point -- function p._npcSprite(npc, alt, showName, noErr) local sprites, aliases, gifs = npcSprites, npcAliases, npcGifs if showName == nil then showName = true end --check for errors if not npc then error('No sprite NPC provided') end --leave only text if npc:find('[^%a%s;]') then npc = npc:gsub('[^%a%s;]', '') end --alternate text local img = npc if not alt and npc:find(';') then local str_storage = mw.text.split(npc, ";") npc = str_storage[1] img = npc alt = str_storage[2] end local isGif = gifs[npc:lower] and true or false --go through sprites and apply correct image if sprites[npc:lower] then alt = alt and alt or aliases[npc:lower] npc = alt and alt or aliases[npc:lower] or error(npc) img = sprites[npc:lower] elseif noErr then return table.concat{ string.makeImage({ img, ' Sprite' }, { ext='png', size=16, link=npc }), showName and ' '..string.makeLink(npc, alt) or '', ''	   }    	-- return string.error('Invalid NPC name: "'..npc..'"', 2) else error('Invalid NPC name: "'..npc..'"', 2) end return table.concat{ string.makeImage({ img, ' Sprite' }, { ext=isGif and 'gif' or 'png', size=16, link=npc }), showName and ' '..string.makeLink(npc, alt) or '', } end

-- -- Template:LocationSprite -- -- Creates a link to an NPC with an option for sprites and images -- function p.locationSprite(frame) local args = getArgs(frame) local location = args[1] local showName = yesno(args[2] or args["showName"] or args["show_name"] or args["sn"], true) return p._locationSprite(location, nil, showName) end -- -- Template:LocationSprite Module access point -- function p._locationSprite(location, alt, showName) local sprites, aliases = locationSprites, locationAliases if showName == nil then showName = true end

--check for errors if not location then error('No sprite Location provided') end --leave only text local location_storage local pat = '[^%a%s;%-% ]' if location:match(pat) then location_storage = location location = location:gsub(pat, '') end --alternate text if not alt and location:find(';') then local str_storage = mw.text.split(location, ";") location = str_storage[1] alt = str_storage[2] end if location:lower:match('[Cc]atacombs?') then return table.concat{, location, } end --go through sprites and apply correct image if aliases[location:lower] then location = aliases[location:lower] alt = alt and alt or location location = sprites[location:lower] else return location_storage end return table.concat{ string.makeImage({ location, ' Sprite' }, { ext='png', size=16, link=location }), showName and ' '..string.makeLink(location, alt) or '', } end --Finish Module return p