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
|
2018-05-29 10:05:16 +00:00
|
|
|
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
|
2018-03-02 13:34:24 +00:00
|
|
|
import com.unciv.ui.worldscreen.WorldScreen
|
|
|
|
|
|
|
|
class UnCivGame : Game() {
|
|
|
|
var gameInfo: GameInfo = GameInfo()
|
|
|
|
var settings = GameSettings()
|
|
|
|
|
2018-05-31 16:46:11 +00:00
|
|
|
lateinit var worldScreen: WorldScreen
|
2018-05-06 05:55:20 +00:00
|
|
|
|
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
|
2018-05-29 10:05:16 +00:00
|
|
|
if (GameSaver().getSave("Autosave").exists()) {
|
2018-03-02 13:34:24 +00:00
|
|
|
try {
|
2018-05-06 05:55:20 +00:00
|
|
|
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-05-06 05:55:20 +00:00
|
|
|
}
|
2018-03-02 13:34:24 +00:00
|
|
|
|
2018-05-06 05:55:20 +00:00
|
|
|
fun loadGame(gameName:String){
|
2018-05-29 10:05:16 +00:00
|
|
|
gameInfo = GameSaver().loadGame( gameName)
|
2018-03-02 13:34:24 +00:00
|
|
|
worldScreen = WorldScreen()
|
|
|
|
setWorldScreen()
|
|
|
|
}
|
|
|
|
|
2018-04-02 12:16:28 +00:00
|
|
|
fun startNewGame(saveTutorialState:Boolean = false) {
|
2018-05-29 19:01:22 +00:00
|
|
|
val newGame = GameStarter().startNewGame(20, 3, "Babylon")
|
2018-04-02 12:16:28 +00:00
|
|
|
if(saveTutorialState) {
|
2018-05-29 19:01:22 +00:00
|
|
|
newGame.tutorial = gameInfo.tutorial
|
2018-04-25 20:47:03 +00:00
|
|
|
}
|
2018-05-29 19:01:22 +00:00
|
|
|
gameInfo = newGame
|
2018-03-02 13:34:24 +00:00
|
|
|
|
|
|
|
worldScreen = WorldScreen()
|
|
|
|
setWorldScreen()
|
2018-05-06 15:03:49 +00:00
|
|
|
|
2018-03-02 13:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fun setWorldScreen() {
|
|
|
|
setScreen(worldScreen)
|
2018-05-31 16:46:11 +00:00
|
|
|
worldScreen.update()
|
|
|
|
Gdx.input.inputProcessor = worldScreen.stage
|
2018-03-02 13:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
lateinit var Current: UnCivGame
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|