Skip to content

Commit d7ad8fd

Browse files
authored
Merge pull request #24 from metaversecloud-com/dev
Update SDK & fix breaking changes
2 parents 2af5fe5 + 3756b6a commit d7ad8fd

File tree

8 files changed

+39
-54
lines changed

8 files changed

+39
-54
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @cpsiaki @LinaBell @liebeskind

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"dependencies": {
66
"@googleapis/sheets": "^7.0.0",
7-
"@rtsdk/topia": "^0.12.0",
7+
"@rtsdk/topia": "^0.15.7",
88
"axios": "^1.6.7",
99
"body-parser": "^1.20.2",
1010
"concurrently": "^8.2.2",

server/controllers/handleCancelRace.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import { errorHandler, World } from "../utils/index.js";
1+
import { errorHandler, getCredentials, World } from "../utils/index.js";
22

33
export const handleCancelRace = async (req, res) => {
44
try {
5-
const { interactiveNonce, interactivePublicKey, urlSlug, visitorId, assetId, profileId, sceneDropId } = req.query;
6-
7-
const credentials = {
8-
interactiveNonce,
9-
interactivePublicKey,
10-
visitorId,
11-
assetId,
12-
};
5+
const credentials = getCredentials(req.query);
6+
const { urlSlug, profileId, sceneDropId } = credentials;
137

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

server/controllers/handleRaceStart.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { addNewRowToGoogleSheets, Visitor, World, errorHandler, getCredentials } from "../utils/index.js";
22
import redisObj from "../redis/redis.js";
3+
import { WorldActivityType } from "@rtsdk/topia";
34

45
export const handleRaceStart = async (req, res) => {
56
try {
67
const credentials = getCredentials(req.query);
7-
const { interactiveNonce, interactivePublicKey, urlSlug, visitorId, profileId, sceneDropId } = credentials;
8+
const { assetId, urlSlug, visitorId, profileId, sceneDropId } = credentials;
89
const { identityId, displayName } = req.query;
910
const startTimestamp = Date.now();
1011

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

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

1517
// move visitor to start line asset
1618
const startCheckpoint = (
@@ -19,21 +21,14 @@ export const handleRaceStart = async (req, res) => {
1921
uniqueName: "race-track-start",
2022
})
2123
)?.[0];
22-
const visitor = await Visitor.get(visitorId, urlSlug, {
23-
credentials: {
24-
interactiveNonce,
25-
interactivePublicKey,
26-
visitorId,
27-
},
28-
});
24+
const visitor = await Visitor.get(visitorId, urlSlug, { credentials });
2925
await visitor.moveVisitor({
3026
shouldTeleportVisitor: true,
3127
x: startCheckpoint?.position?.x,
3228
y: startCheckpoint?.position?.y,
3329
});
3430

3531
// reset race data in World data object)
36-
await world.fetchDataObject();
3732
await world.updateDataObject(
3833
{
3934
[`${sceneDropId}.profiles.${profileId}.checkpoints`]: {},

server/controllers/handleSwitchTrack.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ export const handleSwitchTrack = async (req, res) => {
3333
droppedAssetIds.push(allRaceAssets?.[raceAsset]?.id);
3434
}
3535

36-
await World.deleteDroppedAssets(urlSlug, droppedAssetIds, process.env.INTERACTIVE_SECRET, {
37-
interactiveNonce,
38-
interactivePublicKey,
39-
visitorId,
40-
});
36+
await World.deleteDroppedAssets(urlSlug, droppedAssetIds, process.env.INTERACTIVE_SECRET, credentials);
4137

4238
await world.dropScene({
4339
sceneId: trackSceneId,

server/utils/checkpoints/finishLineEntered.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { WorldActivityType } from "@rtsdk/topia";
12
import { Visitor } from "../topiaInit.js";
23
import { timeToValue } from "../utils.js";
34

45
export const finishLineEntered = async ({ credentials, currentElapsedTime, profileObject, raceObject, world }) => {
56
try {
6-
const { profileId, sceneDropId, urlSlug, username, visitorId } = credentials;
7+
const { profileId, sceneDropId, urlSlug, visitorId } = credentials;
78
const { checkpoints, highscore } = profileObject;
89
const allCheckpointsCompleted = raceObject.numberOfCheckpoints === Object.keys(checkpoints).length;
910

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

16+
await world.updateDataObject(
17+
{
18+
[`${sceneDropId}.profiles.${profileId}.checkpoints`]: {},
19+
[`${sceneDropId}.profiles.${profileId}.elapsedTime`]: currentElapsedTime,
20+
[`${sceneDropId}.profiles.${profileId}.startTimestamp`]: null,
21+
[`${sceneDropId}.profiles.${profileId}.highscore`]: newHighscore,
22+
},
23+
{ analytics: [{ analyticName: "completions", uniqueKey: profileId }] },
24+
);
25+
26+
if (newHighscore !== highscore) world.triggerActivity({ type: WorldActivityType.GAME_HIGH_SCORE, assetId });
27+
1528
const visitor = await Visitor.get(visitorId, urlSlug, { credentials });
1629
const { x, y } = visitor.moveTo;
1730

18-
await Promise.all(
19-
world.updateDataObject(
20-
{
21-
[`${sceneDropId}.profiles.${profileId}`]: {
22-
checkpoints: {},
23-
elapsedTime: currentElapsedTime,
24-
highscore: newHighscore,
25-
startTimestamp: null,
26-
username,
27-
},
28-
},
29-
{ analytics: [{ analyticName: "completions", uniqueKey: profileId }] },
30-
),
31-
visitor.fireToast({
32-
groupId: "race",
33-
title: "🏁 Finish",
34-
text: `You finished the race! Your time: ${currentElapsedTime}`,
35-
}),
36-
visitor.triggerParticle({
37-
name: "trophy_float",
38-
duration: 3,
39-
position: { x, y },
40-
}),
41-
);
31+
visitor.fireToast({
32+
groupId: "race",
33+
title: "🏁 Finish",
34+
text: `You finished the race! Your time: ${currentElapsedTime}`,
35+
});
36+
visitor.triggerParticle({
37+
name: "trophy_float",
38+
duration: 3,
39+
position: { x, y },
40+
});
4241

4342
return;
4443
} catch (error) {

server/utils/errorHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const errorHandler = ({ error, functionName, message, req, res }) => {
1616
reqQueryParams,
1717
reqBody: req?.body,
1818
},
19-
error,
19+
error: JSON.stringify(error, Object.getOwnPropertyNames(error)),
2020
}),
2121
);
2222
}

0 commit comments

Comments
 (0)