Editing Module:UtilsAnimalTables
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 Utils = require("Module:Utils") | local Utils = require("Module:Utils") | ||
local HTMLUtils = require("Module:UtilsHTML") | local HTMLUtils = require("Module:UtilsHTML") | ||
Line 20: | Line 19: | ||
else | else | ||
if parentheses then | if parentheses then | ||
return | return string.format(" (%s)", range) | ||
else | else | ||
return range | return range | ||
Line 37: | Line 36: | ||
if 0.0 < heightNum then | if 0.0 < heightNum then | ||
return | return string.format("%d", heightNum) | ||
elseif 0.0 == heightNum then | elseif 0.0 == heightNum then | ||
-- nil or 0.0 | -- nil or 0.0 | ||
Line 58: | Line 57: | ||
-- @see Util.build_icon | -- @see Util.build_icon | ||
function p.buildResourceItemIcon(imageFileName, link, backgroundColor) | function p.buildResourceItemIcon(imageFileName, link, backgroundColor) | ||
local iconBg = | local iconBg = string.format("icon%s", backgroundColor) | ||
local file = | local file = string.format("[[File:%s|frameless|class=iconRecipe %s|link=%s]]", Utils.checkImage(imageFileName, false), iconBg, link) | ||
return | return string.format("<div class=iconContainerSmall><div class=\"iconStack\">%s</div><div class=\"iconBorder borderBlue\" style=\"position:absolute;\"></div></div>", file) | ||
end | end | ||
Line 73: | Line 72: | ||
if nil == foodCSV then | if nil == foodCSV then | ||
return "—" | return "—" | ||
elseif | elseif string.find(foodCSV, ",") then | ||
return Utils.sortListString(foodCSV, ",", ", ") | return Utils.sortListString(foodCSV, ",", ", ") | ||
else | else | ||
Line 90: | Line 89: | ||
-- @author User:Demian | -- @author User:Demian | ||
function p.formatResourceItem(itemLink, resourceMin, resourceMax) | function p.formatResourceItem(itemLink, resourceMin, resourceMax) | ||
local itemName = | local itemName = string.sub(itemLink, 3, -3) | ||
local actualPageName = Utils.getDirectPageName(itemName, "item") | local actualPageName = Utils.getDirectPageName(itemName, "item") | ||
local countString = p.toCountRange(resourceMin, resourceMax, true) | local countString = p.toCountRange(resourceMin, resourceMax, true) | ||
local linkHTML = | local linkHTML = string.format("%s%s", Utils.formatWikilink(actualPageName, itemName, true), countString) | ||
-- Raw meat seems to be the only exception to the harvest items. It is the only "food" item. | -- Raw meat seems to be the only exception to the harvest items. It is the only "food" item. | ||
Line 128: | Line 127: | ||
-- headDistance: distance between heads when sleeping in a pack. | -- headDistance: distance between heads when sleeping in a pack. | ||
-- resourceBonus: unclear. | -- resourceBonus: unclear. | ||
table.insert(tbl, "<tr>") | table.insert(tbl, "<tr>") | ||
Line 135: | Line 133: | ||
table.insert(tbl, "<th colspan=\"2\">Nutrition</th>") | table.insert(tbl, "<th colspan=\"2\">Nutrition</th>") | ||
table.insert(tbl, "<th colspan=\"10\">Hunting</th>") | table.insert(tbl, "<th colspan=\"10\">Hunting</th>") | ||
table.insert(tbl, | table.insert(tbl, string.format("<th rowspan=\"3\">Carbon<br>Released<br>(%s)</th>", HTMLUtils.textUnit_PartsPerMillion())) | ||
table.insert(tbl, "</tr>") | table.insert(tbl, "</tr>") | ||
Line 142: | Line 140: | ||
table.insert(tbl, "<th rowspan=\"2\">Swims?</th>") | table.insert(tbl, "<th rowspan=\"2\">Swims?</th>") | ||
table.insert(tbl, "<th rowspan=\"2\">Flies?</th>") | table.insert(tbl, "<th rowspan=\"2\">Flies?</th>") | ||
table.insert(tbl, | table.insert(tbl, string.format("<th rowspan=\"2\">Climb<br>Height (%s)</th>", HTMLUtils.textUnit_Meters())) | ||
table.insert(tbl, | table.insert(tbl, string.format("<th colspan=\"2\">Speed (%s)</th>", HTMLUtils.textUnit_MetersPerSecond())) | ||
-- Header: Nutrition | -- Header: Nutrition | ||
Line 154: | Line 152: | ||
table.insert(tbl, "<th rowspan=\"2\">Fear<br>Factor</th>") | table.insert(tbl, "<th rowspan=\"2\">Fear<br>Factor</th>") | ||
table.insert(tbl, "<th rowspan=\"2\">Health</th>") | table.insert(tbl, "<th rowspan=\"2\">Health</th>") | ||
table.insert(tbl, | table.insert(tbl, string.format("<th rowspan=\"2\">Detect<br>Range (%s)</th>", HTMLUtils.textUnit_Meters())) | ||
table.insert(tbl, "<th colspan=\"4\">Attack</th>") | table.insert(tbl, "<th colspan=\"4\">Attack</th>") | ||
table.insert(tbl, "<th rowspan=\"2\">Harvest Item</th>") | table.insert(tbl, "<th rowspan=\"2\">Harvest Item</th>") | ||
Line 166: | Line 164: | ||
-- Header: Attack | -- Header: Attack | ||
table.insert(tbl, "<th>Chance (%)</th>") | table.insert(tbl, "<th>Chance (%)</th>") | ||
table.insert(tbl, | table.insert(tbl, string.format("<th>Range (%s)</th>", HTMLUtils.textUnit_Meters())) | ||
table.insert(tbl, "<th>Damage</th>") | table.insert(tbl, "<th>Damage</th>") | ||
table.insert(tbl, "<th>Delay</th>") | table.insert(tbl, "<th>Delay</th>") | ||
Line 182: | Line 180: | ||
table.insert(tbl, "<tr>") | table.insert(tbl, "<tr>") | ||
table.insert(tbl, | table.insert(tbl, string.format("<td>%s</td>", Utils.formatWikilink(Utils.getDirectPageName(animalName, "animal"), animalName, false))) | ||
-- Movement 5 columns | -- Movement 5 columns | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:center;\">%s</td>", Utils.formatNilToYesNo(data.isSwimming))) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:center;\">%s</td>", Utils.formatNilToYesNo(data.isFlying))) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">%s</td>", p.formatClimbHeight(data.climbHeight))) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", Utils.valueOrDash(tonumber(data.wanderingSpeed)))) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", Utils.valueOrDash(tonumber(data.speed)))) | ||
-- Nutrition 2 columns | -- Nutrition 2 columns | ||
table.insert(tbl, | table.insert(tbl, string.format("<td>%s</td>", p.formatFoodSources(data.foodSources))) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">%s</td>", Utils.valueOrDash(tonumber(data.calorieValue)))) | ||
-- Hunting 10 columns | -- Hunting 10 columns | ||
maxAttackDelay = tonumber(data.maxAttackDelay) | maxAttackDelay = tonumber(data.maxAttackDelay) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:center;\">%s</td>", Utils.formatBoolToYesNo(0.0 ~= maxAttackDelay and 0.0 ~= tonumber(data.damage)))) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:center;\">%s</td>", Utils.formatNilToYesNo(data.flees))) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", data.fearFactor)) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", data.health)) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", data.detectRange)) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", data.chanceToAttack)) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", data.attackRange)) | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", data.damage)) | ||
if 0.0 == maxAttackDelay then | if 0.0 == maxAttackDelay then | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">—</td>")) | ||
else | else | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">%s</td>", Utils.toRangeString(data.minAttackDelay, data.maxAttackDelay, data.minAttackDelay, "%0.1f"))) | ||
end | end | ||
if nil == data.resourceItem then | if nil == data.resourceItem then | ||
table.insert(tbl, | table.insert(tbl, string.format("<td>—</td>")) | ||
else | else | ||
table.insert(tbl, | table.insert(tbl, string.format("<td>%s</td>", p.formatResourceItem(data.resourceItem, data.resourceMin, data.resourceMax))) | ||
end | end | ||
-- Remaining 1 column | -- Remaining 1 column | ||
table.insert(tbl, | table.insert(tbl, string.format("<td style=\"text-align:right;\">%.4f</td>", data.carbonRelease)) | ||
table.insert(tbl, "</tr>") | table.insert(tbl, "</tr>") |