Cookbookdata
Based on game build 7140014 | Last updated: 2026-03-10
Overview
CookbookData is a client-side component that tracks which prepared foods a player has unlocked (via cooking or eating), their recipes, and which dishes were recently discovered (newfoods). It persists unlocked data across sessions using TheSim:SetPersistentString, and supports syncing with online inventory data when available. It works closely with the cooking system to validate recipes and manage data encoding/decoding for storage. This component is intended for use on the player entity to power the in-game cookbook UI.
Usage example
local inst = ThePlayer
inst:AddComponent("cookbookdata")
-- Load persisted data
inst.components.cookbookdata:Load()
-- Learn a newly eaten food
inst.components.cookbookdata:LearnFoodStats("crockpot_stew")
-- Add a newly unlocked recipe (e.g., after cooking)
inst.components.cookbookdata:AddRecipe("crockpot_stew", {"berries", "egg", "honey"})
-- Check discovery status
if inst.components.cookbookdata:IsNewFood("crockpot_stew") then
-- show UI indicator
end
-- Clear flags after UI presentation
inst.components.cookbookdata:ClearNewFlags()
Dependencies & tags
Components used: TheSim, TheInventory, TheFrontEnd, TheNet, cooking
Tags: None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
preparedfoods | table | {} | Map of product_name -> {recipes = {...}, has_eaten = boolean} for all unlocked foods. |
newfoods | table | {} | Set of recently discovered products (consumed but not yet presented in UI). |
filters | table | {} | User-applied filter state for cookbook UI (e.g., "category" -> value). |
dirty | boolean | false | Flag indicating local unsaved changes. |
save_enabled | boolean | Not set (nil) | Controls whether :Save() writes data (controlled externally via self.save_enabled). |
synced | boolean | false | Indicates whether online inventory data has been applied via :ApplyOnlineProfileData(). |
Main functions
GetKnownPreparedFoods()
- Description: Returns the internal table of all unlocked prepared foods.
- Parameters: None.
- Returns:
table— Map of product names to recipe metadata ({recipes, has_eaten}).
Save(force_save)
- Description: Persists current state to disk using
TheSim:SetPersistentString, but only ifforce_saveistrueor (save_enabledanddirty). - Parameters:
force_save(boolean) — Bypasssave_enabledanddirtychecks. - Returns: Nothing.
- Error states: No explicit error handling; relies on
TheSimfor persistence.
Load()
- Description: Loads persisted cookbook data from disk. On parse failure, attempts recovery via
:ApplyOnlineProfileData()and clears data if both fail. - Parameters: None.
- Returns: Nothing.
ApplyOnlineProfileData()
- Description: Fills
preparedfoodsfrom online inventory data (viaTheInventory:GetLocalCookBook()), using decoding helpers. Only executes if online mode and inventory is available. - Parameters: None.
- Returns:
boolean—trueif online data was successfully applied. - Error states: Returns
falseif online sync is not available orTheInventorylacks data.
LearnFoodStats(product)
- Description: Records that the player has eaten a food (
has_eaten = true), marks it asnewfoods, and triggers network and disk persistence. - Parameters:
product(string) — The prepared food name (e.g.,"crockpot_stew"). - Returns:
boolean—trueif new data was recorded (has_eatenchanged), otherwisefalse. - Error states: Silently returns
falseifproductis invalid or not incooking.cookbook_recipes.
AddRecipe(product, ingredients)
- Description: Adds or updates a recipe for a prepared food, up to
MAX_RECIPES = 6. Moves new recipes to the front and deduplicates if already known. - Parameters:
product(string) — Prepared food name.ingredients(table of strings) — Ordered list of ingredient names.
- Returns:
boolean—trueif the recipe list changed, otherwisefalse. - Error states: Silently returns
falseifproductoringredientsisnilor invalid. Normalizes ingredient names by stripping"cooked"/"_cooked_"suffixes before storage.
IsNewFood(product)
- Description: Checks if the food was recently discovered (i.e., in
newfoods). - Parameters:
product(string) — Prepared food name. - Returns:
boolean—trueif recently discovered.
ClearNewFlags()
- Description: Clears all
newfoodsentries (typically after presenting them in UI). - Parameters: None.
- Returns: Nothing.
ClearFilters()
- Description: Resets all filter settings and marks data as dirty.
- Parameters: None.
- Returns: Nothing.
SetFilter(category, value)
- Description: Sets a UI filter value for a given category (e.g.,
"type","difficulty"), marking data as dirty on change. - Parameters:
category(string) — Filter key.value(any) — Filter value.
- Returns: Nothing.
GetFilter(category)
- Description: Returns the current value of a UI filter.
- Parameters:
category(string) — Filter key. - Returns:
any— Current filter value ornil.
IsUnlocked(product)
- Description: Checks if a prepared food is unlocked (exists in
preparedfoods). - Parameters:
product(string) — Prepared food name. - Returns:
boolean—trueif unlocked.
IsValidEntry(product)
- Description: Validates that
productis a known recipe in thecooking.cookbook_recipestable. - Parameters:
product(string) — Prepared food name. - Returns:
boolean—trueif valid.
RemoveCookedFromName(ingredients)
- Description: Normalizes ingredient names by stripping
"cooked","_cooked_", etc., from strings in the list. - Parameters:
ingredients(table of strings) — Raw ingredient names. - Returns:
table of strings— Normalized ingredient names.
Events & listeners
- Listens to: None identified.
- Pushes: None identified.