« Module:FoodDetails » : différence entre les versions

De Eco - Wiki Français
Aller à :navigation, rechercher
[version vérifiée][version vérifiée]
Page créée avec « local p = {} function p.main() local wiki = '' -- import the required modules local itemData = mw.loadData( "Module:ItemData" ) local recipeData = mw.loadData( "Module:RecipeData" ) local plantData = mw.loadData( "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 "... »
 
Aucun résumé des modifications
 
Ligne 2 : Ligne 2 :


function p.main()
function p.main()
local wiki = ''
local wiki = ''
 
-- import the required modules
-- import the required modules
local itemData = mw.loadData( "Module:ItemData" )
local itemData = mw.loadData("Module:ItemData")
local recipeData = mw.loadData( "Module:RecipeData" )
local recipeData = mw.loadData("Module:RecipeData")
local plantData = mw.loadData( "Module:PlantData" )
local plantData = mw.loadData("Module:PlantData")
 
-- assign modules for use
-- assign modules for use
local items = itemData.items
local items = itemData.items
local recipes = recipeData.recipes
local recipes = recipeData.recipes
local plants = plantData.plants
local plants = plantData.plants
 
-- create the header of the table
-- table header
local header = "<table class=\"wikitable sortable\"> \n "
local header = [=[
header = header .. "<tr> \n "
<table class="wikitable sortable">
header = header .. "<th>Food</th> \n "
<tr>
header = header .. "<th>Calories</th> \n "
<th>Food</th>
header = header .. "<th data-sort-type=\"descending\" style=\"color: red;\">Carbs</th> \n "
<th>Calories</th>
header = header .. "<th style=\"color: orange;\">Protein</th> \n "
<th data-sort-type="number" style="color: red;">Carbs</th>
header = header .. "<th style=\"color: yellow;\">Fat</th> \n "
<th style="color: orange;">Protein</th>
header = header .. "<th style=\"color: lightgreen;\">Vitamins</th> \n "
<th style="color: yellow;">Fat</th>
header = header .. "<th>Nutrition</th> \n "
<th style="color: lightgreen;">Vitamins</th>
header = header .. "<th>Density (/100kcal)</th> \n "
<th>Nutrition</th>
header = header .. "<th>Skill Point Contribution</th> \n "
<th>Density (/100kcal)</th>
header = header .. "<th>Created With</th> \n "
<th>Skill Point Contribution</th>
header = header .. "<th>Skill Needed</th> \n "
<th>Created With</th>
header = header .. "<th>Skill Level</th> \n "
<th>Skill Needed</th>
header = header .. "<th data-sort-type=\"number\">Base Crafting Time(Min)</th> \n "
<th>Skill Level</th>
header = header .. "</tr> \n "
<th data-sort-type="number">Base Crafting Time (Min)</th>
</tr>
wiki = header
]=]
 
for k,v in pairs(items) do
wiki = wiki .. header
local row = ''
 
if v.group == 'Food' then
for itemName, v in pairs(items) do
--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
if v.group == "Food" then
local item = k
local row = "<tr>\n"
row = row .. "<tr> \n "
 
local nutrition = v.vitamins + v.carbs + v.protein + v.fat
-- nutrition
local sp_contribution = nutrition * v.calories
local nutrition = (v.vitamins or 0) + (v.carbs or 0) + (v.protein or 0) + (v.fat or 0)
local sp_contribution = nutrition * (v.calories or 0)
-- print name, calories, carbs, protein, fat, vitamins, nutrition and skill point contribution from ItemData.
 
row = row .. "<td> [[" .. item .. "]] </td> \n"
row = row .. "<td> [[" .. itemName .. "]] </td>\n"
row = row .. "<td>" .. v.calories .. " </td> \n"  
row = row .. "<td>" .. (v.calories or 0) .. "</td>\n"
row = row .. "<td>" .. v.carbs .. "</td> \n"  
row = row .. "<td>" .. (v.carbs or 0) .. "</td>\n"
row = row .. "<td>" .. v.protein .. "</td> \n"  
row = row .. "<td>" .. (v.protein or 0) .. "</td>\n"
row = row .. "<td>" .. v.fat .. "</td> \n"
row = row .. "<td>" .. (v.fat or 0) .. "</td>\n"
row = row .. "<td>" .. v.vitamins .. "</td> \n"
row = row .. "<td>" .. (v.vitamins or 0) .. "</td>\n"
row = row .. "<td>" .. nutrition .. "</td> \n"
row = row .. "<td>" .. nutrition .. "</td>\n"
row = row .. "<td>" .. v.density .. "</td> \n"
row = row .. "<td>" .. (v.density or 0) .. "</td>\n"
row = row .. "<td>" .. sp_contribution .. "</td> \n"
row = row .. "<td>" .. sp_contribution .. "</td>\n"
 
local created = ''
------------------------------------------------------------------
local skill = ''
-- FIND SOURCE: recipe or plant
local skill_level = ''
------------------------------------------------------------------
local baseCraftTime = ''
 
local baseLaborCost = ''
local created = "-"
local baseXPGain = ''
local skill = "-"
local recipe = ''
local skill_level = "-"
local plant = ''
local baseCraftTime = "-"
if recipes[item] ~= nil then
 
recipe = recipes[item]  -- implies food item is created via a recipe with the item's name
local recipe = recipes[itemName]
-- else
local plant = nil
-- for key,val in pairs(recipes) do
 
-- for numx =  1, #val.variants[item].products and val.variants ~= '' do
-- 1) RECIPE FOUND
-- if val.variants[item].products[numx][1] == item then
if recipe then
-- recipe = val  -- implies food item is created via a differently named recipe (issue: selects the first found recipe)
if recipe.craftStn and recipe.craftStn[1] then
-- end
created = "[[" .. recipe.craftStn[1][1] .. "]]"
-- end
end
-- end
 
