Skip to content

Commit 98d6052

Browse files
authored
Game: Highlight objects on Hover during Explore mode (#3089)
* game ui update so that objects in explore mode are highlighted * formatting code
1 parent 4734e69 commit 98d6052

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

.tool-versions

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs v20.18.1

src/features/game/effects/GlowingObject.ts

+8
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ export default class GlowingImage {
8888
this.blinkClearer?.();
8989
}
9090

91+
public hoverGlowStart() {
92+
this.imageGlow.setAlpha(0.5);
93+
}
94+
95+
public hoverGlowEnd() {
96+
this.imageGlow.setAlpha(0);
97+
}
98+
9199
public getContainer() {
92100
return this.container;
93101
}

src/features/game/mode/explore/GameModeExplore.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ class GameModeExplore implements IGameUI {
103103
if (!activatable.actionIds || !activatable.actionIds.length) {
104104
return;
105105
}
106-
activatable.clickArea.on('pointerout', () => this.explorePointerOut());
106+
107+
activatable.clickArea.on('pointerout', () =>
108+
this.explorePointerOut(activatable.interactionId)
109+
);
107110
activatable.clickArea.on('pointerover', () =>
108111
this.explorePointerOver(activatable.interactionId)
109112
);
@@ -138,6 +141,8 @@ class GameModeExplore implements IGameUI {
138141
*/
139142
private explorePointerOver(id: ItemId) {
140143
const hasTriggered = GameGlobalAPI.getInstance().hasTriggeredInteraction(id);
144+
GameGlobalAPI.getInstance().objectHoverGlow(id, true);
145+
141146
if (hasTriggered) {
142147
GameGlobalAPI.getInstance().setDefaultCursor(ExploreModeConstants.checked);
143148
} else {
@@ -149,8 +154,9 @@ class GameModeExplore implements IGameUI {
149154
* Function to be executed when user off hover upon interactable object/bbox.
150155
* It sets the cursor back to 'Explore' mode cursor.
151156
*/
152-
private explorePointerOut() {
157+
private explorePointerOut(id: ItemId) {
153158
GameGlobalAPI.getInstance().setDefaultCursor(ExploreModeConstants.normal);
159+
GameGlobalAPI.getInstance().objectHoverGlow(id, false);
154160
}
155161

156162
/**
@@ -163,6 +169,7 @@ class GameModeExplore implements IGameUI {
163169
*/
164170
private explorePointerUp(id: string) {
165171
GameGlobalAPI.getInstance().setDefaultCursor(Constants.defaultCursor);
172+
GameGlobalAPI.getInstance().objectHoverGlow(id, false);
166173
GameGlobalAPI.getInstance().triggerInteraction(id);
167174
GameGlobalAPI.getInstance().setDefaultCursor(ExploreModeConstants.normal);
168175
}

src/features/game/objects/GameObjectManager.ts

+17
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@ class GameObjectManager implements StateObserver {
7979
}
8080
}
8181

82+
/**
83+
* Apply glow effect on the object, for when it's hovered on
84+
*
85+
* @param objectId id of the object
86+
*/
87+
public objectHoverGlow(objectId: ItemId, turnOn: boolean) {
88+
const object = this.objects.get(objectId);
89+
if (!object) {
90+
return;
91+
}
92+
if (turnOn) {
93+
(object.sprite as GlowingImage).hoverGlowStart();
94+
} else {
95+
(object.sprite as GlowingImage).hoverGlowEnd();
96+
}
97+
}
98+
8299
/**
83100
* Create the object from the given object property.
84101
* Because we want this sprite to be activatable

src/features/game/scenes/gameManager/GameGlobalAPI.ts

+4
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class GameGlobalAPI {
135135
this.getGameManager().getObjectManager().makeObjectBlink(objectId, turnOn);
136136
}
137137

138+
public objectHoverGlow(objectId: ItemId, turnOn: boolean) {
139+
this.getGameManager().getObjectManager().objectHoverGlow(objectId, turnOn);
140+
}
141+
138142
public setObjProperty(id: ItemId, newObjProp: ObjectProperty) {
139143
this.getGameManager().getStateManager().setObjProperty(id, newObjProp);
140144
}

0 commit comments

Comments
 (0)