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][checked revision]
(Changing Heading Colour)
No edit summary
 
(22 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
 
local Utils = require("Module:Utils")
-- Grabs args from the parent frame
local Unit = require("Module:Unit")
-- Trims and parses the args into a table, then returns the table
local AnimalUtils = require("Module:UtilsAnimalTables")
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
-- Build an Animal Infobox
function animalBox( args, animalData )
function animalBox( args, animalData )
     -- check that all necessary arguments are passed correctly
     -- check that all necessary arguments are passed correctly
     if args.name == nil or args.name == '' then
     assert(not Utils.isEmpty(args.name), 'Member \'name\' must be specified for an animal in Module:AnimalData.')
        return '\'name\' must be specified.'
    end
      
      
local animal = args.name
    local animal = args.name
    local animalTable = animalData.animals[animal]


local animalimagename = string.gsub(animal, ' ', '')
    --Check Passes
    assert(animalTable ~= nil, mw.ustring.format('Animal \'%s\' could not be found in Module:AnimalData.', animal))
 
    local animalEN = animalTable.untranslated
    local animalimagename = string.gsub(animalEN, ' ', '')
      
      
local animalTable = animalData.animals[animal]
    -- string used to build the infobox
if animalTable == nil then
    local alternateRowColor = ' bgcolor=\"#c3e2ec\"' -- Mixed in 10% Green Blue Crayola from the palette with the table background color.
return animal .. ' could not be found in Module:AnimalData.'
    local headerStyle = 'style=\"background-color:#4688C0;text-align:center;\"'
end
    local valueColumnStyle = 'style=\"text-align:right;padding:0.2em\"'
    local longValueColumnStyle = 'style=\"text-align:right;padding:0.2em;max-width:12em\"'
      
      
    -- string used to build the infobox
     local infobox = '{| class=\"infobox\"\n'
     local infobox = '{| class=\"infobox\"\n'
   
     -- name of the animal
     -- name of the animal
     infobox = infobox .. '|- style=\"background-color: darkgreen; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. animal .. '</big>\'\'\'\n'
     infobox = infobox .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. animal .. '</big>\'\'\'\n'
          
          
     -- Water, Flying or Land Animal
     -- Water, Flying or Land Animal
     infobox = infobox .. '|- style=\"text-align: center; background-color: #517ab2;\"\n| colspan=\"2\"'
     infobox = infobox .. '|- style=\"text-align: center; color: white; background-color: '
     if animalTable.isSwimming == 'Swimming' then
     if animalTable.isSwimming == 'Swimming' then
         infobox = infobox .. '| \'\'\'Water Animal\'\'\'\n'
         infobox = infobox .. '#65a9e6;\"\n| colspan=\"2\" | \'\'\'Water Animal\'\'\'[[Category:Animals]]\n'
     elseif animalTable.isFlying == 'Flying' then
     elseif animalTable.isFlying == 'Flying' then
         infobox = infobox .. '| \'\'\'Flying Animal\'\'\'\n'
         infobox = infobox .. '#e3bd27;\"\n| colspan=\"2\" | \'\'\'Flying Animal\'\'\'[[Category:Animals]]\n'
     else  
     else  
         infobox = infobox .. '| \'\'\'Land Animal\'\'\'\n'    
         infobox = infobox .. '#11af53;\"\n| colspan=\"2\" | \'\'\'Land Animal\'\'\'[[Category:Animals]]\n'    
     end
     end  
 
     -- Animals Icon Image
     -- 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]]'
     local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. animalimagename .. '_Animal.png|[[Category:Pages_with_missing_animal]]'
Line 58: Line 46:
     end
     end
      
      
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
    infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding:0;\" | [[File:' .. image .. '|center|frameless|250x250px]]\n'
      
      
     -- 'General' section header
     -- 'General' section header
     infobox = infobox .. '|- style=\"background-color: #4B9130; text-align: center;\"\n| colspan=\"2\" | \'\'\'General\'\'\'\n'
     infobox = infobox .. '|-' .. headerStyle .. '\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|' .. valueColumnStyle .. '| ' .. 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 .. '|-' .. alternateRowColor .. '\n| Idle Speed:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.wanderingSpeed, 'm/s') .. '\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'
        -- 12em seems to be enough for the other column to scale up to fill the remaining space.
end
        -- With this the longest line "Attack Damage:" fits on one line.
        infobox = infobox .. '|-\n| Eats:\n|' .. longValueColumnStyle .. '| ' .. AnimalUtils.formatFoodSources(animalTable.foodSources) .. '\n'
-- Climbing
    end  
if animalTable.climbHeight ~= nil then
   
infobox = infobox .. '|-\n| Climb Height:\n| style=\"text-align: right;\" | ' .. animalTable.climbHeight .. ' m \n'
    -- Climbing
