Tutorials shown are now per-device (in the game settings) rather than per-game

Game settings are now saved as a proper class, found how to ignore unknown properties in json! =)
This commit is contained in:
Yair Morgenstern 2018-07-26 13:15:38 +03:00
parent efef41541c
commit 1cba56c947
10 changed files with 41 additions and 18 deletions

View File

@ -1,6 +1,24 @@
package com.unciv package com.unciv
class GameSettings : LinkedHashMap<String, String>() { class GameSettings {
var showWorkedTiles: Boolean = true
var showResourcesAndImprovements: Boolean = true
var language: String = "English"
var resolution: String = "1050x700"
var tutorialsShown = ArrayList<String>()
}
@Deprecated("as of 2.6.9")
class OldGameSettings : LinkedHashMap<String, String>() {
fun toGameSettings(): GameSettings {
val newSettings = GameSettings()
newSettings.showResourcesAndImprovements = showResourcesAndImprovements
newSettings.showWorkedTiles = showWorkedTiles
newSettings.language = language
newSettings.resolution = resolution
return newSettings
}
var showWorkedTiles:Boolean var showWorkedTiles:Boolean
get() { get() {
@ -38,3 +56,5 @@ class GameSettings : LinkedHashMap<String, String>() {
this["Resolution"]=value this["Resolution"]=value
} }
} }

View File

@ -2,6 +2,7 @@ package com.unciv
import com.badlogic.gdx.Game import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.utils.Json
import com.unciv.logic.GameInfo import com.unciv.logic.GameInfo
import com.unciv.logic.GameSaver import com.unciv.logic.GameSaver
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
@ -10,6 +11,7 @@ import com.unciv.ui.worldscreen.WorldScreen
class UnCivGame : Game() { class UnCivGame : Game() {
var gameInfo: GameInfo = GameInfo() var gameInfo: GameInfo = GameInfo()
lateinit var settings : GameSettings lateinit var settings : GameSettings
val json = Json().apply { setIgnoreDeprecated(true); setIgnoreUnknownFields(true) }
/** /**
* This exists so that when debugging we can see the entire map. * This exists so that when debugging we can see the entire map.
@ -21,9 +23,9 @@ class UnCivGame : Game() {
lateinit var worldScreen: WorldScreen lateinit var worldScreen: WorldScreen
override fun create() { override fun create() {
Current = this
GameBasics.run { } // just to initialize GameBasics.run { } // just to initialize
settings = GameSaver().getGeneralSettings() settings = GameSaver().getGeneralSettings()
Current = this
if (GameSaver().getSave("Autosave").exists()) { if (GameSaver().getSave("Autosave").exists()) {
try { try {
loadGame("Autosave") loadGame("Autosave")
@ -36,6 +38,9 @@ class UnCivGame : Game() {
fun loadGame(gameInfo:GameInfo){ fun loadGame(gameInfo:GameInfo){
this.gameInfo = gameInfo this.gameInfo = gameInfo
if(settings.tutorialsShown.isEmpty() && this.gameInfo.tutorial.isNotEmpty())
settings.tutorialsShown.addAll(this.gameInfo.tutorial)
worldScreen = WorldScreen() worldScreen = WorldScreen()
setWorldScreen() setWorldScreen()
} }
@ -44,11 +49,8 @@ class UnCivGame : Game() {
loadGame(GameSaver().loadGame( gameName)) loadGame(GameSaver().loadGame( gameName))
} }
fun startNewGame(saveTutorialState:Boolean = false) { fun startNewGame() {
val newGame = GameStarter().startNewGame(20, 3, "Babylon","Chieftain") val newGame = GameStarter().startNewGame(20, 3, "Babylon","Chieftain")
if(saveTutorialState) {
newGame.tutorial = gameInfo.tutorial
}
gameInfo = newGame gameInfo = newGame
worldScreen = WorldScreen() worldScreen = WorldScreen()

View File

@ -12,7 +12,7 @@ import com.unciv.ui.utils.getRandom
class GameInfo { class GameInfo {
var notifications = mutableListOf<Notification>() var notifications = mutableListOf<Notification>()
var tutorial = mutableListOf<String>() @Deprecated("As of 2.6.9") var tutorial = mutableListOf<String>()
var civilizations = mutableListOf<CivilizationInfo>() var civilizations = mutableListOf<CivilizationInfo>()
var tileMap: TileMap = TileMap() var tileMap: TileMap = TileMap()
var turns = 0 var turns = 0

View File

@ -4,6 +4,8 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.files.FileHandle import com.badlogic.gdx.files.FileHandle
import com.badlogic.gdx.utils.Json import com.badlogic.gdx.utils.Json
import com.unciv.GameSettings import com.unciv.GameSettings
import com.unciv.OldGameSettings
import com.unciv.UnCivGame
class GameSaver { class GameSaver {
private val saveFilesFolder = "SaveFiles" private val saveFilesFolder = "SaveFiles"
@ -37,7 +39,12 @@ class GameSaver {
fun getGeneralSettings(): GameSettings { fun getGeneralSettings(): GameSettings {
val settingsFile = getGeneralSettingsFile() val settingsFile = getGeneralSettingsFile()
if(!settingsFile.exists()) return GameSettings() 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){ fun setGeneralSettings(gameSettings: GameSettings){

View File

@ -14,7 +14,6 @@ import com.unciv.ui.utils.tr
open class TileInfo { open class TileInfo {
@Transient lateinit var tileMap: TileMap @Transient lateinit var tileMap: TileMap
var unit:MapUnit?=null
var militaryUnit:MapUnit?=null var militaryUnit:MapUnit?=null
var civilianUnit:MapUnit?=null var civilianUnit:MapUnit?=null
fun getUnits()= listOf(militaryUnit,civilianUnit).filterNotNull() fun getUnits()= listOf(militaryUnit,civilianUnit).filterNotNull()

View File

@ -66,10 +66,6 @@ class TileMap {
fun setTransients() { fun setTransients() {
for (tileInfo in values){ for (tileInfo in values){
tileInfo.tileMap = this 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
}
} }
} }

View File

@ -70,7 +70,6 @@ class NewGameScreen: PickerScreen(){
newGame = GameStarter().startNewGame( newGame = GameStarter().startNewGame(
worldSizeToRadius[worldSizeSelectBox.selected]!!, enemiesSelectBox.selected, worldSizeToRadius[worldSizeSelectBox.selected]!!, enemiesSelectBox.selected,
civSelectBox.selected, difficultySelectBox.selected ) civSelectBox.selected, difficultySelectBox.selected )
.apply { tutorial=game.gameInfo.tutorial }
} }
} }

View File

@ -52,7 +52,7 @@ class VictoryScreen : PickerScreen() {
rightSideButton.isVisible=true rightSideButton.isVisible=true
closeButton.isVisible=false closeButton.isVisible=false
rightSideButton.enable() rightSideButton.enable()
rightSideButton.addClickListener { UnCivGame.Current.startNewGame(true) } rightSideButton.addClickListener { UnCivGame.Current.startNewGame() }
} }
fun scienceVictoryColumn():Table{ fun scienceVictoryColumn():Table{

View File

@ -60,8 +60,8 @@ open class CameraStageBaseScreen : Screen {
override fun dispose() {} override fun dispose() {}
fun displayTutorials(name: String) { fun displayTutorials(name: String) {
if (game.gameInfo.tutorial.contains(name)) return if (UnCivGame.Current.settings.tutorialsShown.contains(name)) return
game.gameInfo.tutorial.add(name) UnCivGame.Current.settings.tutorialsShown.add(name)
val texts = GameBasics.Tutorials[name]!! val texts = GameBasics.Tutorials[name]!!
tutorialTexts.addAll(texts) tutorialTexts.addAll(texts)
if (!isTutorialShowing) displayTutorial() if (!isTutorialShowing) displayTutorial()

View File

@ -85,7 +85,7 @@ class WorldScreen : CameraStageBaseScreen() {
fun update() { fun update() {
kotlin.concurrent.thread { civInfo.happiness = civInfo.getHappinessForNextTurn().values.sum().toInt() } 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") displayTutorials("AfterCityEntered")
} }