end
if recipe.skillNeeds and recipe.skillNeeds[1] then
if recipe ~= '' then
skill = "[[" .. recipe.skillNeeds[1][1] .. "]]"
created = recipe.craftStn[1][1]
skill_level = tonumber(recipe.skillNeeds[1][2]) or "-"
if recipe.skillNeeds[1] == nil then
skill = "none" -- implies a basic recipe like Campfire Beans
skill_level = '-'
else
else
skill = recipe.skillNeeds[1][1] -- implies a "normal" recipe like Fiddlehead Salad that has a skill requirement
skill = "none"
skill_level = tonumber(recipe.skillNeeds[1][2])
skill_level = "-"
end
end
baseCraftTime = tonumber(recipe.baseCraftTime)
baseCraftTime = tonumber(recipe.baseCraftTime)
if baseCraftTime == 0 then
if not baseCraftTime or baseCraftTime == 0 then
baseCraftTime = '?'  -- it looks like many foods have erroneous 0 baseCraftTime, so these are explicitly marked suspect
baseCraftTime = "?"
end
end
else
else
for key,val in pairs(plants) do  
-- 2) NO RECIPE → CHECK PLANT
if val.resourceItem == '[[' .. item .. ']]' then
for _, plantInfo in pairs(plants) do
plant = val  --implies food item is harvested from a plant
if plantInfo.resourceItem == "[[" .. itemName .. "]]" then
plant = plantInfo
break
end
end
end
end
if plant ~= '' then
 
skill = "Gathering"
if plant then
skill = "[[Gathering]]"
skill_level = 0
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
if plant.harvestTool and plant.killOnHarvest == "Yes" then
created = "[[" .. plant.harvestTool .. "]]"
else
else
created = "none" --implies a plant gathered like beets or huckleberry, even if the plant can be destroyed with a tool
created = "none"
end
end
baseCraftTime = 0
baseCraftTime = 0
else
--implies food item not created via a recipe or a plant
created = "-"
skill = "-"
skill_level = "-"
baseCraftTime = "-"
end
end
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>" .. baseCraftTime .. "</td> \n"
row = row .. "</tr>"


row = row .. "<td>" .. created .. "</td>\n"
row = row .. "<td>" .. skill .. "</td>\n"
row = row .. "<td>" .. skill_level .. "</td>\n"
row = row .. "<td>" .. baseCraftTime .. "</td>\n"
row = row .. "</tr>\n"


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


return p
return p

