Editing Module:Table Animals
From Eco - English Wiki
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 | local HTMLUtils = require("Module:UtilsHTML") | ||
local function addFootnotes(t) | local function addFootnotes(t) | ||
Line 16: | Line 16: | ||
end | end | ||
function p.main() | function p.main() | ||
-- 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( | local sortedNames = Utils.getSortedKeys(animals) | ||
-- | -- Temporary variable to store animal data in. | ||
local | 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. | ||
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. | 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( | table.insert(t, "</table>") | ||
return table.concat( | return table.concat(t," \n") | ||
end | end | ||
return p | return p |