111111 < div class ="snapshot-header ">
112112 < div id ="finalTime " class ="score-value "> 0:00.00</ div >
113113 < div id ="missionPerformance " class ="performance-rating "> Calculating...</ div >
114+ < div id ="playerIdentity " class ="player-identity "> </ div >
114115 < div id ="leaderboardSubmit " class ="leaderboard-submit hidden ">
115- <!-- Shown when anonymous -->
116- < div class ="submit-anon ">
117- < button class ="btn-sign-in-to-submit " onclick ="openAuthModal() ">
118- < i class ="iconoir-user "> </ i > Sign in to submit your score
119- </ button >
120- </ div >
121116 < div id ="scoreSubmitStatus " class ="score-submit-status "> </ div >
122117 </ div >
123118 </ div >
147142 < div class ="snapshot-header victory ">
148143 < div id ="victoryTime " class ="score-value "> 5:00.00</ div >
149144 < div id ="victoryPerformance " class ="performance-rating perfect "> MAX SURVIVAL</ div >
145+ < div id ="victoryPlayerIdentity " class ="player-identity "> </ div >
150146 < div id ="victoryLeaderboardSubmit " class ="leaderboard-submit hidden ">
151- <!-- Shown when anonymous -->
152- < div class ="submit-anon ">
153- < button class ="btn-sign-in-to-submit " onclick ="openAuthModal() ">
154- < i class ="iconoir-user "> </ i > Sign in to submit your score
155- </ button >
156- </ div >
157147 < div id ="victoryScoreSubmitStatus " class ="score-submit-status "> </ div >
158148 </ div >
159149 </ div >
@@ -616,6 +606,7 @@ <h2 class="mobile-menu-title">REFLECTIONS</h2>
616606 // Auto-submit score to leaderboard. Called when:
617607 // 1. Game over modal appears and user is signed in
618608 // 2. User signs in from auth modal while game over modal is showing
609+ // Called when game over modal appears. Shows leaderboard rank or sign-in prompt.
619610 window . submitScore = submitScore ;
620611 async function submitScore ( ) {
621612 if ( ! window . game || ! window . leaderboardService || ! window . firebaseAuth ) return ;
@@ -624,26 +615,40 @@ <h2 class="mobile-menu-title">REFLECTIONS</h2>
624615 const service = window . leaderboardService ;
625616 const game = window . game ;
626617
627- // Must be signed in and game must be over
628- if ( auth . isAnonymous ( ) || ! game . gameOver || game . gameTime <= 0 ) return ;
618+ if ( ! game . gameOver || game . gameTime <= 0 ) return ;
629619
630- // Find the visible status element
620+ // Find the visible elements
631621 const isVictory = ! document . getElementById ( 'victoryModal' ) . classList . contains ( 'hidden' ) ;
632622 const statusEl = isVictory
633623 ? document . getElementById ( 'victoryScoreSubmitStatus' )
634624 : document . getElementById ( 'scoreSubmitStatus' ) ;
625+ const identityEl = isVictory
626+ ? document . getElementById ( 'victoryPlayerIdentity' )
627+ : document . getElementById ( 'playerIdentity' ) ;
628+ if ( ! statusEl ) return ;
629+
630+ // Show username if signed in
631+ if ( identityEl ) {
632+ if ( auth . isAnonymous ( ) ) {
633+ identityEl . textContent = '' ;
634+ } else {
635+ const displayName = auth . getDisplayNameOrDefault ( ) ;
636+ identityEl . textContent = displayName ;
637+ }
638+ }
639+
640+ // Anonymous users: show sign-in prompt
641+ if ( auth . isAnonymous ( ) ) {
642+ statusEl . innerHTML = '<span class="leaderboard-signin-link" onclick="openAuthModal()"><i class="iconoir-user"></i> Sign In To Join the Leaderboard</span>' ;
643+ return ;
644+ }
635645
636646 // Don't re-submit if already submitted this game
637- if ( statusEl && statusEl . dataset . submitted === 'true' ) return ;
647+ if ( statusEl . dataset . submitted === 'true' ) return ;
638648
639649 try {
640- if ( statusEl ) {
641- statusEl . textContent = 'Submitting score...' ;
642- statusEl . style . color = 'var(--text-secondary)' ;
643- }
644-
645- // Hide the sign-in prompt since we're signed in
646- document . querySelectorAll ( '.submit-anon' ) . forEach ( el => el . style . display = 'none' ) ;
650+ statusEl . textContent = 'Submitting score...' ;
651+ statusEl . style . color = 'var(--text-secondary)' ;
647652
648653 const mode = game . isDailyChallenge ? 'daily' : 'main' ;
649654 const DailyChallenge = ( await import ( './js/validation/DailyChallenge.js' ) ) . DailyChallenge ;
@@ -660,50 +665,39 @@ <h2 class="mobile-menu-title">REFLECTIONS</h2>
660665 spawnerCount : game . spawners . length ,
661666 } ) ;
662667
663- if ( statusEl ) {
664- statusEl . dataset . submitted = 'true' ;
665-
666- if ( result . isNewBest ) {
667- statusEl . textContent = 'Score submitted - new personal best!' ;
668- statusEl . style . color = '#FFD700' ;
669-
670- // Video upload for main game top 10
671- if ( mode === 'main' && window . videoUploader ) {
672- const isTop = await service . isTop10 ( game . gameTime ) ;
673- if ( isTop ) {
674- const recorder = game . replayRecorder ;
675- let videoBlob = recorder . videoBlob ;
676-
677- if ( ! videoBlob && recorder . canGenerateMP4 ( ) ) {
678- statusEl . textContent = 'Top 10! Generating replay...' ;
679- await game . generateReplayMP4 ( ) ;
680- videoBlob = recorder . videoBlob ;
681- }
682-
683- if ( videoBlob ) {
684- statusEl . textContent = 'Top 10! Uploading replay...' ;
685- await window . videoUploader . uploadReplayVideo (
686- videoBlob , game . gameTime , result . docId ,
687- ( percent ) => {
688- statusEl . textContent = `Uploading replay... ${ percent } %` ;
689- }
690- ) ;
691- statusEl . textContent = 'Top 10! Replay uploaded!' ;
692- }
693- }
668+ statusEl . dataset . submitted = 'true' ;
669+
670+ // Get rank
671+ const rank = await service . getUserRank ( mode , game . gameTime ) ;
672+ const rankText = rank ? `#${ rank } ` : '' ;
673+
674+ if ( result . isNewBest ) {
675+ statusEl . innerHTML = `<span class="leaderboard-rank">${ rankText } on the leaderboard</span> <span class="leaderboard-best">New personal best!</span>` ;
676+
677+ // Video upload for main game top 10
678+ if ( mode === 'main' && rank && rank <= 10 && window . videoUploader ) {
679+ const recorder = game . replayRecorder ;
680+ let videoBlob = recorder . videoBlob ;
681+
682+ if ( ! videoBlob && recorder . canGenerateMP4 ( ) ) {
683+ await game . generateReplayMP4 ( ) ;
684+ videoBlob = recorder . videoBlob ;
685+ }
686+
687+ if ( videoBlob ) {
688+ await window . videoUploader . uploadReplayVideo (
689+ videoBlob , game . gameTime , result . docId
690+ ) ;
694691 }
695- } else {
696- statusEl . textContent = 'Score submitted' ;
697- statusEl . style . color = 'var(--text-secondary)' ;
698692 }
693+ } else {
694+ statusEl . innerHTML = `<span class="leaderboard-rank">${ rankText } on the leaderboard</span>` ;
699695 }
700696
701697 } catch ( error ) {
702698 console . error ( 'Score submission failed:' , error ) ;
703- if ( statusEl ) {
704- statusEl . textContent = 'Submission failed' ;
705- statusEl . style . color = '#E84E6A' ;
706- }
699+ statusEl . textContent = 'Submission failed' ;
700+ statusEl . style . color = '#E84E6A' ;
707701 }
708702 }
709703
0 commit comments