Dernière version du 19 novembre 2025 à 01:24

Ce module fournit la fonctionnalité back-end du Template:FoodDetails.

Si le modèle est utilisé, ce module crée un tableau en utilisant les informations provenant des modules suivants :


local p = {}

function p.main()
	local wiki = ''

	-- import the required modules
	local itemData = mw.loadData("Module:ItemData")
	local recipeData = mw.loadData("Module:RecipeData")
	local plantData = mw.loadData("Module:PlantData")

	-- assign modules for use
	local items = itemData.items
	local recipes = recipeData.recipes
	local plants = plantData.plants

	-- table header
	local header = [=[
<table class="wikitable sortable">
<tr>
<th>Food</th>
<th>Calories</th>
<th data-sort-type="number" style="color: red;">Carbs</th>
<th style="color: orange;">Protein</th>
<th style="color: yellow;">Fat</th>
<th style="color: lightgreen;">Vitamins</th>
<th>Nutrition</th>
<th>Density (/100kcal)</th>
<th>Skill Point Contribution</th>
<th>Created With</th>
<th>Skill Needed</th>
<th>Skill Level</th>
<th data-sort-type="number">Base Crafting Time (Min)</th>
</tr>
]=]

	wiki = wiki .. header

	for itemName, v in pairs(items) do
		if v.group == "Food" then
			local row = "<tr>\n"

			-- nutrition
			local nutrition = (v.vitamins or 0) + (v.carbs or 0) + (v.protein or 0) + (v.fat or 0)
			local sp_contribution = nutrition * (v.calories or 0)

			row = row .. "<td> [[" .. itemName .. "]] </td>\n"
			row = row .. "<td>" .. (v.calories or 0) .. "</td>\n"
			row = row .. "<td>" .. (v.carbs or 0) .. "</td>\n"
			row = row .. "<td>" .. (v.protein or 0) .. "</td>\n"
			row = row .. "<td>" .. (v.fat or 0) .. "</td>\n"
			row = row .. "<td>" .. (v.vitamins or 0) .. "</td>\n"
			row = row .. "<td>" .. nutrition .. "</td>\n"
			row = row .. "<td>" .. (v.density or 0) .. "</td>\n"
			row = row .. "<td>" .. sp_contribution .. "</td>\n"

			------------------------------------------------------------------
			-- FIND SOURCE: recipe or plant
			------------------------------------------------------------------

			local created = "-"
			local skill = "-"
			local skill_level = "-"
			local baseCraftTime = "-"

			local recipe = recipes[itemName]
			local plant = nil

			-- 1) RECIPE FOUND
			if recipe then
				if recipe.craftStn and recipe.craftStn[1] then
					created = "[[" .. recipe.craftStn[1][1] .. "]]"
				end

				if recipe.skillNeeds and recipe.skillNeeds[1] then
					skill = "[[" .. recipe.skillNeeds[1][1] .. "]]"
					skill_level = tonumber(recipe.skillNeeds[1][2]) or "-"
				else
					skill = "none"
					skill_level = "-"
				end

				baseCraftTime = tonumber(recipe.baseCraftTime)
				if not baseCraftTime or baseCraftTime == 0 then
					baseCraftTime = "?"
				end

			else
				-- 2) NO RECIPE → CHECK PLANT
				for _, plantInfo in pairs(plants) do
					if plantInfo.resourceItem == "[[" .. itemName .. "]]" then
						plant = plantInfo
						break
					end
				end

				if plant then
					skill = "[[Gathering]]"
					skill_level = 0

					if plant.harvestTool and plant.killOnHarvest == "Yes" then
						created = "[[" .. plant.harvestTool .. "]]"
					else
						created = "none"
					end

					baseCraftTime = 0
				end
			end

			------------------------------------------------------------------

			row = row .. "<td>" .. created .. "</td>\n"
			row = row .. "<td>" .. skill .. "</td>\n"
			row = row .. "<td>" .. skill_level .. "</td>\n"
			row = row .. "<td>" .. baseCraftTime .. "</td>\n"
			row = row .. "</tr>\n"

			wiki = wiki .. row
		end
	end

	wiki = wiki .. "</table>"
	return wiki
end

return p