1+ import { WorldActivityType } from "@rtsdk/topia" ;
12import { Visitor } from "../topiaInit.js" ;
23import { timeToValue } from "../utils.js" ;
34
45export 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 ) {
0 commit comments