Items - UQcsse3200/2024-studio-3 GitHub Wiki
Items
Overview
The items are one of the most fundamental part to most videos games. Within our game, these items will be used to display ingredient and used to make meals and give them to customers. These items are built through the entity-component system using an entity with multiple components which allows the functionality that we need.
How to create your own item
All of the spawning of the items should occur in ItemFactory where all items including meals and ingredients are spawned individually. All created items should be registered to the entity service upon creation, and unregistered when they are no longer used.
Example of a Fish
Below is an example of how a fish entity might be created and the components it might have.
If you want to add some items together to make a meal which will be servable to the customer, you will do the same thing as an item however use a meal component to give the functionality a meal requires. To get more info on how meal and ingredient component differ, refer to the UML diagram furthur below in the document
Components
The item you want to create will either be a meal or ingredient for the meal.
ItemComponent
The item components is a template class which has very basic functionality and is utilized by meal and ingredients for it's simplicity. It consist of a randomly generated ID, a name, weight and type. There are getter for all these however no setter as these function should not be changed after initialized.
IngredientComponent
The IngredientComponent is a child of the ItemComponent which will be used for all individual food items which will be used within the game. It can be defined to be chopped and/or/neither cooked and can be altered through the many methods available. Refer to UML for full list
MealComponent
The MealComponent is also a child of the ItemComponent which will be used to combine all individual IngredientComponent to make a central dish which can be served to customer. This allows meals to have ingredients set, added and taken away at a basic level and have a set price. The quality will be calculated through a calculateQuality() function which will access each individual item's state to determine each items quality, which each item identified in the incorrect state drawing a 'penalty'. These penalties are then summed and reduce the quality score, which has a maximum of 100.
ItemTimerComponent
ItemTimerComponent is an abstract class which the next two components CookIngredientComponent and ChopIngredientComponent inherit from. This component provides timer functionality for items down to millisecond precision to allow for the starting and stopping of item cooking and chopping. This enables features like the player needing to actively control the chopping process, and allowing for the burning of items.
CookIngredientComponent
The CookIngredientComponent inherits from the abstract ItemTimerComponent. This allows for the item to keep track of the time it has spent cooking. This enables partial cooking of an item. And allows the implementation of burning specific to items that can be cooked.
ChopIngredientComponent
Similar to CookIngredientComponent, ChopIngredientComponent inherits from the abstract ItemTimerComponent. This allows for the item to keep track of the time it has spent cooking. This means that chopping can be paused and resumed whilst saving the progress of how far the item has come.