ATTENTION! The process of updating WiKi to version Eco 10.x has begun. Those wishing to participate can find out more Information on our ECO Contribution Wiki Discord.
From April 26 to May 12, errors may occur in the Wiki, as we will be carrying out a major update to the information processing modules.

Module:Infobox Animal: Difference between revisions

From Eco - English Wiki
[unchecked revision][unchecked revision]
No edit summary
No edit summary
Line 61: Line 61:
      
      
     -- 'General' section header
     -- 'General' section header
     infobox = infobox .. '|- style=\"background-color: #4B9130; text-align: center;\"\n| colspan=\"2\" | \'\'\'General\'\'\'\n'
     infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'General\'\'\'\n'


-- Health
-- Health
if animalTable.health ~= nil then
if animalTable.health ~= nil then
infobox = infobox .. '|-\n| Health:\n| style=\"text-align: right;\" | ' .. animalTable.health .. '\n'
infobox = infobox .. '|-\n| Health:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.health .. '\n'
end
end
-- Idle Speed
-- Idle Speed
if animalTable.wanderingSpeed ~= nil then
if animalTable.wanderingSpeed ~= nil then
infobox = infobox .. '|-\n| Idle Speed:\n| style=\"text-align: right;\" | ' .. animalTable.wanderingSpeed .. ' mps\n'
infobox = infobox .. '|-\n| Idle Speed:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.wanderingSpeed .. ' mps\n'
end
end


-- Eats
-- Eats
if animalTable.foodSources ~= nil then
if animalTable.foodSources ~= nil then
infobox = infobox .. '|-\n| Eats:\n| style=\"text-align: right;\" | ' .. animalTable.foodSources .. '\n'
infobox = infobox .. '|-\n| Eats:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.foodSources .. '\n'
end
end
-- Climbing
-- Climbing
if animalTable.climbHeight ~= nil then
if animalTable.climbHeight ~= nil then
infobox = infobox .. '|-\n| Climb Height:\n| style=\"text-align: right;\" | ' .. animalTable.climbHeight .. ' m \n'
infobox = infobox .. '|-\n| Climb Height:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.climbHeight .. ' m \n'
end
end
-- Carbon Released
-- Carbon Released
if animalTable.carbonRelease ~= nil then
if animalTable.carbonRelease ~= nil then
infobox = infobox .. '|-\n| Carbon Released:\n| style=\"text-align: right;\" | ' .. animalTable.carbonRelease .. ' ppm \n'
infobox = infobox .. '|-\n| Carbon Released:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.carbonRelease .. ' ppm \n'
end
end


     -- 'Hunting Infomation' section header
     -- 'Hunting Infomation' section header
     infobox = infobox .. '|- style=\"background-color: #4B9130; text-align: center;\"\n| colspan=\"2\" | \'\'\'Hunting\'\'\'\n'
     infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Hunting\'\'\'\n'


-- Harvest
-- Harvest
if animalTable.resourceItem ~= nil then
if animalTable.resourceItem ~= nil then
infobox = infobox .. '|-\n| Harvest Item:\n| style=\"text-align: right;\" | ' .. animalTable.resourceItem .. '\n'
infobox = infobox .. '|-\n| Harvest Item:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.resourceItem .. '\n'
end
end
-- Flees
-- Flees
if animalTable.flees ~= nil then
if animalTable.flees ~= nil then
infobox = infobox .. '|-\n| Flees:\n| style=\"text-align: right;\" | Yes \n'
infobox = infobox .. '|-\n| Flees:\n| style=\"text-align: right; padding: 3px;\" | Yes \n'
else  
else  
infobox = infobox .. '|-\n| Flees:\n| style=\"text-align: right;\" | No \n'
infobox = infobox .. '|-\n| Flees:\n| style=\"text-align: right; padding: 3px;\" | No \n'
end
end


-- Animals Fear
-- Animals Fear
if animalTable.fearFactor ~= nil then
if animalTable.fearFactor ~= nil then
infobox = infobox .. '|-\n| [[Fear Factor]]:\n| style=\"text-align: right;\" | ' .. animalTable.fearFactor .. '\n'
infobox = infobox .. '|-\n| [[Fear Factor]]:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.fearFactor .. '\n'
end
end
-- Running Speed
-- Running Speed
if animalTable.speed ~= nil then
if animalTable.speed ~= nil then
infobox = infobox .. '|-\n| Flee Speed:\n| style=\"text-align: right;\" | ' .. animalTable.speed .. ' mps \n'
infobox = infobox .. '|-\n| Flee Speed:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.speed .. ' mps \n'
end
end


         -- Attack Chance
         -- Attack Chance
         if animalTable.chanceToAttack ~= nil then
         if animalTable.chanceToAttack ~= nil then
             infobox = infobox .. '|-\n| Attack Chance:\n| style=\"text-align: right;\" | ' .. (animalTable.chanceToAttack*100) .. ' % \n'
             infobox = infobox .. '|-\n| Attack Chance:\n| style=\"text-align: right; padding: 3px;\" | ' .. (animalTable.chanceToAttack*100) .. ' % \n'
         end
         end
-- Attack Damage
-- Attack Damage
if animalTable.damage ~= nil then
if animalTable.damage ~= nil then
infobox = infobox .. '|-\n| Attack Damage:\n| style=\"text-align: right;\" | ' .. animalTable.damage .. '\n'
infobox = infobox .. '|-\n| Attack Damage:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.damage .. '\n'
end
end
-- Detect Range
-- Detect Range
if animalTable.detectRange ~= nil then
if animalTable.detectRange ~= nil then
infobox = infobox .. '|-\n| Detect Range:\n| style=\"text-align: right;\" | ' .. animalTable.detectRange .. ' m \n'
infobox = infobox .. '|-\n| Detect Range:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.detectRange .. ' m \n'
end
end


