Editing Module:Infobox Animal
From Eco - English Wiki
Your changes will be displayed to readers once an authorized user accepts them. (help)
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 1: | Line 1: | ||
local p = {} | local p = {} | ||
local | |||
local | -- 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 | -- 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 | |||
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 | -- string used to build the infobox | ||
local | local infobox = '{| class=\"infobox\"\n' | ||
-- name of the animal | -- name of the animal | ||
infobox = infobox .. '|- style=\"color: white; background-color: | infobox = infobox .. '|- style=\"text-color: white; background-color: darkgreen; 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 | infobox = infobox .. '|- style=\"text-align: center; background-color: #517ab2;\"\n| colspan=\"2\"' | ||
if animalTable.isSwimming == 'Swimming' then | if animalTable.isSwimming == 'Swimming' then | ||
infobox = infobox .. ' | infobox = infobox .. '| \'\'\'Water Animal\'\'\'\n' | ||
elseif animalTable.isFlying == 'Flying' then | elseif animalTable.isFlying == 'Flying' then | ||
infobox = infobox .. ' | infobox = infobox .. '| \'\'\'Flying Animal\'\'\'\n' | ||
else | else | ||
infobox = infobox .. ' | infobox = infobox .. '| \'\'\'Land Animal\'\'\'\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 46: | Line 58: | ||
end | end | ||
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n' | |||
-- 'General' section header | -- 'General' section header | ||
infobox = infobox .. '|- | infobox = infobox .. '|- style=\"background-color: #4B9130; text-align: center;\"\n| colspan=\"2\" | \'\'\'General\'\'\'\n' | ||
-- Health | |||
if animalTable.health ~= nil then | |||
infobox = infobox .. '|-\n| Health:\n| style=\"text-align: right;\" | ' .. animalTable.health .. '\n' | |||
end | |||
-- Idle Speed | |||
if animalTable.wanderingSpeed ~= nil then | |||
infobox = infobox .. '|-\n| Idle Speed:\n| style=\"text-align: right;\" | ' .. animalTable.wanderingSpeed .. ' mps\n' | |||
end | |||
-- Eats | |||
if animalTable.foodSources ~= nil then | |||
infobox = infobox .. '|-\n| Eats:\n| style=\"text-align: right;\" | ' .. animalTable.foodSources .. '\n' | |||
end | |||
-- Climbing | |||
if animalTable.climbHeight ~= nil then | |||
infobox = infobox .. '|-\n| Climb Height:\n| style=\"text-align: right;\" | ' .. animalTable.climbHeight .. ' m \n' | |||
end | |||
-- Carbon Released | |||
if animalTable.carbonRelease ~= nil then | |||
infobox = infobox .. '|-\n| Carbon Released:\n| style=\"text-align: right;\" | ' .. animalTable.carbonRelease .. ' ppm \n' | |||
end | |||
-- 'Hunting Infomation' section header | |||
infobox = infobox .. '|- style=\"background-color: #4B9130; text-align: center;\"\n| colspan=\"2\" | \'\'\'Hunting\'\'\'\n' | |||
-- Harvest | |||
if animalTable.resourceItem ~= nil then | |||
infobox = infobox .. '|-\n| Harvest Item:\n| style=\"text-align: right;\" | ' .. animalTable.resourceItem .. '\n' | |||
end | |||
-- Flees | |||
if animalTable.flees ~= nil then | |||
infobox = infobox .. '|-\n| Flees:\n| style=\"text-align: right;\" | Yes \n' | |||
else | |||
infobox = infobox .. '|-\n| Flees:\n| style=\"text-align: right;\" | No \n' | |||
end | |||
-- Animals Fear | |||
if animalTable.fearFactor ~= nil then | |||
infobox = infobox .. '|-\n| [[Fear Factor]]:\n| style=\"text-align: right;\" | ' .. animalTable.fearFactor .. '\n' | |||
end | |||
-- Running Speed | |||
if animalTable.speed ~= nil then | |||
infobox = infobox .. '|-\n| Flee Speed:\n| style=\"text-align: right;\" | ' .. animalTable.speed .. ' mps \n' | |||
end | |||
-- Attack Chance | |||
if animalTable.chanceToAttack ~= nil then | |||
infobox = infobox .. '|-\n| Attack Chance:\n| style=\"text-align: right;\" | ' .. (animalTable.chanceToAttack*100) .. ' % \n' | |||
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() | ||
-- get args from the Template | -- get args from the Template | ||
local args = | local args = norm() | ||
-- get animal data | -- get animal data | ||
local animalData = require( | local animalData = require( "Module:AnimalData" ) | ||
return animalBox( args, animalData ) | return animalBox( args, animalData ) | ||
end | end | ||
return p | return p |