Module:Sprite

-- local p = {}

local getArgs = require('Module:Arguments').getArgs local string = require('Module:String') 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 --leave only text if npc:find('[^%a%s;]') then npc = npc:gsub('[^%a%s;]', '') end --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 return table.concat{ string.makeImage({ npc, ' 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) if showName == nil then showName = true end --import sprites and aliases from separate modules local sprites = require('Module:Sprite/Locations/Sprites') local aliases = require('Module:Sprite/Locations/Aliases') --check for errors if not location then error('No sprite Location provided') end --leave only text local pat = '[^%a%s;%-% ]' if location:match(pat) then 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 error('Invalid Location name: "'..location..'"', 2) 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