-- Attack Range
-- Attack Range
if animalTable.attackRange ~= nil then
if animalTable.attackRange ~= nil then
infobox = infobox .. '|-\n| Attack Range:\n| style=\"text-align: right;\" | ' .. animalTable.attackRange .. ' m \n'
infobox = infobox .. '|-\n| Attack Range:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.attackRange .. ' m \n'
end
end

Revision as of 07:29, 15 August 2020

Documentation

This module provides the back end functionality of the Template:Infobox_Animal.

If the template is passed an Infobox will be made using details from the following Modules:


local p = {}

-- Grabs args from the parent frame
-- Trims and parses the args into a table, then returns the table
function norm()
    local origArgs = mw.getCurrentFrame():getParent().args
    local args = {}
    
    for k, v in pairs( origArgs ) do
        v = mw.text.trim( tostring( v ) )
        if v ~= '' then
            args[k] = v
        end
    end
    
    return args
end


-- Build an Animal Infobox
function animalBox( args, animalData )
    -- check that all necessary arguments are passed correctly
    if args.name == nil or args.name == '' then
        return '\'name\' must be specified.'
    end
    
	local animal = args.name

	local animalimagename = string.gsub(animal, ' ', '')
    
	local animalTable = animalData.animals[animal]
	if animalTable == nil then
		return animal .. ' could not be found in Module:AnimalData.'
	end
    
    -- string used to build the infobox
    local infobox = '{| class=\"infobox\"\n'
    
    -- name of the animal
    infobox = infobox .. '|- style=\"color: white; background-color: darkred; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. animal .. '</big>\'\'\'\n'
        
    -- Water, Flying or Land Animal
    infobox = infobox .. '|- style=\"text-align: center; color: white; background-color: '
    if animalTable.isSwimming == 'Swimming' then
        infobox = infobox .. '#517ab2;\"\n| colspan=\"2\" | \'\'\'Water Animal\'\'\'\n'
    elseif animalTable.isFlying == 'Flying' then
        infobox = infobox .. '#bf8c3a;\"\n| colspan=\"2\" | \'\'\'Flying Animal\'\'\'\n'
    else 
        infobox = infobox .. '#37b53e;\"\n| colspan=\"2\" | \'\'\'Land Animal\'\'\'\n'      
    end	
	
    -- Animals Icon Image
    local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. animalimagename .. '_Animal.png|[[Category:Pages_with_missing_animal]]'
    if mw.title.makeTitle('File', animalimagename .. '_Animal.png').file.exists then
        image = animalimagename .. '_Animal.png'
    elseif mw.title.makeTitle('File', animalimagename .. '_Animal.jpg').file.exists then
        image = animalimagename .. '_Animal.jpg'
    end
    
	infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
    
    -- 'General' section header
    infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'General\'\'\'\n'

		-- Health
		if animalTable.health ~= nil then
			infobox = infobox .. '|-\n| Health:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.health .. '\n'
		end	
		
		-- Idle Speed
		if animalTable.wanderingSpeed ~= nil then
			infobox = infobox .. '|-\n| Idle Speed:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.wanderingSpeed .. ' mps\n'
		end		

		-- Eats
		if animalTable.foodSources ~= nil then
			infobox = infobox .. '|-\n| Eats:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.foodSources .. '\n'
		end	
		
		-- Climbing
		if animalTable.climbHeight ~= nil then
			infobox = infobox .. '|-\n| Climb Height:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.climbHeight .. ' m \n'
		end	
		
		-- Carbon Released
		if animalTable.carbonRelease ~= nil then
			infobox = infobox .. '|-\n| Carbon Released:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.carbonRelease .. ' ppm \n'
		end	

	
    -- 'Hunting Infomation' section header
    infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Hunting\'\'\'\n'	

		-- Harvest
		if animalTable.resourceItem ~= nil then
			infobox = infobox .. '|-\n| Harvest Item:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.resourceItem .. '\n'
		end	
		
		-- Flees
		if animalTable.flees ~= nil then
			infobox = infobox .. '|-\n| Flees:\n| style=\"text-align: right; padding: 3px;\" | Yes \n'
		else 
			infobox = infobox .. '|-\n| Flees:\n| style=\"text-align: right; padding: 3px;\" | No \n'	
		end		

		-- Animals Fear
		if animalTable.fearFactor ~= nil then
			infobox = infobox .. '|-\n| [[Fear Factor]]:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.fearFactor .. '\n'
		end
		
		-- Running Speed
		if animalTable.speed ~= nil then
			infobox = infobox .. '|-\n| Flee Speed:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.speed .. ' mps \n'
		end		

        -- Attack Chance
        if animalTable.chanceToAttack ~= nil then
            infobox = infobox .. '|-\n| Attack Chance:\n| style=\"text-align: right; padding: 3px;\" | ' .. (animalTable.chanceToAttack*100) .. ' % \n'
        end
		
		-- Attack Damage
		if animalTable.damage ~= nil then
			infobox = infobox .. '|-\n| Attack Damage:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.damage .. '\n'
		end
		
		-- Detect Range
		if animalTable.detectRange ~= nil then
			infobox = infobox .. '|-\n| Detect Range:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.detectRange .. ' m \n'
		end

		-- Attack Range
		if animalTable.attackRange ~= nil then
			infobox = infobox .. '|-\n| Attack Range:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.attackRange .. ' m \n'
		end		
	
    infobox = infobox .. '|}'
	
    return infobox
end


-- Main entry point for the Module
function p.AnimalMain()
    -- get args from the Template
    local args = norm()
    
    -- get animal data
    local animalData = require( "Module:AnimalData" )
    
    return animalBox( args, animalData )
    
end


return p