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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @cpsiaki @LinaBell @liebeskind
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"dependencies": {
"@googleapis/sheets": "^7.0.0",
"@rtsdk/topia": "^0.12.0",
"@rtsdk/topia": "^0.15.7",
"axios": "^1.6.7",
"body-parser": "^1.20.2",
"concurrently": "^8.2.2",
Expand Down
12 changes: 3 additions & 9 deletions server/controllers/handleCancelRace.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { errorHandler, World } from "../utils/index.js";
import { errorHandler, getCredentials, World } from "../utils/index.js";

export const handleCancelRace = async (req, res) => {
try {
const { interactiveNonce, interactivePublicKey, urlSlug, visitorId, assetId, profileId, sceneDropId } = req.query;

const credentials = {
interactiveNonce,
interactivePublicKey,
visitorId,
assetId,
};
const credentials = getCredentials(req.query);
const { urlSlug, profileId, sceneDropId } = credentials;

const world = await World.create(urlSlug, { credentials });

Expand Down
13 changes: 4 additions & 9 deletions server/controllers/handleRaceStart.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { addNewRowToGoogleSheets, Visitor, World, errorHandler, getCredentials } from "../utils/index.js";
import redisObj from "../redis/redis.js";
import { WorldActivityType } from "@rtsdk/topia";

export const handleRaceStart = async (req, res) => {
try {
const credentials = getCredentials(req.query);
const { interactiveNonce, interactivePublicKey, urlSlug, visitorId, profileId, sceneDropId } = credentials;
const { assetId, urlSlug, visitorId, profileId, sceneDropId } = credentials;
const { identityId, displayName } = req.query;
const startTimestamp = Date.now();

redisObj.set(profileId, JSON.stringify({ 0: false }));

const world = World.create(urlSlug, { credentials });
world.triggerActivity({ type: WorldActivityType.GAME_ON, assetId });

// move visitor to start line asset
const startCheckpoint = (
Expand All @@ -19,21 +21,14 @@ export const handleRaceStart = async (req, res) => {
uniqueName: "race-track-start",
})
)?.[0];
const visitor = await Visitor.get(visitorId, urlSlug, {
credentials: {
interactiveNonce,
interactivePublicKey,
visitorId,
},
});
const visitor = await Visitor.get(visitorId, urlSlug, { credentials });
await visitor.moveVisitor({
shouldTeleportVisitor: true,
x: startCheckpoint?.position?.x,
y: startCheckpoint?.position?.y,
});

// reset race data in World data object)
await world.fetchDataObject();
await world.updateDataObject(
{
[`${sceneDropId}.profiles.${profileId}.checkpoints`]: {},
Expand Down
6 changes: 1 addition & 5 deletions server/controllers/handleSwitchTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ export const handleSwitchTrack = async (req, res) => {
droppedAssetIds.push(allRaceAssets?.[raceAsset]?.id);
}

await World.deleteDroppedAssets(urlSlug, droppedAssetIds, process.env.INTERACTIVE_SECRET, {
interactiveNonce,
interactivePublicKey,
visitorId,
});
await World.deleteDroppedAssets(urlSlug, droppedAssetIds, process.env.INTERACTIVE_SECRET, credentials);

await world.dropScene({
sceneId: trackSceneId,
Expand Down
49 changes: 24 additions & 25 deletions server/utils/checkpoints/finishLineEntered.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { WorldActivityType } from "@rtsdk/topia";
import { Visitor } from "../topiaInit.js";
import { timeToValue } from "../utils.js";

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

Expand All @@ -12,33 +13,31 @@ export const finishLineEntered = async ({ credentials, currentElapsedTime, profi
const newHighscore =
!highscore || timeToValue(currentElapsedTime) < timeToValue(highscore) ? currentElapsedTime : highscore;

await world.updateDataObject(
{
[`${sceneDropId}.profiles.${profileId}.checkpoints`]: {},
[`${sceneDropId}.profiles.${profileId}.elapsedTime`]: currentElapsedTime,
[`${sceneDropId}.profiles.${profileId}.startTimestamp`]: null,
[`${sceneDropId}.profiles.${profileId}.highscore`]: newHighscore,
},
{ analytics: [{ analyticName: "completions", uniqueKey: profileId }] },
);

if (newHighscore !== highscore) world.triggerActivity({ type: WorldActivityType.GAME_HIGH_SCORE, assetId });

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

await Promise.all(
world.updateDataObject(
{
[`${sceneDropId}.profiles.${profileId}`]: {
checkpoints: {},
elapsedTime: currentElapsedTime,
highscore: newHighscore,
startTimestamp: null,
username,
},
},
{ analytics: [{ analyticName: "completions", uniqueKey: profileId }] },
),
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}`,
});
visitor.triggerParticle({
name: "trophy_float",
duration: 3,
position: { x, y },
});

return;
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion server/utils/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const errorHandler = ({ error, functionName, message, req, res }) => {
reqQueryParams,
reqBody: req?.body,
},
error,
error: JSON.stringify(error, Object.getOwnPropertyNames(error)),
}),
);
}
Expand Down
Loading