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:FoodDetails: Difference between revisions

From Eco - English Wiki
[unchecked revision][unchecked revision]
m (Reverted edits by Nesphit (talk) to last revision by ZeelNightwolf)
 
m (1 revision imported)
(No difference)

Revision as of 23:18, 6 December 2019

Documentation

This module provides the back end functionality of the Template:FoodDetails.

If the template is passed, this module creates a table using details from the following Modules:


local p = {}

function p.main()
	local wiki = ''	
	
	-- import the required modules
	local itemData = require( "Module:ItemData" )	
	local recipeData = require( "Module:CraftingRecipes" )
	local plantData = require( "Module:PlantData" )
	
	-- assign modules for use
	local items = itemData.items
	local recipes = recipeData.recipes
	local plants = plantData.plants
	
	-- create the header of the table
	local header = "<table class=\"wikitable sortable\"> \n " 
	header = header .. "<tr> \n "
	header = header .. "<th>Food</th> \n "
	header = header .. "<th>Calories</th> \n "
	header = header .. "<th data-sort-type=\"descending\" style=\"color: red;\">Carbs</th> \n "
	header = header .. "<th style=\"color: orange;\">Protein</th> \n "
	header = header .. "<th style=\"color: yellow;\">Fat</th> \n "
	header = header .. "<th style=\"color: lightgreen;\">Vitamins</th> \n "
	header = header .. "<th>Nutrition</th> \n "
	header = header .. "<th>Density (/100kcal)</th> \n "
	header = header .. "<th>Skill Point Contribution</th> \n "
	header = header .. "<th>Created With</th> \n "
	header = header .. "<th>Skill Needed</th> \n "
	header = header .. "<th>Skill Level</th> \n "
	header = header .. "<th data-sort-type=\"number\">Minutes Crafting</th> \n "
	header = header .. "</tr> \n "
	
	wiki = header
	
	for k,v in pairs(items) do
		local row = ''
		if v.group == 'Food' then
--if (k == "Basic Salad" or k == "Fiddlehead Salad" or k == "Bear S U P R E M E" or k == "Charred Tomato" or k == "Tallow" or k == "Beet" or k == "Campfire Beans" or k == "Wheat") then
			local item = k
			row = row .. "<tr> \n "
			local nutrition = v.vitamins + v.carbs + v.protein + v.fat
			local sp_contribution = nutrition * v.calories
			
			-- print name, calories, carbs, protein, fat, vitamins, nutrition and skill point contribution from ItemData.
			row = row .. "<td> [[" .. item .. "]] </td> \n"
			row = row .. "<td>" .. v.calories .. " </td> \n" 
			row = row .. "<td>" .. v.carbs .. "</td> \n" 
			row = row .. "<td>" .. v.protein .. "</td> \n" 
			row = row .. "<td>" .. v.fat .. "</td> \n"
			row = row .. "<td>" .. v.vitamins .. "</td> \n"
			row = row .. "<td>" .. nutrition .. "</td> \n"
			row = row .. "<td>" .. v.density .. "</td> \n"			
			row = row .. "<td>" .. sp_contribution .. "</td> \n"
			
			local created = ''
			local skill = ''
			local skill_level = ''
			local ctime = ''
			local recipe = ''
			local plant = ''
			if recipes[item] ~= nil then
				recipe = recipes[item]  -- implies food item is created via a recipe with the item's name
			else
				for key,val in pairs(recipes) do
					for numx =  1, #val.products do
						if val.products[numx][1] == item then
							recipe = val  -- implies food item is created via a differently named recipe (issue: selects the first found recipe)
						end
					end	
				end
			end
			if recipe ~= '' then
				created = recipe.craftStn[1]
				if recipe.skillNeeds[1] == nil then
					skill = "none"  -- implies a basic recipe like Campfire Beans
					skill_level = '-'
				else
					skill = recipe.skillNeeds[1][1] -- implies a "normal" recipe like Fiddlehead Salad that has a skill requirement
					skill_level = tonumber(recipe.skillNeeds[1][2])
				end
				ctime = tonumber(recipe.ctime)
				if ctime == 0 then
					ctime = '?'  -- it looks like many foods have erroneous 0 ctime, so these are explicitly marked suspect
				end
			else
				for key,val in pairs(plants) do 
					if val.resourceItem == '[[' .. item .. ']]' then
						plant = val  --implies food item is harvested from a plant
					end
				end
				if plant ~= '' then
					skill = "Gathering"
					skill_level = 0
					if (plant.harvestTool ~= nil and plant.killOnHarvest == 'Yes') then
						created = plant.harvestTool  --implies a plant like wheat that must be destroyed with a tool 
					else
						created = "none"  --implies a plant gathered like beets or huckleberry, even if the plant can be destroyed with a tool
					end
					ctime = 0
				else
					--implies food item not created via a recipe or a plant
					created = "-"
					skill = "-"
					skill_level = "-"
					ctime = "-"
				end
			end

			if (skill ~= '' and skill ~= 'none' and skill ~= '-') then
				skill = "[[" .. skill .. "]]"
			end

			if (created ~= '' and created ~= 'none' and created ~= '-') then
				created = "[[" .. created .. "]]"
			end
			
			-- print the icon or none for the found created.
			row = row .. "<td>" .. tostring(created) .. "</td> \n"
			
			-- print skill needed or none.
			row = row .. "<td>" .. tostring(skill) .. "</td> \n"
			
			-- print skill level needed.
			row = row .. "<td>" .. tostring(skill_level) .. "</td> \n"
			
			-- print crafting minutes.
			row = row .. "<td>" .. ctime .. "</td> \n" 
			row = row .. "</tr>"


			--print(item)
			--print(tostring(created))
			--print(tostring(skill))
			--print(tostring(skill_level))
			--print(tostring(ctime))
			--print("")
			
--end
		end
		
		-- add row created to table.
		wiki = wiki .. row
		
	end
	wiki = wiki .. " </table>"
	return wiki
end

return p