end
    if animalTable.climbHeight ~= nil then
        infobox = infobox .. '|--' .. alternateRowColor .. '\n| Climb Height:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.climbHeight, 'm') .. '\n'
-- Carbon Released
    end  
if animalTable.carbonRelease ~= nil then
   
infobox = infobox .. '|-\n| Carbon Released:\n| style=\"text-align: right;\" | ' .. animalTable.carbonRelease .. ' ppm \n'
    -- Carbon Released
end
    if animalTable.carbonRelease ~= nil then
        infobox = infobox .. '|-\n| Carbon Released:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.carbonRelease, 'ppm') .. '\n'
    end  
   
    -- 'Hunting Information' section header
    infobox = infobox .. '|-' .. headerStyle .. '\n| colspan=\"2\" | \'\'\'Hunting\'\'\'\n'   


     -- Harvest
     -- 'Hunting Infomation' section header
     if animalTable.resourceItem ~= nil then
     infobox = infobox .. '|- style=\"background-color: #4B9130; text-align: center;\"\n| colspan=\"2\" | \'\'\'Hunting\'\'\'\n'
        infobox = infobox .. '|-\n| Harvest Item:\n|' .. valueColumnStyle .. '| ' .. animalTable.resourceItem .. '\n'
    end   
   
    -- Flees
    infobox = infobox .. '|--' .. alternateRowColor .. '\n| Flees:\n|' .. valueColumnStyle .. '| ' .. Utils.formatNilToYesNo(animalTable.flees) .. '\n'


-- Harvest
    -- Animals Fear
if animalTable.resourceItem ~= nil then
    if animalTable.fearFactor ~= nil then
infobox = infobox .. '|-\n| Harvest Item:\n| style=\"text-align: right;\" | ' .. animalTable.resourceItem .. '\n'
        infobox = infobox .. '|-\n| [[Fear Factor]]:\n|' .. valueColumnStyle .. '| ' .. animalTable.fearFactor .. '\n'
end
    end
   
-- Flees
    -- Running Speed
if animalTable.flees ~= nil then
    if animalTable.speed ~= nil then
infobox = infobox .. '|-\n| Flees:\n| style=\"text-align: right;\" | Yes \n'
        infobox = infobox .. '|-' .. alternateRowColor .. '\n| Flee Speed:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.speed, 'm/s') .. '\n'
else
    end      
infobox = infobox .. '|-\n| Flees:\n| style=\"text-align: right;\" | No \n'
end


-- Animals Fear
    -- Attack Chance
if animalTable.fearFactor ~= nil then
    if animalTable.chanceToAttack ~= nil then
infobox = infobox .. '|-\n| [[Fear Factor]]:\n| style=\"text-align: right;\" | ' .. animalTable.fearFactor .. '\n'
        infobox = infobox .. '|-\n| Attack Chance:\n|' .. valueColumnStyle .. '| ' .. tonumber(Unit._unit(animalTable.chanceToAttack))*100 .. ' % \n'
end
    end
   
-- Running Speed
    -- Attack Damage
if animalTable.speed ~= nil then
    if animalTable.damage ~= nil then
infobox = infobox .. '|-\n| Flee Speed:\n| style=\"text-align: right;\" | ' .. animalTable.speed .. ' mps \n'
        infobox = infobox .. '|-' .. alternateRowColor .. '\n| Attack Damage:\n|' .. valueColumnStyle .. '| ' .. animalTable.damage .. '\n'
end
    end
   
    -- Detect Range
    if animalTable.detectRange ~= nil then
        infobox = infobox .. '|-\n| Detect Range:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.detectRange, 'm') .. '\n'
    end


        -- Attack Chance
    -- Attack Range
        if animalTable.chanceToAttack ~= nil then
    if animalTable.attackRange ~= nil then
            infobox = infobox .. '|-\n| Attack Chance:\n| style=\"text-align: right;\" | ' .. (animalTable.chanceToAttack*100) .. ' % \n'
        infobox = infobox .. '|-' .. alternateRowColor .. '\n| Attack Range:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.attackRange, 'm') .. '\n'
        end
    end      
   
-- Attack Damage
if animalTable.damage ~= nil then
infobox = infobox .. '|-\n| Attack Damage:\n| style=\"text-align: right;\" | ' .. animalTable.damage .. '\n'
end
-- Detect Range
if animalTable.detectRange ~= nil then
infobox = infobox .. '|-\n| Detect Range:\n| style=\"text-align: right;\" | ' .. animalTable.detectRange .. ' m \n'
end
 
-- Attack Range
if animalTable.attackRange ~= nil then
infobox = infobox .. '|-\n| Attack Range:\n| style=\"text-align: right;\" | ' .. animalTable.attackRange .. ' m \n'
end
     infobox = infobox .. '|}'
     infobox = infobox .. '|}'
   
     return infobox
     return infobox
end
end


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


return p
return p

Latest revision as of 21:29, 1 September 2023

