Cooking Ingredients - UQcsse3200/2024-studio-3 GitHub Wiki

Introduction

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.


Purpose

  • 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."

1. CookIngredientComponent

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.

Key Attributes:

  • 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.

Key Methods:

  • create(): Initializes the CookIngredientComponent when 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.

    create()

  • 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 using GameTime, 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".

    ci_update()

  • cookIngredient(String stationState, int oven_multiplier): This method initiates the cooking process for the ingredient. It calculates the cookEndTime by 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.

    CookIngredient()

  • stopCookingIngredient(): Stops the cooking process by setting the isCooking flag 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.

2. ChopIngredientComponent

Description

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.

Key Attributes

  • ingredient (IngredientComponent): A reference to the IngredientComponent associated 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 the GameTime class. 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. When isChopping is 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. The chopEndTime is calculated by adding the ingredient's chopping duration (retrieved from ChopIngredientConfig or ingredientChopTimes) to the current game time when the chopping starts.

Key Methods

  • create(): This method is called when the ChopIngredientComponent is 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. The create() method ensures that the component is properly integrated into the game’s event system.

    chop_create()

  • update(): The update() method is called every frame to monitor the chopping process. It checks whether the current game time has reached or exceeded the chopEndTime. If the chopping time has been met, the method triggers the chopItem() function on the IngredientComponent, 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.

    chop_update()

  • chopIngredient(): This method begins the chopping process for the ingredient. It calculates the chopEndTime based on the current time provided by the GameTime class and the chopping duration specified for the ingredient. The duration is usually retrieved from the ChopIngredientConfig, which holds the chopping times for different ingredients. Once the chopEndTime is set, the isChopping flag is set to true, and the update() method takes over to monitor the process.

    chopIngredient()

  • stopChoppingIngredient(): This method halts the chopping process by setting the isChopping flag 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.

3. ChopIngredientConfig

Note: This has become obsolete since Team 6 decided to create their own version json file, ingredients.json to load the information they need.

Description

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.

Key Attributes

  • ingredientChopTimes Map<String, Integer>: A map that holds the chopping times for each ingredient.

Key Methods

  • getChopTime(String ingredientName): int: Retrieves the chop time for a specific ingredient from the configuration.

JSON File: IngredientsChopTimes.json

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 ChopIngredientComponent uses this configuration to determine how long to chop each ingredient.

4. CookIngredientConfig

Note: This has become obsolete since Team 6 decided to create their own version json file, ingredients.json to load the information they need.

Description

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.

Key Attributes

  • ingredientCookTimes: Map<String, Integer>: A map that holds the cooking times for each ingredient

Key Methods

  • getCookTime(String ingredientName): int: Retrieves the cook time for a specific ingredient from the configuration.

JSON file: ingredientCookTimes.json

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.


Interaction with other Components



StationItemHandlerComponent

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.

Interactions:

  • Triggers cookIngredient() in CookIngredientComponent for stations like COOK_TOP and OVEN.
  • Triggers chopIngredient() in ChopIngredientComponent for the CUTTING_BOARD station.
  • Manages the addition and removal of items from stations.

    giveItem()

    takeItem()

IngredientComponent

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.

Interactions

  • CookIngredientComponent updates the state of the ingredient by calling methods such as cookItem() and burnItem() to set the appropriate cooking states (e.g., cooked, burnt).
  • ChopIngredientComponent updates the state of the ingredient by calling chopItem() to mark it as chopped once the chopping process is complete.
  • ChopIngredientComponent updates the state of the ingredient by calling chopItem() to mark it as chopped once the chopping process is complete.
  • The IngredientComponent provides methods like getCookTime() and getItemState() to retrieve the cooking time and current state of the ingredient, which are used by the cooking and chopping components.

GameTime

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.

Interactions

  • CookIngredientComponent uses GameTime.getTime() to track when the cooking process starts and to calculate the time when the cooking should end or when the ingredient will burn.
  • ChopIngredientComponent similarly uses GameTime.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 GameTime to ensure that time-dependent actions are executed at the appropriate times within the game.


Summary

  • CookIngredientComponent and ChopIngredientComponent are responsible for handling the state changes of ingredients during cooking and chopping.
  • These components interact with IngredientComponent to manage ingredient states and use GameTime to track the necessary timing for these processes.
  • The StationItemHandlerComponent acts as the bridge between game stations and these components, triggering the appropriate actions based on the station type and item provided.
  • ChopIngredientConfig and CookIngredientConfig provide the necessary configurations for chopping and cooking times, ensuring that the ingredients are processed according to their specific properties as defined in IngredientsChopTimes.json and ingredientCookTimes.json.

    UML_Cooking_Ingredients
⚠️ **GitHub.com Fallback** ⚠️