Skip to content

Commit

Permalink
fixed duplicate writes
Browse files Browse the repository at this point in the history
  • Loading branch information
daerup committed May 12, 2024
1 parent 8bd496b commit 285d2df
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 121 deletions.
41 changes: 0 additions & 41 deletions Schnacc.Authorization.UnitTests/AuthorizationApiTest.cs

This file was deleted.

This file was deleted.

30 changes: 0 additions & 30 deletions Schnacc.Database.UnitTests/FirebaseDatabaseTest.cs

This file was deleted.

23 changes: 0 additions & 23 deletions Schnacc.Database.UnitTests/Schnacc.Database.UnitTests.csproj

This file was deleted.

5 changes: 3 additions & 2 deletions Schnacc.UserInterface/PlayAreaView/PlayAreaPageView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@
</Grid>
<Grid DockPanel.Dock="Left">
<Grid.RowDefinitions>
<RowDefinition Height="15*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="80*"/>
<RowDefinition Height="20*"/>
<RowDefinition Height="17*"/>
</Grid.RowDefinitions>
<Grid Visibility="{Binding Path=ErrorIsVisible, Converter={StaticResource BoolToVisibilityConverter}}">
<Grid.RowDefinitions>
<RowDefinition Height="40*"/>
<RowDefinition Height="40*"/>
</Grid.RowDefinitions>
<TextBlock
Margin="0,10"
Text="Please Login save your highscore"
Style="{StaticResource InputFontContent}"
TextWrapping="Wrap"
Expand Down
11 changes: 6 additions & 5 deletions Schnacc.UserInterface/PlayAreaView/PlayAreaPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ public class PlayAreaViewModel : ViewModelBase, INavigableViewModel
private DateTime _lastDirectionChange;
private readonly int _difficultyLevel;
private int _slowMotionTicks;

private object writingHighScoreLock = new object();
private bool _highScoreIsWritten;

private bool IsAllowedToWriteHighScore => !this._highScoreIsWritten && this.NavigationService.AuthorizationApi.IsAnonymous && this.NavigationService.AuthorizationApi.EmailIsVerified;
private bool UserIsAllowedToWriteHighScore => !this.NavigationService.AuthorizationApi.IsAnonymous && this.NavigationService.AuthorizationApi.EmailIsVerified;
private bool SlowMotionIsActive => !this._slowMotionTicks.Equals(0);
private string SnakeColor => !this.SlowMotionIsActive ? "#3d9e31" : "#6cf85b";
private string FoodColor => !this.SlowMotionIsActive ? "#f93910" :"#ff33cc";
Expand Down Expand Up @@ -207,15 +209,14 @@ private void OnRenderUpdate(object newGameState)

private async Task CheckForGameState()
{
if (this.GameIsOver && this.SessionTokenPresent)
if (this.GameIsOver)
{
if (this.IsAllowedToWriteHighScore)
if (this.UserIsAllowedToWriteHighScore && !this._highScoreIsWritten)
{
this._highScoreIsWritten = true;
var newHighScore = new Highscore(this.NavigationService.AuthorizationApi.Username, this.Score);
await this._firebaseDatabase.WriteHighScore(newHighScore);
this._highScoreIsWritten = true;
}

await this._movementTimer.DisposeAsync();
await this._renderTimer.DisposeAsync();
}
Expand Down

0 comments on commit 285d2df

Please sign in to comment.