mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-10 15:27:27 +07:00
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:
parent
efef41541c
commit
1cba56c947
@ -1,6 +1,24 @@
|
||||
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
|
||||
get() {
|
||||
@ -38,3 +56,5 @@ class GameSettings : LinkedHashMap<String, String>() {
|
||||
this["Resolution"]=value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
@ -12,7 +12,7 @@ import com.unciv.ui.utils.getRandom
|
||||
|
||||
class GameInfo {
|
||||
var notifications = mutableListOf<Notification>()
|
||||
var tutorial = mutableListOf<String>()
|
||||
@Deprecated("As of 2.6.9") var tutorial = mutableListOf<String>()
|
||||
var civilizations = mutableListOf<CivilizationInfo>()
|
||||
var tileMap: TileMap = TileMap()
|
||||
var turns = 0
|
||||
|
@ -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){
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,6 @@ class NewGameScreen: PickerScreen(){
|
||||
newGame = GameStarter().startNewGame(
|
||||
worldSizeToRadius[worldSizeSelectBox.selected]!!, enemiesSelectBox.selected,
|
||||
civSelectBox.selected, difficultySelectBox.selected )
|
||||
.apply { tutorial=game.gameInfo.tutorial }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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{
|
||||
|
@ -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()
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user