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

89 lines
2.7 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
import com.unciv.ui.LanguagePickerScreen
import com.unciv.ui.utils.ImageGetter
2018-03-02 13:34:24 +00:00
import com.unciv.ui.worldscreen.WorldScreen
class UnCivGame : Game() {
var gameInfo: GameInfo = GameInfo()
lateinit var settings : GameSettings
2018-03-02 13:34:24 +00:00
/**
* This exists so that when debugging we can see the entire map.
* Remember to turn this to false before commit and upload!
*/
val viewEntireMapForDebug = false
// For when you need to test something in an advanced game and don't have time to faff around
val superchargedForDebug = false
lateinit var worldScreen: WorldScreen
2018-03-02 13:34:24 +00:00
override fun create() {
Current = this
Gdx.input.isCatchBackKey=true
2018-10-12 12:02:12 +00:00
GameBasics.run { } // just to initialize the GameBasics
settings = GameSaver().getGeneralSettings()
if (GameSaver().getSave("Autosave").exists()) {
try {
loadGame("Autosave")
} catch (ex: Exception) { // silent fail if we can't read the autosave
startNewGame()
}
2018-03-02 13:34:24 +00:00
}
else screen= LanguagePickerScreen()
}
2018-03-02 13:34:24 +00:00
fun loadGame(gameInfo:GameInfo){
this.gameInfo = gameInfo
2018-03-02 13:34:24 +00:00
worldScreen = WorldScreen()
setWorldScreen()
}
fun loadGame(gameName:String){
loadGame(GameSaver().loadGame( gameName))
}
fun startNewGame() {
val newGame = GameStarter().startNewGame(GameParameters().apply { difficulty="Chieftain" })
2018-05-29 19:01:22 +00:00
gameInfo = newGame
2018-03-02 13:34:24 +00:00
worldScreen = WorldScreen()
setWorldScreen()
}
fun setWorldScreen() {
setScreen(worldScreen)
Gdx.input.inputProcessor = worldScreen.stage
worldScreen.shouldUpdate=true // This can set the screen to the policy picker or tech picker screen, so the input processor must come before
2018-03-02 13:34:24 +00:00
}
override fun resume() {
super.resume()
ImageGetter.refreshAltas()
// This is to solve a rare problem that I still on't understand its cause -
// Sometimes, resume() is called and the gameInfo doesn't have any civilizations.
// My guess is that resume() was called but create() wasn't, or perhaps was aborted too early,
// and the original (and empty) initial GameInfo remained.
if(gameInfo.civilizations.isEmpty())
return create()
worldScreen = WorldScreen()
setWorldScreen()
}
// Maybe this will solve the resume error on chrome OS, issue 322? Worth a shot
override fun resize(width: Int, height: Int) {
resume()
}
2018-03-02 13:34:24 +00:00
companion object {
lateinit var Current: UnCivGame
}
}