Cooking Ingredients - UQcsse3200/2024-studio-3 GitHub Wiki
This documentation outlines the functionality, integration, and configuration of the CookIngredientComponent and ChopIngredientComponent within the game. These components are responsible for managing the cooking and chopping processes of ingredients, ensuring they are processed correctly according to the game’s mechanics.
The components are responsible for managing the duration of cooking or chopping, determining when these processes are complete, and handling the interaction between different game entities. The components interact with other classes such as IngredientComponent, StationItemHandlerComponent, GameTime, and configuration classes like ChopIngredientConfig and CookIngredientConfig. Additionally, the configuration files ingredientCookTimes.json and IngredientsChopTimes.json provide the necessary data for cooking and chopping times. The following sections provide a detailed overview of each component, its purpose, and its integration within the game.
-
CookIngredientComponent: Manages the cooking process of ingredients. It tracks the timing when the ingredient has been taken out to update the state to cooked, or if it exceeds the cook time to update the state to burnt. -
ChopIngredientComponent: Manages the chopping process of ingredients. It tracks the duration of chopping, ensures the process is completed, and updates the ingredient’s state to "chopped."
The CookIngredientComponent is responsible for managing the entire cooking process of an ingredient within the game. This component works by tracking the cooking duration, determining the cooking status (e.g., raw, cooked, burnt), and updating the ingredient’s state accordingly. The cooking process can vary depending on the type of cooking station (e.g., "COOK_TOP", "OVEN") and any multipliers that affect cooking speed (e.g., for an oven). The component is designed to integrate with the game's time management system, ensuring that the cooking process reflects the real passage of in-game time.
-
ingredient(IngredientComponent): A reference to the IngredientComponent associated with the entity being cooked. This attribute holds the current ingredient being processed and is used to retrieve and update the ingredient’s state (e.g., from raw to cooked). -
timesource(GameTime): This attribute represents the time-tracking service provided by the game. It is used to calculate the cooking duration and determine when the cooking process should start, finish, or when an ingredient might burn. -
isCooking(boolean): A flag that indicates whether the cooking process is currently active. When true, the component continuously checks the cooking progress in each frame -
cookEndTime(long): The exact in-game time (in milliseconds) when the cooking process is expected to complete. This is calculated based on the current time and the ingredient's required cooking time, possibly modified by station-specific multipliers.
-
create(): Initializes theCookIngredientComponentwhen the game entity is created. This method sets up the necessary event listeners that respond to in-game events, such as starting or stopping the cooking process.
-
update(): This method is called every frame to check the current state of the cooking process. It calculates the elapsed time since the cooking started usingGameTime, and updates the ingredient's state accordingly. If the cooking time has passed, the ingredient's state is updated to "cooked". If additional time passes, the ingredient may be marked as "burnt".

-
cookIngredient(String stationState, int oven_multiplier): This method initiates the cooking process for the ingredient. It calculates thecookEndTimeby adding the ingredient’s cooking duration to the current time, factoring in the stationState (e.g., "HOT", "NORMAL", "WARM") and the oven_multiplier if the cooking is being done in an oven. For example, a "HOT" station with a higher oven multiplier will cook the ingredient faster.
-
stopCookingIngredient(): Stops the cooking process by setting theisCookingflag to false. This method is typically called when the ingredient is removed from the cooking station or when the cooking is manually stopped. -
getIsCooking(): boolean: Returns the current status of the cooking process. It checks whether the ingredient is still being cooked or if the process has been stopped.
Similar to the CookIngredientComponent, ChopIngredientComponent is a crucial component in the game that manages the chopping process for ingredients. This component is responsible for tracking the time an ingredient spends being chopped, determining when the chopping is complete, and updating the ingredient's state to reflect its new status (e.g., from whole to chopped). The chopping process is controlled by the in-game time, ensuring that the ingredient is processed for the correct duration before it is marked as chopped. This component is tightly integrated with the IngredientComponent, which holds the state of the ingredient, and the GameTime class, which provides the current in-game time.
-
ingredient(IngredientComponent): A reference to theIngredientComponentassociated with the entity being chopped. This attribute is essential for retrieving the ingredient's chop time and updating its state to "chopped" once the process is complete. The ingredient attribute links the chopping process to the specific ingredient being processed. -
timesource(GameTime): This attribute represents the game’s time management system, provided by theGameTimeclass. The timesource is used to calculate the exact start and end times of the chopping process, ensuring that the chopping duration is accurately tracked according to the game's passage of time. -
isChopping(boolean): A flag that indicates whether the chopping process is currently in progress. WhenisChoppingis true, the component actively monitors the chopping process, checking the elapsed time in each game frame. -
chopEndTime(long): This attribute stores the specific in-game time (in milliseconds) when the chopping process is expected to be completed. ThechopEndTimeis calculated by adding the ingredient's chopping duration (retrieved from ChopIngredientConfig or ingredientChopTimes) to the current game time when the chopping starts.
-
create(): This method is called when theChopIngredientComponentis first initialized as part of the entity's creation process. It sets up the necessary event listeners that will respond to in-game events, such as when an ingredient is placed on a chopping station or when chopping should start or stop. Thecreate()method ensures that the component is properly integrated into the game’s event system.

