The Alchemist Code Wiki

READ MORE

The Alchemist Code Wiki
The Alchemist Code Wiki
QZxtr (talk | contribs)
(Undo revision 729322 by QZxtr (talk))
Tag: Undo
QZxtr (talk | contribs)
(fixing the module)
Line 27: Line 27:
 
'[[File:Game,%s.png|%spx%s%s]]',
 
'[[File:Game,%s.png|%spx%s%s]]',
 
file or '',
 
file or '',
size,
+
size - padding,
 
name and name ~= '' and '|'..wikiSafeName(name) or '',
 
name and name ~= '' and '|'..wikiSafeName(name) or '',
 
link and link ~= '' and '|link='..wikiSafeName(link) or ''
 
link and link ~= '' and '|link='..wikiSafeName(link) or ''

Revision as of 12:59, 11 June 2021

Documentation for this module may be created at Module:Render/doc

local wikiSafeName = require('Module:LinkUtils').wikiSafeName
local p = {}

function p.icon(file, name, link, rare, type, size, count, classes, content, inline)
	size = size or 128
	local padding = math.floor(size*14/128)
	size = size - padding
	inline = inline and 'span' or 'div'
	local sb = mw.html.create(inline)
                  :addClass('item-icon')
	if classes ~= nil then
    	sb:addClass(classes)
	end
	local img = sb:tag(inline)
                  :addClass('img')
                  :addClass('x-'..(rare or 0))
                  :addClass('y-'..(type or 0))
                  :css('width', size..'px')
                  :css('height', size..'px')
                  :css('padding', (padding/2)..'px')
	if count ~= nil then
    	img:tag(inline)
    		:addClass('item-count')
    		:wikitext('×'..count)
	end
	  img:wikitext(string.format(
      '[[File:Game,%s.png|%spx%s%s]]',
      file or '',
      size - padding,
      name and name ~= '' and '|'..wikiSafeName(name) or '',
      link and link ~= '' and '|link='..wikiSafeName(link) or ''
    ))
	if content ~= nil then
    	sb:wikitext(content)
	end
	return tostring(sb)
end

return p