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

76 lines
2.1 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.NewGameScreen
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
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()) {
2018-10-28 14:37:51 +00:00
// try {
loadGame("Autosave")
2018-10-28 14:37:51 +00:00
// } catch (ex: Exception) { // silent fail if we can't read the autosave
// startNewGame()
// }
2018-03-02 13:34:24 +00:00
}
else startNewGame() // screen=LanguagePickerScreen() disabled because of people's negative reviews =(
}
2018-03-02 13:34:24 +00:00
fun loadGame(gameInfo:GameInfo){
this.gameInfo = gameInfo
if(settings.tutorialsShown.isEmpty() && this.gameInfo.tutorial.isNotEmpty())
settings.tutorialsShown.addAll(this.gameInfo.tutorial)
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(NewGameScreen.NewGameParameters().apply { difficulty="Chieftain" })
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
2018-03-02 13:34:24 +00:00
}
override fun resume() {
ImageGetter.refreshAltas()
worldScreen = WorldScreen()
setWorldScreen()
}
2018-03-02 13:34:24 +00:00
companion object {
lateinit var Current: UnCivGame
}
}