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

73 lines
2 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.badlogic.gdx.utils.Json
2018-03-02 13:34:24 +00:00
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
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
val json = Json().apply { setIgnoreDeprecated(true); setIgnoreUnknownFields(true) }
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
2018-05-29 19:01:22 +00:00
GameBasics.run { } // just to initialize
settings = GameSaver().getGeneralSettings()
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 screen=LanguagePickerScreen() //startNewGame()
}
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() {
2018-07-25 19:56:25 +00:00
val newGame = GameStarter().startNewGame(20, 3, "Babylon","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
}
companion object {
lateinit var Current: UnCivGame
}
}