Skip to content

Commit d4626c4

Browse files
committed
Fix: Games stats were being added twice
1 parent 8e12696 commit d4626c4

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

core/src/main/kotlin/ogz/tripeaks/screens/GameScreen.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class GameScreen(private val context: Context) : KtxScreen, InputAdapter() {
160160
private fun stalledDialogCallback(result: StalledDialogResult) {
161161
when (result) {
162162
StalledDialogResult.NEW_GAME -> {
163-
game?.let { playerStatistics.addLose(it.statistics) }
163+
addStat()
164164
startNewGame()
165165
}
166166

@@ -170,7 +170,10 @@ class GameScreen(private val context: Context) : KtxScreen, InputAdapter() {
170170

171171
private fun winDialogCallback(result: WinDialogResult) {
172172
when (result) {
173-
WinDialogResult.NEW_GAME -> startNewGame()
173+
WinDialogResult.NEW_GAME -> {
174+
addStat()
175+
startNewGame()
176+
}
174177
WinDialogResult.EXIT -> Gdx.app.exit()
175178
}
176179
}
@@ -181,7 +184,6 @@ class GameScreen(private val context: Context) : KtxScreen, InputAdapter() {
181184

182185
private fun onWon() {
183186
game?.also { game ->
184-
playerStatistics.addWin(game.statistics)
185187
val dialog = WinDialog(
186188
settings.get().skin,
187189
assets,
@@ -246,13 +248,7 @@ class GameScreen(private val context: Context) : KtxScreen, InputAdapter() {
246248
}
247249

248250
private fun onNewGame() {
249-
game?.let { game ->
250-
if (game.won) {
251-
playerStatistics.addWin(game.statistics)
252-
} else if (game.wasPlayed) {
253-
playerStatistics.addLose(game.statistics)
254-
}
255-
}
251+
addStat()
256252
menu = null
257253
startNewGame()
258254
}
@@ -308,9 +304,6 @@ class GameScreen(private val context: Context) : KtxScreen, InputAdapter() {
308304
}
309305

310306
private fun setupGame(game: GameState) {
311-
this.game?.also {
312-
if (!it.won && it.wasPlayed) playerStatistics.addLose(game.statistics)
313-
}
314307
this.game = game
315308
view.currentGame = game
316309
switch.setGame(game)
@@ -321,4 +314,14 @@ class GameScreen(private val context: Context) : KtxScreen, InputAdapter() {
321314
setupGame(settings.getNewGame())
322315
}
323316

317+
private fun addStat() {
318+
game?.let { game ->
319+
if (game.won) {
320+
playerStatistics.addWin(game.statistics)
321+
} else if (game.wasPlayed) {
322+
playerStatistics.addLose(game.statistics)
323+
}
324+
}
325+
}
326+
324327
}

0 commit comments

Comments
 (0)