Editing Module:UtilsAnimalTables

From Eco - English Wiki

Your changes will be displayed to readers once an authorized user accepts them. (help)

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 1: Line 1:
local p = {}
local p = {}
local Utils = require("Module:Utils")
local Utils = require("Module:Utils")
local Unit = require("Module:Unit")
local HTMLUtils = require("Module:UtilsHTML")
local HTMLUtils = require("Module:UtilsHTML")


Line 20: Line 19:
else
else
if parentheses then
if parentheses then
return mw.ustring.format(" (%s)", range)
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 mw.ustring.format("%d", heightNum)
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 = mw.ustring.format("icon%s", backgroundColor)
local iconBg = string.format("icon%s", backgroundColor)
local file = mw.ustring.format("[[File:%s|frameless|class=iconRecipe %s|link=%s]]", Utils.checkImage(imageFileName, false), iconBg, link)
local file = string.format("[[File:%s|frameless|class=iconRecipe %s|link=%s]]", Utils.checkImage(imageFileName, false), iconBg, link)
return mw.ustring.format("<div class=iconContainerSmall><div class=\"iconStack\">%s</div><div class=\"iconBorder borderBlue\" style=\"position:absolute;\"></div></div>", file)
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 mw.ustring.find(foodCSV, ",") then
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 = mw.ustring.sub(itemLink, 3, -3)
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 = mw.ustring.format("%s%s", Utils.formatWikilink(actualPageName, itemName, true), countString)
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.
local meterAbbr = Unit._unit(nil, "m", true)
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, mw.ustring.format("<th rowspan=\"3\">Carbon<br>Released<br>(%s)</th>", Unit._unit(nil, "ppm", true)))
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, mw.ustring.format("<th rowspan=\"2\">Climb<br>Height (%s)</th>", meterAbbr))
table.insert(tbl, string.format("<th rowspan=\"2\">Climb<br>Height (%s)</th>", HTMLUtils.textUnit_Meters()))
table.insert(tbl, mw.ustring.format("<th colspan=\"2\">Speed (%s)</th>", Unit._unit(nil, "m/s", true)))
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, mw.ustring.format("<th rowspan=\"2\">Detect<br>Range (%s)</th>", meterAbbr))
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, mw.ustring.format("<th>Range (%s)</th>", meterAbbr))
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, mw.ustring.format("<td>%s</td>", Utils.formatWikilink(Utils.getDirectPageName(animalName, "animal"), animalName, false)))
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, mw.ustring.format("<td style=\"text-align:center;\">%s</td>", Utils.formatNilToYesNo(data.isSwimming)))
table.insert(tbl, string.format("<td style=\"text-align:center;\">%s</td>", Utils.formatNilToYesNo(data.isSwimming)))
table.insert(tbl, mw.ustring.format("<td style=\"text-align:center;\">%s</td>", Utils.formatNilToYesNo(data.isFlying)))
table.insert(tbl, string.format("<td style=\"text-align:center;\">%s</td>", Utils.formatNilToYesNo(data.isFlying)))
table.insert(tbl, mw.ustring.format("<td style=\"text-align:right;\">%s</td>", p.formatClimbHeight(data.climbHeight)))
table.insert(tbl, string.format("<td style=\"text-align:right;\">%s</td>", p.formatClimbHeight(data.climbHeight)))
table.insert(tbl, mw.ustring.format("<td style=\"text-align:right;\">%.1f</td>", Utils.valueOrDash(tonumber(data.wanderingSpeed))))
table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", Utils.valueOrDash(tonumber(data.wanderingSpeed))))
table.insert(tbl, mw.ustring.format("<td style=\"text-align:right;\">%.1f</td>", Utils.valueOrDash(tonumber(data.speed))))
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, mw.ustring.format("<td>%s</td>", p.formatFoodSources(data.foodSources)))
table.insert(tbl, string.format("<td>%s</td>", p.formatFoodSources(data.foodSources)))
table.insert(tbl, mw.ustring.format("<td style=\"text-align:right;\">%s</td>", Utils.valueOrDash(tonumber(data.calorieValue))))
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, mw.ustring.format("<td style=\"text-align:center;\">%s</td>", Utils.formatBoolToYesNo(0.0 ~= maxAttackDelay and 0.0 ~= tonumber(data.damage))))
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, mw.ustring.format("<td style=\"text-align:center;\">%s</td>", Utils.formatNilToYesNo(data.flees)))
table.insert(tbl, string.format("<td style=\"text-align:center;\">%s</td>", Utils.formatNilToYesNo(data.flees)))
table.insert(tbl, mw.ustring.format("<td style=\"text-align:right;\">%.1f</td>", data.fearFactor))
table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", data.fearFactor))
table.insert(tbl, mw.ustring.format("<td style=\"text-align:right;\">%.1f</td>", data.health))
table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", data.health))
table.insert(tbl, mw.ustring.format("<td style=\"text-align:right;\">%.1f</td>", data.detectRange))
table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", data.detectRange))
table.insert(tbl, mw.ustring.format("<td style=\"text-align:right;\">%.1f</td>", data.chanceToAttack))
table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", data.chanceToAttack))
table.insert(tbl, mw.ustring.format("<td style=\"text-align:right;\">%.1f</td>", data.attackRange))
table.insert(tbl, string.format("<td style=\"text-align:right;\">%.1f</td>", data.attackRange))
table.insert(tbl, mw.ustring.format("<td style=\"text-align:right;\">%.1f</td>", data.damage))
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, mw.ustring.format("<td style=\"text-align:right;\">—</td>"))
table.insert(tbl, string.format("<td style=\"text-align:right;\">—</td>"))
else
else
table.insert(tbl, mw.ustring.format("<td style=\"text-align:right;\">%s</td>", Utils.toRangeString(data.minAttackDelay, data.maxAttackDelay, data.minAttackDelay, "%0.1f")))
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, mw.ustring.format("<td>—</td>"))
table.insert(tbl, string.format("<td>—</td>"))
else
else
table.insert(tbl, mw.ustring.format("<td>%s</td>", p.formatResourceItem(data.resourceItem, data.resourceMin, data.resourceMax)))
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, mw.ustring.format("<td style=\"text-align:right;\">%.4f</td>", data.carbonRelease))
table.insert(tbl, string.format("<td style=\"text-align:right;\">%.4f</td>", data.carbonRelease))


table.insert(tbl, "</tr>")
table.insert(tbl, "</tr>")
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: