Editing Module:Infobox Animal/sandbox

From Eco - English Wiki

Your changes will be displayed to readers once an authorized user accepts them. (help)

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 7: Line 7:
function animalBox( args, animalData )
function animalBox( args, animalData )
     -- check that all necessary arguments are passed correctly
     -- 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.')
     if args.name == nil or args.name == '' then
        return 'ERROR: \'name\' must be specified.'
    end
      
      
    local animal = args.name
local animal = args.name
    local animalTable = animalData.animals[animal]
local animalTable = animalData.animals[animal]


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


     local animalEN = animalTable.untranslated
     local animalEN = animalTable.untranslated
    local animalimagename = string.gsub(animalEN, ' ', '')
local animalimagename = string.gsub(animalEN, ' ', '')
      
      
     local subheaderClass = '|- class=\"subheader\" \n'
    -- string used to build the infobox
     local wideColumnClass = 'class=\"value-column wide-column\"'
     local infobox = '{| class=\"infobox\"\n'
     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;\" '
      
      
    -- string used to build the infobox
    local infobox = '{| class=\"infobox animal-infobox\"\n'
     -- name of the animal
     -- name of the animal
     infobox = infobox .. '|- class=\"animal-name\"\n| colspan=\"2\" | ' .. animal .. '\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; color: white; background-color: '
     if animalTable.isSwimming == 'Swimming' then
     if animalTable.isSwimming == 'Swimming' then
         infobox = infobox .. '|- class=\"animal-type swimming\"\n| colspan=\"2\" | Water Animal[[Category:Animals]]\n'
         infobox = infobox .. '#65a9e6;\"\n| colspan=\"2\" | \'\'\'Water Animal\'\'\'[[Category:Animals]]\n'
     elseif animalTable.isFlying == 'Flying' then
     elseif animalTable.isFlying == 'Flying' then
         infobox = infobox .. '|- class=\"animal-type flying\"\n| colspan=\"2\" | Flying Animal[[Category:Animals]]\n'
         infobox = infobox .. '#e3bd27;\"\n| colspan=\"2\" | \'\'\'Flying Animal\'\'\'[[Category:Animals]]\n'
     else  
     else  
         infobox = infobox .. '|- class=\"animal-type land\"\n| colspan=\"2\" | Land Animal[[Category:Animals]]\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]]'
    if mw.title.makeTitle('File', animalimagename .. '_Animal.png').file.exists then
if mw.title.makeTitle('File', animalimagename .. '_Animal.png').file.exists then
        image = animalimagename .. '_Animal.png'
image = animalimagename .. '_Animal.png'
    elseif mw.title.makeTitle('File', animalimagename .. '_Animal.jpg').file.exists then
elseif mw.title.makeTitle('File', animalimagename .. '_Animal.jpg').file.exists then
        image = animalimagename .. '_Animal.jpg'
image = animalimagename .. '_Animal.jpg'
    end
end
      
      
    infobox = infobox .. '|- class=\"animal-image\"\n| colspan=\"2\" | [[File:' .. image .. '|center|frameless|250x250px]]\n'
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding:0;\" | [[File:' .. image .. '|center|frameless|250x250px]]\n'
      
      
     -- 'General' section header
     -- 'General' section header
     infobox = infobox .. subheaderClass .. '| colspan=\"2\" | General\n'
     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


    -- Health
-- Eats
    if animalTable.health ~= nil then
if animalTable.foodSources ~= nil then
        infobox = infobox .. '|-\n| Health:\n|' .. animalTable.health .. '\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|' .. valueColumnStyle .. '|style=\"max-width:12em;\"|' .. AnimalUtils.formatFoodSources(animalTable.foodSources) .. '\n'
    -- Idle Speed
end
    if animalTable.wanderingSpeed ~= nil then
        infobox = infobox .. '|-\n| Idle Speed:\n|' .. Unit._unit(animalTable.wanderingSpeed, 'm/s') .. '\n'
-- Climbing
    end      
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


    -- 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|' .. wideColumnClass .. '| ' .. AnimalUtils.formatFoodSources(animalTable.foodSources) .. '\n'
    end   
   
    -- Climbing
    if animalTable.climbHeight ~= nil then
        infobox = infobox .. '|-\n| Climb Height:\n|' .. Unit._unit(animalTable.climbHeight, 'm') .. '\n'
    end   
   
    -- Carbon Released
    if animalTable.carbonRelease ~= nil then
        infobox = infobox .. '|-\n| Carbon Released:\n|' .. Unit._unit(animalTable.carbonRelease, 'ppm') .. '\n'
    end   
   
     -- 'Hunting Information' section header
     -- 'Hunting Information' section header
     infobox = infobox .. subheaderClass .. '| colspan=\"2\" | Hunting\n'  
     infobox = infobox .. '|-' .. headerStyle .. '\n| colspan=\"2\" | \'\'\'Hunting\'\'\'\n'


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


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


     -- Attack Chance
     -- Attack Chance
     if animalTable.chanceToAttack ~= nil then
     if animalTable.chanceToAttack ~= nil then
         infobox = infobox .. '|-\n| Attack Chance:\n|' .. (animalTable.chanceToAttack * 100) .. ' % \n'
         infobox = infobox .. '|-\n| Attack Chance:\n|' .. valueColumnStyle .. '| ' .. (animalTable.chanceToAttack*100) .. ' % \n'
    end
   
    -- Attack Damage
    if animalTable.damage ~= nil then
        infobox = infobox .. '|-\n| Attack Damage:\n|' .. animalTable.damage .. '\n'
    end
   
    -- Detect Range
    if animalTable.detectRange ~= nil then
        infobox = infobox .. '|-\n| Detect Range:\n|' .. Unit._unit(animalTable.detectRange, 'm') .. '\n'
     end
     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
-- Attack Range
    if animalTable.attackRange ~= nil then
if animalTable.attackRange ~= nil then
        infobox = infobox .. '|-\n| Attack Range:\n|' .. Unit._unit(animalTable.attackRange, 'm') .. '\n'
infobox = infobox .. '|-' .. alternateRowColor .. '\n| Attack Range:\n|' .. valueColumnStyle .. '| ' .. Unit._unit(animalTable.attackRange, 'm') .. '\n'
    end      
end
   
     infobox = infobox .. '|}'
     infobox = infobox .. '|}'
   
     return infobox
     return infobox
end
end
Line 124: Line 131:
function p.AnimalMain(frame)
function p.AnimalMain(frame)
     -- get args from the Template
     -- get args from the Template
    local args = Utils.normaliseArgs(frame)
local args = Utils.normaliseArgs(frame)
      
      
     -- get animal data
     -- get animal data
Line 130: Line 137:
      
      
     return animalBox( args, animalData )
     return animalBox( args, animalData )
   
end
end


return p
return p
Please note that all contributions to Eco - English Wiki are considered to be released under the CC BY-NC-SA 4.0 (see Eco:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following hCaptcha:

Cancel Editing help (opens in new window)

Template used on this page: