SpaceArena Wiki
Advertisement

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

--Space Arena Wiki Icon Module
--http://spacearena.fandom.com/
--Written by User:ChickenBar

local p = {}

local IconData = mw.loadData( 'Module:Icon/data' )


function p.Item(frame)
	local iconname = frame.args[1]
	local textexist = frame.args[2]
	local imagesize = frame.args.imgsize
 
	return p._Item(iconname, textexist, imagesize)
end

--Extracting out to this function allows other Modules to call item text
--Since any templates output by another module won't be parsed by the wiki
function p._Item(iconname, textexist, imagesize)
	local iconname = string.gsub(" "..string.lower( iconname ), "%W%l", string.upper):sub(2)
	local link = ''
	if IconData["Items"][iconname] == nil then
		return "<span style=\"color:red;\">Invalid</span>[[Category:Icon Module error]]"  
	else
		link = IconData["Items"][iconname]["link"]
		title = IconData["Items"][iconname]["title"]
		iconname = IconData["Items"][iconname]["icon"]
		if (imagesize == nil or imagesize == '') then
			imagesize = 'x26'
		end
		
		local imgText = '[[File:'..iconname..'|'..imagesize..'px'
		if(link ~= nil) then
			imgText = imgText..'|link='..link
		elseif(title~=nil) then
			imgText = imgText..'|'..title
		end
		imgText = imgText..']]'
		
		if (textexist == 'text' or textexist == 'Text') then
			if (link ~= nil) then
				return imgText..' [['..link..']]'
			elseif (title ~= nil) then
				return imgText..' '..title
			else
				return imgText
			end
		end
		return imgText
	end
end

function p.Resource( frame )
    local iconname = frame.args[1]        
    local textexist = frame.args[2]
    local imagesize = frame.args.imgsize
 
    return p._Resource(iconname, textexist, imagesize)
end

function p._Resource(iconname, textexist, imagesize)
    local link = ''
    if IconData["Resources"][iconname] == nil then          
        if (textexist == 'text' or textexist == 'Text') then                           
            return '[['.. iconname ..']]'
        end
        -- TODO: A placeholder icon and do this for all the item types
        return ""
    else
        link = IconData["Resources"][iconname]["link"]
        iconname = IconData["Resources"][iconname]["icon"]
        if (imagesize == nil or imagesize == '') then
            imagesize = 'x32'                                 
        end
        if (textexist == 'text' or textexist == 'Text') then                           
            return '[[File:'..iconname..'|'..imagesize..'px|link='..link..']] [['..link..']]'
        end
        return '[[File:'..iconname..'|'..imagesize..'px|link='..link..']]'
    end
end

function p.Test2(par1, par2)
    spans = tooltipSpan(par1, par2)
    return spans[1]..spans[2]
end

function p.Test(frame)
    return p._Proc(frame.args[1])
end

return p
Advertisement