-
update(): Theupdate()method is called every frame to monitor the chopping process. It checks whether the current game time has reached or exceeded thechopEndTime. If the chopping time has been met, the method triggers thechopItem()function on theIngredientComponent, changing the ingredient's state to "chopped." This method is critical for ensuring that the chopping process is accurately timed and that the ingredient's state is updated as soon as the chopping is complete.

-
chopIngredient(): This method begins the chopping process for the ingredient. It calculates thechopEndTimebased on the current time provided by theGameTimeclass and the chopping duration specified for the ingredient. The duration is usually retrieved from theChopIngredientConfig, which holds the chopping times for different ingredients. Once thechopEndTimeis set, theisChoppingflag is set to true, and theupdate()method takes over to monitor the process.

-
stopChoppingIngredient(): This method halts the chopping process by setting theisChoppingflag to false. It is typically invoked when the ingredient is removed from the chopping station before the process is complete or when chopping is manually stopped. By stopping the chopping process, this method ensures that the ingredient's state remains unchanged if it is not fully chopped.
Note: This has become obsolete since Team 6 decided to create their own version json file, ingredients.json to load the information they need.
This configuration class defines the chopping times for various ingredients. The times are stored in a JSON file (IngredientsChopTimes.json) and are loaded into the game to determine how long each ingredient needs to be chopped.
-
ingredientChopTimesMap<String, Integer>: A map that holds the chopping times for each ingredient.
-
getChopTime(String ingredientName): int: Retrieves the chop time for a specific ingredient from the configuration.
This file maps ingredient names to their respective chopping times. For example:
- "banana": 2 indicates that bananas require 2 seconds to be chopped.
- "beef": 20 indicates that beef requires 20 seconds to be chopped.
The
ChopIngredientComponentuses this configuration to determine how long to chop each ingredient.
Note: This has become obsolete since Team 6 decided to create their own version json file, ingredients.json to load the information they need.
This configuration class defines the cooking times for various ingredients. The times are stored in a JSON file (ingredientCookTimes.json) and are loaded into the game to determine how long each ingredient needs to be cooked.
-
ingredientCookTimes: Map<String, Integer>: A map that holds the cooking times for each ingredient
-
getCookTime(String ingredientName): int: Retrieves the cook time for a specific ingredient from the configuration.
This file maps ingredient names to their respective cooking times. For example:
- "tomato": 3 indicates that tomatoes require 3 seconds to be cooked.
- "chocolate": 1 indicates that chocolate requires 1 second to be cooked.
The CookIngredientComponent uses this configuration to determine how long to cook each ingredient.
The StationItemHandlerComponent facilitates the interaction between game stations (e.g., cooking tops, ovens, cutting boards) and ingredients. It triggers the cooking and chopping processes by interacting with CookIngredientComponent and ChopIngredientComponent based on the type of station and the ingredient provided.
- Triggers
cookIngredient()inCookIngredientComponentfor stations like COOK_TOP and OVEN. - Triggers
chopIngredient()inChopIngredientComponentfor the CUTTING_BOARD station. - Manages the addition and removal of items from stations.
The IngredientComponent is responsible for representing the state of the ingredient (e.g., raw, cooked, chopped, burnt). It directly interacts with both CookIngredientComponent and ChopIngredientComponent to manage and update the ingredient’s state during the cooking or chopping process.
-
CookIngredientComponentupdates the state of the ingredient by calling methods such ascookItem()andburnItem()to set the appropriate cooking states (e.g., cooked, burnt). -
ChopIngredientComponentupdates the state of the ingredient by callingchopItem()to mark it as chopped once the chopping process is complete. -
ChopIngredientComponentupdates the state of the ingredient by callingchopItem()to mark it as chopped once the chopping process is complete. - The IngredientComponent provides methods like
getCookTime()andgetItemState()to retrieve the cooking time and current state of the ingredient, which are used by the cooking and chopping components.
The GameTime class is responsible for managing the in-game time, tracking how long ingredients have been cooking or chopping, and determining when processes such as cooking or chopping are complete.
-
CookIngredientComponentusesGameTime.getTime()to track when the cooking process starts and to calculate the time when the cooking should end or when the ingredient will burn. -
ChopIngredientComponentsimilarly usesGameTime.getTime()to track the start and end of the chopping process, ensuring that the ingredient is chopped for the correct duration. - Both components rely on
GameTimeto ensure that time-dependent actions are executed at the appropriate times within the game.
-
CookIngredientComponentandChopIngredientComponentare responsible for handling the state changes of ingredients during cooking and chopping. - These components interact with
IngredientComponentto manage ingredient states and useGameTimeto track the necessary timing for these processes. - The
StationItemHandlerComponentacts as the bridge between game stations and these components, triggering the appropriate actions based on the station type and item provided. -
ChopIngredientConfigandCookIngredientConfigprovide the necessary configurations for chopping and cooking times, ensuring that the ingredients are processed according to their specific properties as defined inIngredientsChopTimes.jsonandingredientCookTimes.json.