Skip to content

Commit

Permalink
feat(view): add replay loading to game creation view and generify
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed Oct 2, 2023
1 parent bd94111 commit fa59d7b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ for details on our versioning scheme.
### 24.1.X - 2023-10-XX
- Indicate ship speed through graphics
- Fix missing pixels between current
- Fix double turn advances in replays

### 24.1.4 Guide - 2023-09-29
### 24.1.4 Guidance - 2023-10
- Update instructions and merge into game creation screen
- Fix regression: double turn advances in replays

### 24.1.3 Edge Infos - 2023-09-21
- Highlight available Push target fields
Expand Down
17 changes: 17 additions & 0 deletions src/main/kotlin/sc/gui/controller/GameFlowController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package sc.gui.controller
import javafx.animation.Animation
import javafx.animation.KeyFrame
import javafx.animation.Timeline
import javafx.stage.FileChooser
import javafx.util.Duration
import mu.KotlinLogging
import sc.api.plugins.IGameState
import sc.framework.HelperMethods
import sc.gui.GamePausedEvent
import sc.gui.GameReadyEvent
import sc.gui.NewGameState
Expand All @@ -16,6 +18,21 @@ import sc.networking.clients.IGameController
import tornadofx.*
import java.io.IOException

fun View.selectReplay(onConfirm: () -> Unit = {}) {
chooseFile("Replay laden",
arrayOf(FileChooser.ExtensionFilter("XML", "*.xml", "*.xml.gz")),
HelperMethods.replayFolder.takeIf { it.exists() },
mode = FileChooserMode.Single,
).forEach {
onConfirm()
try {
find(GameFlowController::class).loadReplay(GameLoaderClient(it))
} catch(e: Exception) {
warning("Replay laden fehlgeschlagen", "Das Replay $it konnte nicht geladen werden:\n" + e.stackTraceToString())
}
}
}

class GameFlowController: Controller() {
private val logger = KotlinLogging.logger {}

Expand Down
13 changes: 2 additions & 11 deletions src/main/kotlin/sc/gui/view/AppView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package sc.gui.view

import javafx.application.Platform
import javafx.scene.control.Alert
import javafx.stage.FileChooser
import mu.KotlinLogging
import sc.gui.AppStyle
import sc.gui.controller.AppController
import sc.gui.controller.CreateGame
import sc.gui.controller.GameFlowController
import sc.gui.controller.selectReplay
import sc.gui.events.*
import sc.gui.guideMq
import sc.gui.model.ViewType
import sc.networking.clients.GameLoaderClient
import sc.util.browse
import sc.util.browseUrl
import sc.util.listenImmediately
Expand Down Expand Up @@ -52,17 +51,9 @@ class AppView: View("Software-Challenge Germany") {
}
separator()
item("Replay laden", "Shortcut+R").action {
chooseFile("Replay laden",
arrayOf(FileChooser.ExtensionFilter("XML", "*.xml", "*.xml.gz")),
File("replays").takeIf { it.exists() }
).forEach {
selectReplay {
if(controller.model.currentView.get() == ViewType.GAME)
fire(TerminateGame())
try {
gameFlowController.loadReplay(GameLoaderClient(it))
} catch(e: Exception) {
warning("Replay laden fehlgeschlagen", "Das Replay $it konnte nicht geladen werden:\n" + e.stackTraceToString())
}
}
}
item("Logs öffnen", "Shortcut+L").action {
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/sc/gui/view/GameCreationView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import javafx.stage.FileChooser
import sc.api.plugins.Team
import sc.gui.AppStyle
import sc.gui.controller.StartGame
import sc.gui.controller.selectReplay
import sc.gui.guideMq
import sc.gui.model.PlayerType
import sc.gui.model.TeamSettings
Expand Down Expand Up @@ -54,6 +55,9 @@ class GameCreationView: View() {
}
}
}
top = hbox(AppStyle.spacing, Pos.CENTER_RIGHT) {
button("Replay laden").action { selectReplay() }
}
bottom = hbox(AppStyle.spacing, Pos.CENTER_RIGHT) {
button("Erstellen") {
action {
Expand Down

0 comments on commit fa59d7b

Please sign in to comment.