Внимание! Начат процесс обновления Wiki до версии игры 10.0. Если у Вас есть желание принять участие, то Вы можете найти больше информации в нашем ECO Contribution Wiki Discord.

Модуль:Infobox Animal

Материал из Eco - Русская Wiki
Перейти к:навигация, поиск

Для документации этого модуля может быть создана страница Модуль:Infobox Animal/doc

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 animalTable = animalData.animals[animal]

	--Check Passes
	if animalTable == nil then
		return animal .. ' could not be found in Module:AnimalData.'
	end

    local animalEN = animalTable.untranslated
	local animalimagename = string.gsub(animalEN, ' ', '')
    
    -- string used to build the infobox
    local infobox = '{| class=\"infobox\"\n'
    
    -- name of the animal
    infobox = infobox .. '|- style=\"color: white; background-color: #1165AF; 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 .. '#65a9e6;\"\n| colspan=\"2\" | \'\'\'Water Animal\'\'\'[[Category:Animals]]\n'
    elseif animalTable.isFlying == 'Flying' then
        infobox = infobox .. '#e3bd27;\"\n| colspan=\"2\" | \'\'\'Flying Animal\'\'\'[[Category:Animals]]\n'
    else 
        infobox = infobox .. '#11af53;\"\n| colspan=\"2\" | \'\'\'Land Animal\'\'\'[[Category:Animals]]\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|250x250px]]\n'
    
    -- 'General' section header
    infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Общие\'\'\'\n'

		-- Health
		if animalTable.health ~= nil then
			infobox = infobox .. '|-\n| Здоровье:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.health .. '\n'
		end	
		
		-- Idle Speed
		if animalTable.wanderingSpeed ~= nil then
			infobox = infobox .. '|-\n| Скорость:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.wanderingSpeed .. ' mps\n'
		end		

		-- Eats
		if animalTable.foodSources ~= nil then
			infobox = infobox .. '|-\n| Питается:\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| Выдыхает CO2:\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| Получаемое:\n| style=\"text-align: right; padding: 3px;\" | ' .. animalTable.resourceItem .. '\n'
		end	
		
		-- Flees
		if animalTable.flees ~= nil then
			infobox = infobox .. '|-\n| Бегает:\n| style=\"text-align: right; padding: 3px;\" | Yes \n'
		else 
			infobox = infobox .. '|-\n| Бегает:\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