Unciv/core/src/com/unciv/UnCivGame.kt

62 lines
1.5 KiB
Kotlin
Raw Normal View History

2018-04-11 20:46:00 +00:00
package com.unciv
2018-03-02 13:34:24 +00:00
import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx
import com.unciv.logic.GameInfo
import com.unciv.logic.GameSaver
2018-05-29 19:01:22 +00:00
import com.unciv.models.gamebasics.GameBasics
2018-04-11 20:46:00 +00:00
import com.unciv.ui.GameSettings
import com.unciv.ui.NewGameScreen
2018-03-02 13:34:24 +00:00
import com.unciv.ui.worldscreen.WorldScreen
class UnCivGame : Game() {
var gameInfo: GameInfo = GameInfo()
var settings = GameSettings()
var worldScreen: WorldScreen? = null
2018-03-02 13:34:24 +00:00
override fun create() {
2018-05-29 19:01:22 +00:00
GameBasics.run { } // just to initialize
2018-03-02 13:34:24 +00:00
Current = this
if (GameSaver().getSave("Autosave").exists()) {
2018-03-02 13:34:24 +00:00
try {
loadGame("Autosave")
2018-03-02 13:34:24 +00:00
} catch (ex: Exception) { // silent fail if we can't read the autosave
startNewGame()
}
}
else startNewGame()
}
2018-03-02 13:34:24 +00:00
fun loadGame(gameName:String){
gameInfo = GameSaver().loadGame( gameName)
2018-03-02 13:34:24 +00:00
worldScreen = WorldScreen()
setWorldScreen()
}
fun startNewGame(saveTutorialState:Boolean = false) {
2018-05-29 19:01:22 +00:00
val newGame = GameStarter().startNewGame(20, 3, "Babylon")
if(saveTutorialState) {
2018-05-29 19:01:22 +00:00
newGame.tutorial = gameInfo.tutorial
}
2018-05-29 19:01:22 +00:00
gameInfo = newGame
2018-03-02 13:34:24 +00:00
worldScreen = WorldScreen()
setWorldScreen()
2018-03-02 13:34:24 +00:00
}
fun setWorldScreen() {
setScreen(worldScreen)
worldScreen!!.update()
Gdx.input.inputProcessor = worldScreen!!.stage
}
companion object {
lateinit var Current: UnCivGame
}
}