CookingComponent - UQcsse3200/2024-studio-3 GitHub Wiki
Introduction
The CookingComponent class is an integral part of the cooking functionality of the game. This class predominantly handles the process of transforming raw or ‘uncooked’ ingredients in a station and consequently cooking that item. Additionally, this class interacts with the base game’s event system to listen for when an item is added and removed from a station.
Initialising the Component
In order to function, CookingComponent requires an instance of StationInventoryComponent to be attached to the same entity.
newEntity = new Entity();
inventoryComponent = new StationInventoryComponent();
newEntity.addComponent(inventoryComponent);
cookingComponent = new CookingComponent();
newEntity.addComponent(cookingComponent);
newEntity.create();
Methods
create()- Initialises the component and adds event listenersupdate()- Handles cooking process by using GameTime to decrement the cooking timeaddItem(item)- Adds item to station and begins cooking processremoveItem()- Removes item from station and stops cooking processisCooking() - returns true if the station is currently cooking itemsgetCookingTime()- gets the time remaining until the recipe is cookedgetTargetRecipe()- gets the recipe being cooked
Attributes
| Attribute | Type | Description |
|---|---|---|
inventoryComponent |
StationInventoryComponent |
Tracks the StationInventoryComponent attached to this component’s entity. |
gameTime |
GameTime |
Used for timing. |
cookingTime |
long |
The time (in seconds) remaining until the recipe is cooked. |
isCooking |
boolean |
A flag to tell whether the station is currently cooking food or not. |
targetRecipe |
String |
The name of the dish to be made once cooking is complete. |
Events
CookingComponent uses the same event names as StationItemHandlerComponent for adding and removing items from the station respectively. This is so that calling either event triggers the respective method in both components.
Timing
A countdown timer system was used so that the remaining cooking time can be accessed publicly for future use - eg a UI progress bar or for tracking how cooked each item is.