Module:Icon: Difference between revisions

From Terra Invicta Official Wiki
Redwah (talk | contribs)
No edit summary
Redwah (talk | contribs)
No edit summary
 
(8 intermediate revisions by 2 users not shown)
Line 6: Line 6:
local iconData = mw.loadData( 'Module:Icon/data' )
local iconData = mw.loadData( 'Module:Icon/data' )
local missionIconData = mw.loadData( 'Module:Icon/mission' )
local missionIconData = mw.loadData( 'Module:Icon/mission' )
local bodiesIconData = mw.loadData( 'Module:Icon/bodies' )
local slower = string.lower
local slower = string.lower


function p.Icon( frame )
function p.Icon( frame )
local iconName = frame.args[1]
if not iconName then
return 'no icon name specified'
end
if not iconData[iconName] then
iconName = slower(iconName)
end
if not iconData[iconName] then
iconName = mw.text.trim(iconName)
end
if not iconData[iconName] then
return 'No such icon as "' .. iconName .. '"'
end
local bgcolor = frame.args['bgcolor']
if not bgcolor or mw.text.trim(bgcolor) == '' then
bgcolor = 'transparent'
end
local size = frame.args['size']
if not size or mw.text.trim(size) == '' then
size = '20px'
end
local retstart = '<span style="background-color: ' .. bgcolor .. '; display: inline-block;">[[File:'
local retmid = '|' .. size .. '|'
local retend = ']]</span>'
-- iconData[iconName][1] is the file name.
-- iconData[iconName][2] is the caption.
return retstart .. iconData[iconName][1]  .. retmid .. iconData[iconName][2] .. retend
end
function p.MissionIcon( frame )
     local iconName = frame.args[1]
     local iconName = frame.args[1]
     if not iconName then
     if not iconName then
     return 'No such icon'
     return 'No such icon'
     end
     end
     if not iconData[iconName] then
     if not missionIconData[iconName] then
     iconName = slower(iconName)
     iconName = slower(iconName)
     end
     end
     if not iconData[iconName] then
     if not missionIconData[iconName] then
     return 'No such icon'
     return 'No such icon'
    end
   
    local bgcolor = frame.args['bgcolor']
    if not bgcolor or mw.text.trim(bgcolor) == '' then
    bgcolor = 'transparent'
     end
     end
      
      
Line 30: Line 60:
     end
     end
      
      
local retstart = '<span style="background-color: ' .. bgcolor .. '; display: inline-block;">[[File:'
local retstart = '<span style="background-color: transparent; display: inline-block;">[[File:'
local retmid = '|' .. size .. '|'
local retmid = '|' .. size .. '|'
local retend = ']]</span>'
local retend = ']]</span>'


-- iconData[iconName][1] is the file name.
-- missionIconData[iconName][1] is the file name.
-- iconData[iconName][2] is the caption.
-- missionIconData[iconName][2] is the caption.
     return retstart .. iconData[iconName][1]  .. retmid .. iconData[iconName][2] .. retend
     return retstart .. missionIconData[iconName][1]  .. retmid .. missionIconData[iconName][2] .. retend
end
end


function p.MissionIcon( frame )
function p.BodiesIcon( frame )
     local iconName = frame.args[1]
     local iconName = frame.args[1]
     if not iconName then
     if not iconName then
     return 'No such icon'
     return 'No such icon'
     end
     end
     if not missionIconData[iconName] then
     if not bodiesIconData[iconName] then
     iconName = slower(iconName)
     iconName = slower(iconName)
     end
     end
     if not missionIconData[iconName] then
     if not bodiesIconData[iconName] then
     return 'No such icon'
     return 'No such icon'
     end
     end
      
     -- Default to xpx as icon height is constant but Saturn is double width
     local size = frame.args['size']
     local size = frame.args[2]
     if not size then
     if not size or mw.text.trim(size) == '' then
     size = '20px'
     size = 'x20px'
     end
     end
      
      
Line 60: Line 90:
local retend = ']]</span>'
local retend = ']]</span>'


-- missionIconData[iconName][1] is the file name.
-- bodiesIconData[iconName][1] is the file name.
-- missionIconData[iconName][2] is the caption.
-- bodiesIconData[iconName][2] is the caption.
     return retstart .. missionIconData[iconName][1]  .. retmid .. missionIconData[iconName][2] .. retend
     return retstart .. bodiesIconData[iconName][1]  .. retmid .. bodiesIconData[iconName][2] .. retend
end
end


return p
return p

Latest revision as of 13:42, 30 December 2025

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

-- This is a LUA version of the Template:Icon page. 
-- I'm making this because it should run way way way faster than the 100+ switch cases used by Template:Icon

local p = {}

local iconData = mw.loadData( 'Module:Icon/data' )
local missionIconData = mw.loadData( 'Module:Icon/mission' )
local bodiesIconData = mw.loadData( 'Module:Icon/bodies' )
local slower = string.lower

function p.Icon( frame )
	local iconName = frame.args[1]
	if not iconName then
		return 'no icon name specified'	
	end
	if not iconData[iconName] then
		iconName = slower(iconName)	
	end
	if not iconData[iconName] then
		iconName = mw.text.trim(iconName)	
	end
	if not iconData[iconName] then
		return 'No such icon as "' .. iconName .. '"'
	end
	
	local bgcolor = frame.args['bgcolor']
	if not bgcolor or mw.text.trim(bgcolor) == '' then
		bgcolor = 'transparent'	
	end
	
	local size = frame.args['size']
	if not size or mw.text.trim(size) == '' then
		size = '20px'	
	end
	
	local retstart = '<span style="background-color: ' .. bgcolor .. '; display: inline-block;">[[File:'
	local retmid = '|' .. size .. '|'
	local retend = ']]</span>'
	
	-- iconData[iconName][1] is the file name.
	-- iconData[iconName][2] is the caption.
	return retstart .. iconData[iconName][1]  .. retmid .. iconData[iconName][2] .. retend
end

function p.MissionIcon( frame )
    local iconName = frame.args[1]
    if not iconName then
    	return 'No such icon'	
    end
    if not missionIconData[iconName] then
    	iconName = slower(iconName)	
    end
    if not missionIconData[iconName] then
    	return 'No such icon'	
    end
    
    local size = frame.args['size']
    if not size or mw.text.trim(size) == '' then
    	size = '20px'	
    end
    
	local retstart = '<span style="background-color: transparent; display: inline-block;">[[File:'
	local retmid = '|' .. size .. '|'
	local retend = ']]</span>'

	-- missionIconData[iconName][1] is the file name.
	-- missionIconData[iconName][2] is the caption.
    return retstart .. missionIconData[iconName][1]  .. retmid .. missionIconData[iconName][2] .. retend
end

function p.BodiesIcon( frame )
    local iconName = frame.args[1]
    if not iconName then
    	return 'No such icon'	
    end
    if not bodiesIconData[iconName] then
    	iconName = slower(iconName)	
    end
    if not bodiesIconData[iconName] then
    	return 'No such icon'	
    end
    -- Default to xpx as icon height is constant but Saturn is double width
    local size = frame.args[2]
    if not size or mw.text.trim(size) == '' then
    	size = 'x20px'	
    end
    
	local retstart = '<span style="background-color: transparent; display: inline-block;">[[File:'
	local retmid = '|' .. size .. '|'
	local retend = ']]</span>'

	-- bodiesIconData[iconName][1] is the file name.
	-- bodiesIconData[iconName][2] is the caption.
    return retstart .. bodiesIconData[iconName][1]  .. retmid .. bodiesIconData[iconName][2] .. retend
end

return p