Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions server/controllers/handleCheckpointEntered.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ export const handleCheckpointEntered = async (req, res) => {
checkpointsCompleted: cachedCheckpoints,
});
const visitor = await Visitor.create(visitorId, urlSlug, { credentials });
await visitor.fireToast({
groupId: "race",
title: "❌ Wrong checkpoint",
text: "Oops! Go back. You missed a checkpoint!",
});
await visitor
.fireToast({
groupId: "race",
title: "❌ Wrong checkpoint",
text: "Oops! Go back. You missed a checkpoint!",
})
.catch((error) =>
errorHandler({
error,
functionName: "handleCheckpointEntered",
message: "Error firing toast",
}),
);
return;
} else {
redisObj.publish(channel, {
Expand Down
10 changes: 7 additions & 3 deletions server/controllers/handleRaceStart.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ export const handleRaceStart = async (req, res) => {
redisObj.set(profileId, JSON.stringify({ 0: false }));

const world = World.create(urlSlug, { credentials });
world.triggerActivity({ type: WorldActivityType.GAME_ON, assetId }).catch((error) => {
console.error("Error triggering activity:", error);
});
world.triggerActivity({ type: WorldActivityType.GAME_ON, assetId }).catch((error) =>
errorHandler({
error,
functionName: "handleRaceStart",
message: "Error triggering world activity",
}),
);

// move visitor to start line asset
const startCheckpoint = (
Expand Down
18 changes: 13 additions & 5 deletions server/utils/checkpoints/checkpointEntered.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ export const checkpointEntered = async ({ checkpointNumber, currentTimestamp, cr
const currentElapsedTime = !startTimestamp ? null : formatElapsedTime(currentTimestamp - startTimestamp);

const visitor = await Visitor.create(visitorId, urlSlug, { credentials });
await visitor.fireToast({
groupId: "race",
title: `✅ Checkpoint ${checkpointNumber}`,
text: ENCOURAGEMENT_MESSAGES[checkpointNumber % ENCOURAGEMENT_MESSAGES.length],
});
await visitor
.fireToast({
groupId: "race",
title: `✅ Checkpoint ${checkpointNumber}`,
text: ENCOURAGEMENT_MESSAGES[checkpointNumber % ENCOURAGEMENT_MESSAGES.length],
})
.catch((error) =>
errorHandler({
error,
functionName: "checkpointEntered",
message: "Error firing toast",
}),
);

await world.updateDataObject(
{
Expand Down
47 changes: 34 additions & 13 deletions server/utils/checkpoints/finishLineEntered.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,44 @@ export const finishLineEntered = async ({ credentials, currentElapsedTime, profi
);

if (newHighscore !== highscore)
world.triggerActivity({ type: WorldActivityType.GAME_HIGH_SCORE, assetId }).catch((error) => {
console.error("Error triggering activity:", error);
});
world.triggerActivity({ type: WorldActivityType.GAME_HIGH_SCORE, assetId }).catch((error) =>
errorHandler({
error,
functionName: "finishLineEntered",
message: "Error triggering world activity",
}),
);

const visitor = await Visitor.get(visitorId, urlSlug, { credentials });
const { x, y } = visitor.moveTo;

visitor.fireToast({
groupId: "race",
title: "🏁 Finish",
text: `You finished the race! Your time: ${currentElapsedTime}`,
});
visitor.triggerParticle({
name: "trophy_float",
duration: 3,
position: { x, y },
});
visitor
.fireToast({
groupId: "race",
title: "🏁 Finish",
text: `You finished the race! Your time: ${currentElapsedTime}`,
})
.catch((error) =>
errorHandler({
error,
functionName: "finishLineEntered",
message: "Error firing toast",
}),
);

visitor
.triggerParticle({
name: "trophy_float",
duration: 3,
position: { x, y },
})
.catch((error) =>
errorHandler({
error,
functionName: "finishLineEntered",
message: "Error triggering particle effects",
}),
);

return;
} catch (error) {
Expand Down
Loading