Module:Infobox Animal/sandbox: Difference between revisions
From Eco - English Wiki
[unchecked revision] | [checked revision] |
m (Styles.) |
mNo edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
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.') | |||
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 animalEN = animalTable.untranslated | ||
local animalimagename = string.gsub(animalEN, ' ', '') | |||
local subheaderClass = '|- class=\"subheader\" \n' | |||
local wideColumnClass = 'class=\"value-column wide-column\"' | |||
-- string used to build the infobox | -- string used to build the infobox | ||
local infobox = '{| class=\"infobox animal-infobox\"\n' | |||
local infobox = '{| class=\"infobox\"\n' | |||
-- name of the animal | -- name of the animal | ||
infobox = infobox .. '|- | infobox = infobox .. '|- class=\"animal-name\"\n| colspan=\"2\" | ' .. animal .. '\n' | ||
-- Water, Flying or Land Animal | -- Water, Flying or Land Animal | ||
if animalTable.isSwimming == 'Swimming' then | if animalTable.isSwimming == 'Swimming' then | ||
infobox = infobox .. ' | infobox = infobox .. '|- class=\"animal-type swimming\"\n| colspan=\"2\" | Water Animal[[Category:Animals]]\n' | ||
elseif animalTable.isFlying == 'Flying' then | elseif animalTable.isFlying == 'Flying' then | ||
infobox = infobox .. ' | infobox = infobox .. '|- class=\"animal-type flying\"\n| colspan=\"2\" | Flying Animal[[Category:Animals]]\n' | ||
else | else | ||
infobox = infobox .. ' | infobox = infobox .. '|- class=\"animal-type land\"\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]]' | |||
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 .. '|- class=\"animal-image\"\n| colspan=\"2\" | [[File:' .. image .. '|center|frameless|250x250px]]\n' | |||
-- 'General' section header | -- 'General' section header | ||
infobox = infobox .. | infobox = infobox .. subheaderClass .. '| colspan=\"2\" | General\n' | ||
-- Health | |||
if animalTable.health ~= nil then | |||
infobox = infobox .. '|-\n| Health:\n|' .. animalTable.health .. '\n' | |||
end | |||
-- Idle Speed | |||
if animalTable.wanderingSpeed ~= nil then | |||
infobox = infobox .. '|-\n| Idle Speed:\n|' .. 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|' .. 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 .. | infobox = infobox .. subheaderClass .. '| colspan=\"2\" | Hunting\n' | ||
-- Harvest | |||
if animalTable.resourceItem ~= nil then | |||
infobox = infobox .. '|-\n| Harvest Item:\n|' .. animalTable.resourceItem .. '\n' | |||
end | |||
-- Flees | |||
infobox = infobox .. '|-\n| Flees:\n|' .. Utils.formatNilToYesNo(animalTable.flees) .. '\n' | |||
-- Animals Fear | |||
if animalTable.fearFactor ~= nil then | |||
infobox = infobox .. '|-\n| [[Fear Factor]]:\n|' .. animalTable.fearFactor .. '\n' | |||
end | |||
-- Running Speed | |||
if animalTable.speed ~= nil then | |||
infobox = infobox .. '|-\n| Flee Speed:\n|' .. Unit._unit(animalTable.speed, 'm/s') .. '\n' | |||
end | |||
-- Attack Chance | -- Attack Chance | ||
if animalTable.chanceToAttack ~= nil then | if animalTable.chanceToAttack ~= nil then | ||
infobox = infobox .. '|-\n| Attack Chance:\n|' .. | infobox = infobox .. '|-\n| Attack Chance:\n|' .. (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 Range | |||
if animalTable.attackRange ~= nil then | |||
infobox = infobox .. '|-\n| Attack Range:\n|' .. Unit._unit(animalTable.attackRange, 'm') .. '\n' | |||
end | |||
infobox = infobox .. '|}' | infobox = infobox .. '|}' | ||
return infobox | return infobox | ||
end | end | ||
Line 132: | Line 124: | ||
function p.AnimalMain(frame) | function p.AnimalMain(frame) | ||
-- get args from the Template | -- get args from the Template | ||
local args = Utils.normaliseArgs(frame) | |||
-- get animal data | -- get animal data | ||
Line 138: | Line 130: | ||
return animalBox( args, animalData ) | return animalBox( args, animalData ) | ||
end | end | ||
return p | return p |
Latest revision as of 21:06, 9 April 2022
Documentation for this module may be created at Module:Infobox Animal/sandbox/doc
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, ' ', '')
local subheaderClass = '|- class=\"subheader\" \n'
local wideColumnClass = 'class=\"value-column wide-column\"'
-- string used to build the infobox
local infobox = '{| class=\"infobox animal-infobox\"\n'
-- name of the animal
infobox = infobox .. '|- class=\"animal-name\"\n| colspan=\"2\" | ' .. animal .. '\n'
-- Water, Flying or Land Animal
if animalTable.isSwimming == 'Swimming' then
infobox = infobox .. '|- class=\"animal-type swimming\"\n| colspan=\"2\" | Water Animal[[Category:Animals]]\n'
elseif animalTable.isFlying == 'Flying' then
infobox = infobox .. '|- class=\"animal-type flying\"\n| colspan=\"2\" | Flying Animal[[Category:Animals]]\n'
else
infobox = infobox .. '|- class=\"animal-type land\"\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 .. '|- class=\"animal-image\"\n| colspan=\"2\" | [[File:' .. image .. '|center|frameless|250x250px]]\n'
-- 'General' section header
infobox = infobox .. subheaderClass .. '| colspan=\"2\" | General\n'
-- Health
if animalTable.health ~= nil then
infobox = infobox .. '|-\n| Health:\n|' .. animalTable.health .. '\n'
end
-- Idle Speed
if animalTable.wanderingSpeed ~= nil then
infobox = infobox .. '|-\n| Idle Speed:\n|' .. 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|' .. 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
infobox = infobox .. subheaderClass .. '| colspan=\"2\" | Hunting\n'
-- Harvest
if animalTable.resourceItem ~= nil then
infobox = infobox .. '|-\n| Harvest Item:\n|' .. animalTable.resourceItem .. '\n'
end
-- Flees
infobox = infobox .. '|-\n| Flees:\n|' .. Utils.formatNilToYesNo(animalTable.flees) .. '\n'
-- Animals Fear
if animalTable.fearFactor ~= nil then
infobox = infobox .. '|-\n| [[Fear Factor]]:\n|' .. animalTable.fearFactor .. '\n'
end
-- Running Speed
if animalTable.speed ~= nil then
infobox = infobox .. '|-\n| Flee Speed:\n|' .. Unit._unit(animalTable.speed, 'm/s') .. '\n'
end
-- Attack Chance
if animalTable.chanceToAttack ~= nil then
infobox = infobox .. '|-\n| Attack Chance:\n|' .. (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
-- Attack Range
if animalTable.attackRange ~= nil then
infobox = infobox .. '|-\n| Attack Range:\n|' .. 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