diff --git a/core/src/com/unciv/GameSettings.kt b/core/src/com/unciv/GameSettings.kt index 1f993828ae..cfc1f89121 100644 --- a/core/src/com/unciv/GameSettings.kt +++ b/core/src/com/unciv/GameSettings.kt @@ -1,6 +1,24 @@ package com.unciv -class GameSettings : LinkedHashMap() { +class GameSettings { + var showWorkedTiles: Boolean = true + var showResourcesAndImprovements: Boolean = true + var language: String = "English" + var resolution: String = "1050x700" + var tutorialsShown = ArrayList() +} + + +@Deprecated("as of 2.6.9") +class OldGameSettings : LinkedHashMap() { + fun toGameSettings(): GameSettings { + val newSettings = GameSettings() + newSettings.showResourcesAndImprovements = showResourcesAndImprovements + newSettings.showWorkedTiles = showWorkedTiles + newSettings.language = language + newSettings.resolution = resolution + return newSettings + } var showWorkedTiles:Boolean get() { @@ -38,3 +56,5 @@ class GameSettings : LinkedHashMap() { this["Resolution"]=value } } + + diff --git a/core/src/com/unciv/UnCivGame.kt b/core/src/com/unciv/UnCivGame.kt index fc18156463..5a4cc8c5f3 100644 --- a/core/src/com/unciv/UnCivGame.kt +++ b/core/src/com/unciv/UnCivGame.kt @@ -2,6 +2,7 @@ package com.unciv import com.badlogic.gdx.Game import com.badlogic.gdx.Gdx +import com.badlogic.gdx.utils.Json import com.unciv.logic.GameInfo import com.unciv.logic.GameSaver import com.unciv.models.gamebasics.GameBasics @@ -10,6 +11,7 @@ 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) } /** * This exists so that when debugging we can see the entire map. @@ -21,9 +23,9 @@ class UnCivGame : Game() { lateinit var worldScreen: WorldScreen override fun create() { + Current = this GameBasics.run { } // just to initialize settings = GameSaver().getGeneralSettings() - Current = this if (GameSaver().getSave("Autosave").exists()) { try { loadGame("Autosave") @@ -36,6 +38,9 @@ class UnCivGame : Game() { fun loadGame(gameInfo:GameInfo){ this.gameInfo = gameInfo + if(settings.tutorialsShown.isEmpty() && this.gameInfo.tutorial.isNotEmpty()) + settings.tutorialsShown.addAll(this.gameInfo.tutorial) + worldScreen = WorldScreen() setWorldScreen() } @@ -44,11 +49,8 @@ class UnCivGame : Game() { loadGame(GameSaver().loadGame( gameName)) } - fun startNewGame(saveTutorialState:Boolean = false) { + fun startNewGame() { val newGame = GameStarter().startNewGame(20, 3, "Babylon","Chieftain") - if(saveTutorialState) { - newGame.tutorial = gameInfo.tutorial - } gameInfo = newGame worldScreen = WorldScreen() diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index cfbec4f11e..68675d7089 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -12,7 +12,7 @@ import com.unciv.ui.utils.getRandom class GameInfo { var notifications = mutableListOf() - var tutorial = mutableListOf() + @Deprecated("As of 2.6.9") var tutorial = mutableListOf() var civilizations = mutableListOf() var tileMap: TileMap = TileMap() var turns = 0 diff --git a/core/src/com/unciv/logic/GameSaver.kt b/core/src/com/unciv/logic/GameSaver.kt index fbc0d34cfe..8814fa3611 100644 --- a/core/src/com/unciv/logic/GameSaver.kt +++ b/core/src/com/unciv/logic/GameSaver.kt @@ -4,6 +4,8 @@ import com.badlogic.gdx.Gdx import com.badlogic.gdx.files.FileHandle import com.badlogic.gdx.utils.Json import com.unciv.GameSettings +import com.unciv.OldGameSettings +import com.unciv.UnCivGame class GameSaver { private val saveFilesFolder = "SaveFiles" @@ -37,7 +39,12 @@ class GameSaver { fun getGeneralSettings(): GameSettings { val settingsFile = getGeneralSettingsFile() if(!settingsFile.exists()) return GameSettings() - return Json().fromJson(GameSettings::class.java, settingsFile) + try { + return UnCivGame.Current.json.fromJson(GameSettings::class.java, settingsFile) + } + catch(ex:Exception) { + return UnCivGame.Current.json.fromJson(OldGameSettings::class.java, settingsFile).toGameSettings() + } } fun setGeneralSettings(gameSettings: GameSettings){ diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 0a21458b7e..e0db7abb75 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -14,7 +14,6 @@ import com.unciv.ui.utils.tr open class TileInfo { @Transient lateinit var tileMap: TileMap - var unit:MapUnit?=null var militaryUnit:MapUnit?=null var civilianUnit:MapUnit?=null fun getUnits()= listOf(militaryUnit,civilianUnit).filterNotNull() diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index 4c532cef35..ae5619e675 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -66,10 +66,6 @@ class TileMap { fun setTransients() { for (tileInfo in values){ tileInfo.tileMap = this - if(tileInfo.unit!=null){ // thi is for the old "unit" field which has been replaced. - tileInfo.unit!!.putInTile(tileInfo) - tileInfo.unit=null - } } } diff --git a/core/src/com/unciv/ui/NewGameScreen.kt b/core/src/com/unciv/ui/NewGameScreen.kt index 35020c6e3b..6affec2d64 100644 --- a/core/src/com/unciv/ui/NewGameScreen.kt +++ b/core/src/com/unciv/ui/NewGameScreen.kt @@ -70,7 +70,6 @@ class NewGameScreen: PickerScreen(){ newGame = GameStarter().startNewGame( worldSizeToRadius[worldSizeSelectBox.selected]!!, enemiesSelectBox.selected, civSelectBox.selected, difficultySelectBox.selected ) - .apply { tutorial=game.gameInfo.tutorial } } } diff --git a/core/src/com/unciv/ui/VictoryScreen.kt b/core/src/com/unciv/ui/VictoryScreen.kt index 992580442a..b6871d95e7 100644 --- a/core/src/com/unciv/ui/VictoryScreen.kt +++ b/core/src/com/unciv/ui/VictoryScreen.kt @@ -52,7 +52,7 @@ class VictoryScreen : PickerScreen() { rightSideButton.isVisible=true closeButton.isVisible=false rightSideButton.enable() - rightSideButton.addClickListener { UnCivGame.Current.startNewGame(true) } + rightSideButton.addClickListener { UnCivGame.Current.startNewGame() } } fun scienceVictoryColumn():Table{ diff --git a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt index 952b7560c8..ffd2e778a9 100644 --- a/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt +++ b/core/src/com/unciv/ui/utils/CameraStageBaseScreen.kt @@ -60,8 +60,8 @@ open class CameraStageBaseScreen : Screen { override fun dispose() {} fun displayTutorials(name: String) { - if (game.gameInfo.tutorial.contains(name)) return - game.gameInfo.tutorial.add(name) + if (UnCivGame.Current.settings.tutorialsShown.contains(name)) return + UnCivGame.Current.settings.tutorialsShown.add(name) val texts = GameBasics.Tutorials[name]!! tutorialTexts.addAll(texts) if (!isTutorialShowing) displayTutorial() diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index ebf5e0aacb..24a55ffd12 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -85,7 +85,7 @@ class WorldScreen : CameraStageBaseScreen() { fun update() { kotlin.concurrent.thread { civInfo.happiness = civInfo.getHappinessForNextTurn().values.sum().toInt() } - if (game.gameInfo.tutorial.contains("CityEntered")) { + if (UnCivGame.Current.settings.tutorialsShown.contains("CityEntered")) { displayTutorials("AfterCityEntered") }