Module:Sprite

-- local p = {}

local getArgs = require('Module:Arguments').getArgs local string = require('Module:String') local table = require('Module:Table') local yesno = require('Module:Yesno')

-- -- 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) if showName == nil then showName = true end --import sprites and aliases from separate modules local sprites = require('Module:Sprite/Mobs/Sprites') local aliases = require('Module:Sprite/Mobs/Aliases') --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) return p._npcSprite(npc, nil, showName) end -- -- Template:NPCSprite Module access point -- function p._npcSprite(npc, alt, showName) if showName == nil then showName = true end --import sprites and aliases from separate modules local sprites = require('Module:Sprite/NPCs/Sprites') local aliases = require('Module:Sprite/NPCs/Aliases') local gifs = require('Module:Sprite/NPCs/Gifs') --check for errors if not npc then error('No sprite NPC provided') end local npcs = mw.text.split(npc, '\s*%*\s*') local ret = {} if table.includes(npcs, "\n") or table.includes(npcs, "") then local index = table.indexOf(npcs, "") table.remove(npcs, index ~= -1 and index or table.indexOf(npcs, "\n")) end for _, npc in pairs(npcs) do   	 --leave only text if npc:find('[^%a%s;]') then npc = npc:gsub('[^%a%s;]', '') end npc = mw.text.trim(npc) --alternate text if not alt and npc:find(';') then local str_storage = mw.text.split(npc, ";") npc = str_storage[1] 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 = sprites[npc:lower] else error('Invalid NPC name: "'..npc..'"', 2) end local done = table.concat{ string.makeImage({ npc, ' Sprite' }, { ext=isGif and 'gif' or 'png', size=16, link=npc }), showName and ' '..string.makeLink(npc, alt) or '', }	   if #npcs > 1 then done = string.wrapTag(done, 'li') end table.push(ret, done) end if #npcs > 1 then return string.wrapHtml(string.wrapTag(ret, 'ul'), ' ', { class="plainlist" }) else return table.concat(ret) end end --Finish Module return p