FANDOM


local p = {}
 
local icons = {
   ['gold'] = {
       ['filename']    = 'Gold.png',
       ['defaultsize'] = 20,
       ['defaultlink'] = 'Resources#Gold',
   },
   ['elixir'] = {
       ['filename']    = 'Elixir.png',
       ['defaultsize'] = 18,
       ['defaultlink'] = 'Resources#Elixir',
   },
   ['darkelixir'] = {
       ['filename']    = 'Dark elixir.png',
       ['defaultsize'] = 18,
       ['defaultlink'] = 'Resources#Dark Elixir',
   },
}
 
local function round( num, idp )
   local mult = 10 ^ ( idp or 0 )
   return math.floor( num * mult + 0.5 ) / mult
end
 
 
function p.icon( iconType, size, link )
   iconType = string.gsub(string.lower( iconType ), "%s+", "")
   icon     = icons[ iconType ]
 
   if not icon then
      return ''
   end
 
   if not size then
      size = icon[ 'defaultsize' ] .. 'px'
   elseif tonumber( size ) then
      size = size .. 'px'
   elseif string.sub( size, -1 ) == '%' then
      local pct = tonumber( string.sub( size, 0, -2 ) )
 
      if pct then
         size = round( icon[ 'defaultsize' ] * pct / 100, 0 ) .. 'px'
      end
   end
 
   if not link then
      link = icon[ 'defaultlink' ]
   elseif string.lower( link ) == 'none' then
      link = ''
   end
 
   return '[[File:' .. icon[ 'filename' ] .. '|' .. size .. '|link=' .. link ..']]'
end
 
function p.main( frame )
   local iconType = frame.args[ 'type' ] or frame.args[ 1 ]
   local size     = frame.args[ 'size' ]
   local link     = frame.args[ 'link' ]
 
   local icon = p.icon( iconType, size, link )
   return frame:preprocess( icon )
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.