Skip to content
Merged

Dev #25

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
4 changes: 3 additions & 1 deletion server/controllers/handleRaceStart.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ 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 });
world.triggerActivity({ type: WorldActivityType.GAME_ON, assetId }).catch((error) => {
console.error("Error triggering activity:", error);
});

// move visitor to start line asset
const startCheckpoint = (
Expand Down
6 changes: 3 additions & 3 deletions server/controllers/handleSwitchTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { World, Visitor, errorHandler, getCredentials } from "../utils/index.js"
export const handleSwitchTrack = async (req, res) => {
try {
const credentials = getCredentials(req.query);
const { assetId, profileId, interactiveNonce, interactivePublicKey, urlSlug, visitorId, sceneDropId } = credentials;
const { assetId, profileId, urlSlug, visitorId, sceneDropId } = credentials;
const { trackSceneId } = req.query;

const world = await World.create(urlSlug, { credentials });
Expand Down Expand Up @@ -41,6 +41,8 @@ export const handleSwitchTrack = async (req, res) => {
sceneDropId,
});

await visitor.closeIframe(assetId);

const numberOfCheckpoints = await world.fetchDroppedAssetsWithUniqueName({
uniqueName: "race-track-checkpoint",
isPartial: true,
Expand All @@ -54,8 +56,6 @@ export const handleSwitchTrack = async (req, res) => {
{ analytics: [{ analyticName: "trackUpdates", profileId, uniqueKey: profileId }] },
);

await visitor.closeIframe(assetId);

return res.json({ success: true });
} catch (error) {
return errorHandler({
Expand Down
8 changes: 6 additions & 2 deletions server/utils/checkpoints/finishLineEntered.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { timeToValue } from "../utils.js";

export const finishLineEntered = async ({ credentials, currentElapsedTime, profileObject, raceObject, world }) => {
try {
const { profileId, sceneDropId, urlSlug, visitorId } = credentials;
const { profileId, sceneDropId, urlSlug, username, visitorId } = credentials;
const { checkpoints, highscore } = profileObject;
const allCheckpointsCompleted = raceObject.numberOfCheckpoints === Object.keys(checkpoints).length;

Expand All @@ -19,11 +19,15 @@ export const finishLineEntered = async ({ credentials, currentElapsedTime, profi
[`${sceneDropId}.profiles.${profileId}.elapsedTime`]: currentElapsedTime,
[`${sceneDropId}.profiles.${profileId}.startTimestamp`]: null,
[`${sceneDropId}.profiles.${profileId}.highscore`]: newHighscore,
[`${sceneDropId}.profiles.${profileId}.username`]: username,
},
{ analytics: [{ analyticName: "completions", uniqueKey: profileId }] },
);

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

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