Editing Module:Table Animals

From Eco - English Wiki
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 2: Line 2:
local Utils = require("Module:Utils")
local Utils = require("Module:Utils")
local AnimalUtils = require("Module:UtilsAnimalTables")
local AnimalUtils = require("Module:UtilsAnimalTables")
local AnimalData = mw.loadData("Module:AnimalData")
local HTMLUtils = require("Module:UtilsHTML")


local function addFootnotes(t)
local function addFootnotes(t)
Line 16: Line 16:
end
end


--- Create a HTML table with details on fish type animals.
-- @return #string HTML table in a string.
-- @author User:Demian
function p.main()
function p.main()
assert(AnimalData.animals, "Failed to data from Module:AnimalData!")
-- Import the data.
local animals = require("Module:AnimalData").animals
-- Table to build the rows to.
local t = { }
-- Sort animals by their name so the generated table will be pre-sorted on page load.
-- Sort animals by their name so the generated table will be pre-sorted on page load.
local sortedNames = Utils.getSortedKeys(AnimalData.animals)
local sortedNames = Utils.getSortedKeys(animals)
-- Table to insert data into.
-- Temporary variable to store animal data in.
local tbl = { "<table class=\"wikitable sortable\">" }
local data;
local maxAttackDelay;
 
-- The following values are left out as rather niche or unclear information.
-- maturity: unclear.
-- headDistance: distance between heads when sleeping in a pack.
-- resourceBonus: unclear.


-- Create the table header.
-- Create the table header.
AnimalUtils.insertAnimalListHeader(tbl)
table.insert(t, "<table class=\"wikitable sortable\">")
 
table.insert(t, "<tr>")
table.insert(t, "<th rowspan=\"3\">Animal</th>")
table.insert(t, "<th colspan=\"5\">Movement</th>")
table.insert(t, "<th colspan=\"2\">Nutrition</th>")
table.insert(t, "<th colspan=\"10\">Hunting</th>")
table.insert(t, string.format("<th rowspan=\"3\">Carbon<br>Released<br>(%s)</th>", HTMLUtils.textUnit_PartsPerMillion()))
table.insert(t, "</tr>")
 
table.insert(t, "<tr>")
-- Header: Movement
table.insert(t, "<th rowspan=\"2\">Swims?</th>")
table.insert(t, "<th rowspan=\"2\">Flies?</th>")
table.insert(t, string.format("<th rowspan=\"2\">Climb<br>Height (%s)</th>", HTMLUtils.textUnit_Meters()))
table.insert(t, string.format("<th colspan=\"2\">Speed (%s)</th>", HTMLUtils.textUnit_MetersPerSecond()))
 
-- Header: Nutrition
table.insert(t, "<th rowspan=\"2\">Eats</th>")
table.insert(t, "<th rowspan=\"2\">Calories</th>")
 
-- Header: Hunting
table.insert(t, "<th rowspan=\"2\">Attacks?</th>")
table.insert(t, "<th rowspan=\"2\">Flees?</th>")
table.insert(t, "<th rowspan=\"2\">Fear<br>Factor</th>")
table.insert(t, "<th rowspan=\"2\">Health</th>")
table.insert(t, string.format("<th rowspan=\"2\">Detect<br>Range (%s)</th>", HTMLUtils.textUnit_Meters()))
table.insert(t, "<th colspan=\"4\">Attack</th>")
table.insert(t, "<th rowspan=\"2\">Harvest Item</th>")
table.insert(t, "</tr>")
 
table.insert(t, "<tr>")
-- Header: Speed
table.insert(t, "<th>Idle</th>")
table.insert(t, "<th>Run</th>")
 
-- Header: Attack
table.insert(t, "<th>Chance (%)</th>")
table.insert(t, string.format("<th>Range (%s)</th>", HTMLUtils.textUnit_Meters()))
table.insert(t, "<th>Damage</th>")
table.insert(t, "<th>Delay</th>")
table.insert(t, "</tr>")


-- Create the table rows.
-- Create the table rows.
for _, animalName in ipairs(sortedNames) do
for _, animalName in ipairs(sortedNames) do
AnimalUtils.insertAnimalListDataRow(tbl, animalName, AnimalData.animals[animalName])
data = animals[animalName]
 
table.insert(t, "<tr>")
table.insert(t, string.format("<td>%s</td>", Utils.formatWikilink(Utils.getDirectPageName(animalName, "animal"), animalName, false)))
 
-- Movement 5 columns
table.insert(t, string.format("<td style=\"text-align:center;\">%s</td>", Utils.formatNilToYesNo(data.isSwimming)))
table.insert(t, string.format("<td style=\"text-align:center;\">%s</td>", Utils.formatNilToYesNo(data.isFlying)))
table.insert(t, string.format("<td style=\"text-align:right;\">%s</td>", AnimalUtils.formatClimbHeight(data.climbHeight)))
table.insert(t, string.format("<td style=\"text-align:right;\">%.1f</td>", Utils.valueOrDash(tonumber(data.wanderingSpeed))))
table.insert(t, string.format("<td style=\"text-align:right;\">%.1f</td>", Utils.valueOrDash(tonumber(data.speed))))
 
-- Nutrition 2 columns
table.insert(t, string.format("<td>%s</td>", AnimalUtils.formatFoodSources(data.foodSources)))
table.insert(t, string.format("<td style=\"text-align:right;\">%s</td>", Utils.valueOrDash(tonumber(data.calorieValue))))
 
-- Hunting 10 columns
maxAttackDelay = tonumber(data.maxAttackDelay)
table.insert(t, string.format("<td style=\"text-align:center;\">%s</td>", Utils.formatBoolToYesNo(0.0 ~= maxAttackDelay and 0.0 ~= tonumber(data.damage))))
table.insert(t, string.format("<td style=\"text-align:center;\">%s</td>", Utils.formatNilToYesNo(data.flees)))
table.insert(t, string.format("<td style=\"text-align:right;\">%.1f</td>", data.fearFactor))
table.insert(t, string.format("<td style=\"text-align:right;\">%.1f</td>", data.health))
table.insert(t, string.format("<td style=\"text-align:right;\">%.1f</td>", data.detectRange))
table.insert(t, string.format("<td style=\"text-align:right;\">%.1f</td>", data.chanceToAttack))
table.insert(t, string.format("<td style=\"text-align:right;\">%.1f</td>", data.attackRange))
table.insert(t, string.format("<td style=\"text-align:right;\">%.1f</td>", data.damage))
 
if 0.0 == maxAttackDelay then
table.insert(t, string.format("<td style=\"text-align:right;\">—</td>"))
else
table.insert(t, string.format("<td style=\"text-align:right;\">%s</td>", Utils.toRangeString(data.minAttackDelay, data.maxAttackDelay, data.minAttackDelay, "%0.1f")))
end
 
if nil == data.resourceItem then
table.insert(t, string.format("<td>—</td>"))
else
table.insert(t, string.format("<td>%s</td>", AnimalUtils.formatResourceItem(data.resourceItem, data.resourceMin, data.resourceMax)))
end
 
table.insert(t, string.format("<td style=\"text-align:right;\">%.4f</td>", data.carbonRelease))
 
table.insert(t, "</tr>")
end
end


table.insert(tbl, "</table>")
table.insert(t, "</table>")


return table.concat(tbl," \n")
return table.concat(t," \n")
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: