@@ -4,7 +4,7 @@ import { timeToValue } from "../utils.js";
44
55export const finishLineEntered = async ( { credentials, currentElapsedTime, profileObject, raceObject, world } ) => {
66 try {
7- const { profileId, sceneDropId, urlSlug, username , visitorId } = credentials ;
7+ const { profileId, sceneDropId, urlSlug, visitorId } = credentials ;
88 const { checkpoints, highscore } = profileObject ;
99 const allCheckpointsCompleted = raceObject . numberOfCheckpoints === Object . keys ( checkpoints ) . length ;
1010
@@ -13,35 +13,31 @@ export const finishLineEntered = async ({ credentials, currentElapsedTime, profi
1313 const newHighscore =
1414 ! highscore || timeToValue ( currentElapsedTime ) < timeToValue ( highscore ) ? currentElapsedTime : highscore ;
1515
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+
1626 if ( newHighscore !== highscore ) world . triggerActivity ( { type : WorldActivityType . GAME_HIGH_SCORE , assetId } ) ;
1727
1828 const visitor = await Visitor . get ( visitorId , urlSlug , { credentials } ) ;
1929 const { x, y } = visitor . moveTo ;
2030
21- await Promise . all (
22- world . updateDataObject (
23- {
24- [ `${ sceneDropId } .profiles.${ profileId } ` ] : {
25- checkpoints : { } ,
26- elapsedTime : currentElapsedTime ,
27- highscore : newHighscore ,
28- startTimestamp : null ,
29- username,
30- } ,
31- } ,
32- { analytics : [ { analyticName : "completions" , uniqueKey : profileId } ] } ,
33- ) ,
34- visitor . fireToast ( {
35- groupId : "race" ,
36- title : "🏁 Finish" ,
37- text : `You finished the race! Your time: ${ currentElapsedTime } ` ,
38- } ) ,
39- visitor . triggerParticle ( {
40- name : "trophy_float" ,
41- duration : 3 ,
42- position : { x, y } ,
43- } ) ,
44- ) ;
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+ } ) ;
4541
4642 return ;
4743 } catch ( error ) {
0 commit comments