-
Notifications
You must be signed in to change notification settings - Fork 7
Plant mouse hover component
This component triggers an event that indicates if the player is hovering their mouse cursor over a the plant entity that this component is attached to.
This component is essential for the PlantInfoDisplayDomponent
to function properly. This component overrides the update()
method from the Component class so that the info being displayed on the PlantInfoDisplayDomponent
is updated every frame. The update function works by getting the current position of the users mouse and comparing it to the current position of the crop tile that the plant is attached to. If these two positions are equal, then an event for the PlantInfoService
is triggered,
ServiceLocator.getPlantInfoService().getEvents().trigger("showPlantInfo, plantName, plantInfo);
If the positions do not match then this event is triggered,
ServiceLocator.getPlantInfoService().getEvents().trigger("clearPlantInfo);
These events inform the PlantInfoDisplayComponent
the correct information to display.
-
private boolean showInfo
: Indicates if the cursor is over the plant. -
private boolean plantDead
: Is true if the plant is dead and no more info should be displayed. -
private boolean noMoreUse
: Indicates if the component is to be disposed.
-
public void create()
: Initialise the variables for the component. -
public void update()
: Updates the component every frame. Calls updateInfo() -
private void updateInfo()
: Updates the information being shown on the plant info UI. -
public void plantDied()
: Used to signal when the plant has died.
To incorporate the PlantMouseHoverComponent into the plant system:
1. Import the necessary classes
import com.csse3200.game.components.plants.PlantMouseHoverComponent;
**2. Add the PlantMouseHoverComponent to a plant entity **
plant.addComponent(new PlantMouseHoverComponent());
- create the setUp method to be run before each test
- initialize the
PlantMouseHoverComponent
object - mock the necessary dependencies
- create tests for the setter and getter methods
- create tests for all other methods