Documentation[edit source]

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 = {}
local Utils = require("Module:Utils")
local Unit = require("Module:Unit")
local AnimalUtils = require("Module:UtilsAnimalTables")

-- Build an Animal Infobox
function animalBox( args, animalData )
    -- check that all necessary arguments are passed correctly
    assert(not Utils.isEmpty(args.name), 'Member \'name\' must be specified for an animal in Module:AnimalData.')
    
    local animal = args.name
    local animalTable = animalData.animals[animal]

    --Check Passes
    assert(animalTable ~= nil, mw.ustring.format('Animal \'%s\' could not be found in Module:AnimalData.', animal))

    local animalEN = animalTable.untranslated
    local animalimagename = string.gsub(animalEN, ' ', '')
    
    -- string used to build the infobox
    local alternateRowColor = ' bgcolor=\"#c3e2ec\"' -- Mixed in 10% Green Blue Crayola from the palette with the table background color.
    local headerStyle = 'style=\"background-color:#4688C0;text-align:center;\"'
    local valueColumnStyle = 'style=\"text-align:right;padding:0.2em\"'
    local longValueColumnStyle = 'style=\"text-align:right;padding:0.2em;max-width:12em\"'
    
    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:0;\" | [[File:' .. image .. '|center|frameless|250x250px]]\n'
    
    -- 'General' section header
    infobox = infobox .. '|-' .. headerStyle .. '\n| colspan=\"2\" | \'\'\'General\'\'\'\n'

    -- Health
    if animalTable.health ~= nil then
        infobox = infobox .. '|-\n| Health:\n|' .. valueColumnStyle .. '| ' .. animalTable.health .. '\n'
    end    
    
    -- Idle Speed
    if animalTable.wanderingSpeed ~= nil then
        infobox = infobox .. '|-' .. alternateRowColor .. '\n| Idle Speed:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.wanderingSpeed, 'm/s') .. '\n'
    end        

    -- Eats
    if animalTable.foodSources ~= nil then
        -- 12em seems to be enough for the other column to scale up to fill the remaining space.
        -- With this the longest line "Attack Damage:" fits on one line.
        infobox = infobox .. '|-\n| Eats:\n|' .. longValueColumnStyle .. '| ' .. AnimalUtils.formatFoodSources(animalTable.foodSources) .. '\n'
    end    
    
    -- Climbing
    if animalTable.climbHeight ~= nil then
        infobox = infobox .. '|--' .. alternateRowColor .. '\n| Climb Height:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.climbHeight, 'm') .. '\n'
    end    
    
    -- Carbon Released
    if animalTable.carbonRelease ~= nil then
        infobox = infobox .. '|-\n| Carbon Released:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.carbonRelease, 'ppm') .. '\n'
    end    
    
    -- 'Hunting Information' section header
    infobox = infobox .. '|-' .. headerStyle .. '\n| colspan=\"2\" | \'\'\'Hunting\'\'\'\n'    

    -- Harvest
    if animalTable.resourceItem ~= nil then
        infobox = infobox .. '|-\n| Harvest Item:\n|' .. valueColumnStyle .. '| ' .. animalTable.resourceItem .. '\n'
    end    
    
    -- Flees
    infobox = infobox .. '|--' .. alternateRowColor .. '\n| Flees:\n|' .. valueColumnStyle .. '| ' .. Utils.formatNilToYesNo(animalTable.flees) .. '\n'

    -- Animals Fear
    if animalTable.fearFactor ~= nil then
        infobox = infobox .. '|-\n| [[Fear Factor]]:\n|' .. valueColumnStyle .. '| ' .. animalTable.fearFactor .. '\n'
    end
    
    -- Running Speed
    if animalTable.speed ~= nil then
        infobox = infobox .. '|-' .. alternateRowColor .. '\n| Flee Speed:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.speed, 'm/s') .. '\n'
    end        

    -- Attack Chance
    if animalTable.chanceToAttack ~= nil then
        infobox = infobox .. '|-\n| Attack Chance:\n|' .. valueColumnStyle .. '| ' .. tonumber(Unit._unit(animalTable.chanceToAttack))*100 .. ' % \n'
    end
    
    -- Attack Damage
    if animalTable.damage ~= nil then
        infobox = infobox .. '|-' .. alternateRowColor .. '\n| Attack Damage:\n|' .. valueColumnStyle .. '| ' .. animalTable.damage .. '\n'
    end
    
    -- Detect Range
    if animalTable.detectRange ~= nil then
        infobox = infobox .. '|-\n| Detect Range:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.detectRange, 'm') .. '\n'
    end

    -- Attack Range
    if animalTable.attackRange ~= nil then
        infobox = infobox .. '|-' .. alternateRowColor .. '\n| Attack Range:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.attackRange, 'm') .. '\n'
    end        
    
    infobox = infobox .. '|}'
    
    return infobox
end

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

return p