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.loadData('Module:Sprite/Mobs/Sprites') local mobAliases = loader.loadData('Module:Sprite/Mobs/Aliases')

local npcSprites = loader.loadData('Module:Sprite/NPCs/Sprites') local npcAliases = loader.loadData('Module:Sprite/NPCs/Aliases') local npcGifs = loader.loadData('Module:Sprite/NPCs/Gifs')

local locationSprites = loader.loadData('Module:Sprite/Locations/Sprites') local locationAliases = loader.loadData('Module:Sprite/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 = mobSprites, mobAliases if showName == nil then showName = true end --check for errors assertTrue(mob, 'No sprite mob provided', 2) --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 local name, spr --go through sprites and apply correct image if sprites.mobs[mob:lower] then name = alt and alt or aliases.mobs[mob:lower] spr = sprites.mobs[mob:lower] elseif sprites.sea_creatures[mob:lower] then name = alt and alt or aliases.sea_creatures[mob:lower] spr = sprites.sea_creatures[mob:lower] elseif sprites.slayer_mobs[mob:lower] then name = alt and alt or aliases.slayer_mobs[mob:lower] spr = sprites.slayer_mobs[mob:lower] elseif sprites.passive_mobs[mob:lower] then name = alt and alt or aliases.passive_mobs[mob:lower] spr = sprites.passive_mobs[mob:lower] --elseif sprites.dungeon_mobs[mob:lower] then        name = alt and alt or aliases.dungeon_mobs[mob:lower]        spr = sprites.dungeon_mobs[mob:lower]    --coming soon    --elseif sprites.dungeon_bosses[mob:lower] then         name = alt and alt or aliases.dungeon_bosses[mob:lower]        spr = sprites.dungeon_bosses[mob:lower]    --coming soon    --elseif sprites.dungeon_boss_mobs[mob:lower] then         name = alt and alt or aliases.dungeon_boss_mobs[mob:lower]        spr = sprites.dungeon_boss_mobs[mob:lower]    --coming soon    --elseif sprites.dungeon_watcher_mobs[mob:lower] then         name = alt and alt or aliases.dungeon_watcher_mobs[mob:lower]        spr = sprites.dungeon_watcher_mobs[mob:lower] else error('Invalid mob name: "'..mob..'"', 2) end return table.concat{ string.makeImage({spr, ' Sprite.png'}, { size=16, link=name }), showName and (' '..string.makeLink(name, name)) 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 assertTrue(npc, 'No sprite NPC provided', 2) --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, exist = gifs[npc:lower] and true or false, false --go through sprites and apply correct image alt = alt and alt or (aliases[npc:lower] or npc) npc = aliases[npc:lower] or npc if sprites[npc:lower] then exist = true 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 '', exist and  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 assertTrue(location, 'No sprite Location provided', 2) --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