The Alchemist Code Wiki

READ MORE

The Alchemist Code Wiki
QZxtr (talk | contribs)
mNo edit summary
QZxtr (talk | contribs)
(Undo revision 729322 by QZxtr (talk))
Tag: Undo
Line 4: Line 4:
 
function p.icon(file, name, link, rare, type, size, count, classes, content, inline)
 
function p.icon(file, name, link, rare, type, size, count, classes, content, inline)
 
size = size or 128
 
size = size or 128
local padding = math.floor(size*28/128)
+
local padding = math.floor(size*14/128)
 
size = size - padding
 
size = size - padding
 
inline = inline and 'span' or 'div'
 
inline = inline and 'span' or 'div'

Revision as of 15:25, 1 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,
      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