ATTENTION! The process of updating WiKi to version Eco 10.x has begun. Those wishing to participate can find out more Information on our ECO Contribution Wiki Discord.
From April 26 to May 12, errors may occur in the Wiki, as we will be carrying out a major update to the information processing modules.

Module:Table Animals

From Eco - English Wiki
Revision as of 01:12, 26 February 2022 by Demian (talk | contribs) (Demian moved page Module:List Animals to Module:Table Animals without leaving a redirect: Consistent naming: list to table.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:Template backend It creates an HTML table with data from Module:AnimalData

This module uses the following modules:


local p = {}
local Utils = require("Module:Utils")
local AnimalUtils = require("Module:UtilsAnimalTables")
local AnimalData = mw.loadData("Module:AnimalData")

local function addFootnotes(t)
	-- Sadly I could not find a way to add HTML to the table header generated with the Lua code below.
	-- <a id=\"cite_ref-1\" class=\"reference\" href=\"#cite_note-1\">[1]</a>
	-- <a id=\"cite_ref-2\" class=\"reference\" href=\"#cite_note-2\">[2]</a>
	table.insert(t, "<strong>Footnotes</strong>")
	table.insert(t, "<div class=\"mw-references-wrap\">")
	table.insert(t, "<ol class=\"references\">")
	table.insert(t, "<li id=\"cite_note-1\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-1\" aria-label=\"Jump up\" title=\"Jump up\">&uarr;</a></span> <span class=\"reference-text\">Calories consumed by predator animals who eat this animal. Not applicable to players, see the <strong>Harvest Item</strong> column for details on the player consumable food items.</span></li>")
	table.insert(t, "<li id=\"cite_note-2\"><span class=\"mw-cite-backlink\"><a href=\"#cite_ref-2\" aria-label=\"Jump up\" title=\"Jump up\">&uarr;</a></span> <span class=\"reference-text\">The minimum and maximum delay between attacks. Lower values equal faster attacks.</span></li>")
	table.insert(t, "</ol></div>")
end

--- Create a HTML table with details on fish type animals.
-- @return #string HTML table in a string.
-- @author User:Demian
function p.main()
	assert(AnimalData.animals, "Failed to data from Module:AnimalData!")
	
	-- Sort animals by their name so the generated table will be pre-sorted on page load.
	local sortedNames = Utils.getSortedKeys(AnimalData.animals)
	-- Table to insert data into.
	local tbl = { "<table class=\"wikitable sortable\">" }

	-- Create the table header.
	AnimalUtils.insertAnimalListHeader(tbl)

	-- Create the table rows.
	for _, animalName in ipairs(sortedNames) do
		AnimalUtils.insertAnimalListDataRow(tbl, animalName, AnimalData.animals[animalName])
	end

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

	return table.concat(tbl," \n")
end

return p