mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-07 00:41:39 +07:00
Json is apparently not thread safe, so we now create a new instance for each stringify
This commit is contained in:
@ -21,8 +21,8 @@ android {
|
|||||||
applicationId "com.unciv.game"
|
applicationId "com.unciv.game"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 122
|
versionCode 124
|
||||||
versionName "2.7.9"
|
versionName "2.7.9.2"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@ -2,7 +2,6 @@ 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
|
||||||
@ -12,7 +11,6 @@ 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.
|
||||||
|
@ -22,8 +22,8 @@ class GameInfo {
|
|||||||
//region pure functions
|
//region pure functions
|
||||||
fun clone():GameInfo{
|
fun clone():GameInfo{
|
||||||
val toReturn = GameInfo()
|
val toReturn = GameInfo()
|
||||||
toReturn.civilizations.addAll(civilizations.map { it.clone() })
|
|
||||||
toReturn.tileMap=tileMap.clone()
|
toReturn.tileMap=tileMap.clone()
|
||||||
|
toReturn.civilizations.addAll(civilizations.map { it.clone() })
|
||||||
toReturn.notifications.addAll(notifications)
|
toReturn.notifications.addAll(notifications)
|
||||||
toReturn.turns=turns
|
toReturn.turns=turns
|
||||||
toReturn.setTransients()
|
toReturn.setTransients()
|
||||||
|
@ -2,14 +2,14 @@ package com.unciv.logic
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
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.unciv.GameSettings
|
import com.unciv.GameSettings
|
||||||
import com.unciv.OldGameSettings
|
import com.unciv.OldGameSettings
|
||||||
import com.unciv.UnCivGame
|
|
||||||
|
|
||||||
class GameSaver {
|
class GameSaver {
|
||||||
private val saveFilesFolder = "SaveFiles"
|
private val saveFilesFolder = "SaveFiles"
|
||||||
|
|
||||||
fun json() = UnCivGame.Current.json
|
fun json() = Json().apply { setIgnoreDeprecated(true); setIgnoreUnknownFields(true) } // Json() is NOT THREAD SAFE so we need to create a new one for each function
|
||||||
|
|
||||||
fun getSave(GameName: String): FileHandle {
|
fun getSave(GameName: String): FileHandle {
|
||||||
return Gdx.files.local("$saveFilesFolder/$GameName")
|
return Gdx.files.local("$saveFilesFolder/$GameName")
|
||||||
|
@ -55,12 +55,12 @@ class HexMath {
|
|||||||
}
|
}
|
||||||
for (i in 0 until distance) { // 8 to 10
|
for (i in 0 until distance) { // 8 to 10
|
||||||
vectors.add(Current.cpy())
|
vectors.add(Current.cpy())
|
||||||
vectors.add(origin.cpy().scl(2f).sub(Current)) // Get vector on other side of cloick
|
vectors.add(origin.cpy().scl(2f).sub(Current)) // Get vector on other side of clock
|
||||||
Current.add(1f, 1f)
|
Current.add(1f, 1f)
|
||||||
}
|
}
|
||||||
for (i in 0 until distance) { // 10 to 12
|
for (i in 0 until distance) { // 10 to 12
|
||||||
vectors.add(Current.cpy())
|
vectors.add(Current.cpy())
|
||||||
vectors.add(origin.cpy().scl(2f).sub(Current)) // Get vector on other side of cloick
|
vectors.add(origin.cpy().scl(2f).sub(Current)) // Get vector on other side of clock
|
||||||
Current.add(0f, 1f)
|
Current.add(0f, 1f)
|
||||||
}
|
}
|
||||||
return vectors
|
return vectors
|
||||||
|
@ -24,13 +24,13 @@ class MapUnit {
|
|||||||
//region pure functions
|
//region pure functions
|
||||||
fun clone(): MapUnit {
|
fun clone(): MapUnit {
|
||||||
val toReturn = MapUnit()
|
val toReturn = MapUnit()
|
||||||
toReturn.action=action
|
|
||||||
toReturn.currentMovement=currentMovement
|
|
||||||
toReturn.name=name
|
|
||||||
toReturn.promotions=promotions.clone()
|
|
||||||
toReturn.health=health
|
|
||||||
toReturn.attacksThisTurn=attacksThisTurn
|
|
||||||
toReturn.owner=owner
|
toReturn.owner=owner
|
||||||
|
toReturn.name=name
|
||||||
|
toReturn.currentMovement=currentMovement
|
||||||
|
toReturn.health=health
|
||||||
|
toReturn.action=action
|
||||||
|
toReturn.attacksThisTurn=attacksThisTurn
|
||||||
|
toReturn.promotions=promotions.clone()
|
||||||
return toReturn
|
return toReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ open class TileInfo {
|
|||||||
|
|
||||||
var militaryUnit:MapUnit?=null
|
var militaryUnit:MapUnit?=null
|
||||||
var civilianUnit:MapUnit?=null
|
var civilianUnit:MapUnit?=null
|
||||||
fun getUnits()= listOf(militaryUnit,civilianUnit).filterNotNull()
|
|
||||||
|
|
||||||
var position: Vector2 = Vector2.Zero
|
var position: Vector2 = Vector2.Zero
|
||||||
lateinit var baseTerrain: String
|
lateinit var baseTerrain: String
|
||||||
@ -29,6 +28,25 @@ open class TileInfo {
|
|||||||
var roadStatus = RoadStatus.None
|
var roadStatus = RoadStatus.None
|
||||||
var turnsToImprovement: Int = 0
|
var turnsToImprovement: Int = 0
|
||||||
|
|
||||||
|
|
||||||
|
fun clone(): TileInfo {
|
||||||
|
val toReturn = TileInfo()
|
||||||
|
if(militaryUnit!=null) toReturn.militaryUnit=militaryUnit!!.clone()
|
||||||
|
if(civilianUnit!=null) toReturn.civilianUnit=civilianUnit!!.clone()
|
||||||
|
toReturn.position=position.cpy()
|
||||||
|
toReturn.baseTerrain=baseTerrain
|
||||||
|
toReturn.terrainFeature=terrainFeature
|
||||||
|
toReturn.resource=resource
|
||||||
|
toReturn.improvement=improvement
|
||||||
|
toReturn.improvementInProgress=improvementInProgress
|
||||||
|
toReturn.roadStatus=roadStatus
|
||||||
|
toReturn.turnsToImprovement=turnsToImprovement
|
||||||
|
return toReturn
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun getUnits()= listOf(militaryUnit,civilianUnit).filterNotNull()
|
||||||
|
|
||||||
fun getCity(): CityInfo? {
|
fun getCity(): CityInfo? {
|
||||||
return tileMap.gameInfo.tilesToCities.get(this)
|
return tileMap.gameInfo.tilesToCities.get(this)
|
||||||
//return tileMap.gameInfo.civilizations.flatMap { it.cities }.firstOrNull{it.tiles.contains(position)}
|
//return tileMap.gameInfo.civilizations.flatMap { it.cities }.firstOrNull{it.tiles.contains(position)}
|
||||||
@ -210,18 +228,4 @@ open class TileInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun arialDistanceTo(otherTile:TileInfo) = abs(position.x-otherTile.position.x) + abs(position.y-otherTile.position.y)
|
fun arialDistanceTo(otherTile:TileInfo) = abs(position.x-otherTile.position.x) + abs(position.y-otherTile.position.y)
|
||||||
fun clone(): TileInfo {
|
|
||||||
val toReturn = TileInfo()
|
|
||||||
if(civilianUnit!=null) toReturn.civilianUnit=civilianUnit!!.clone()
|
|
||||||
if(militaryUnit!=null) toReturn.militaryUnit=militaryUnit!!.clone()
|
|
||||||
toReturn.improvement=improvement
|
|
||||||
toReturn.position=position
|
|
||||||
toReturn.baseTerrain=baseTerrain
|
|
||||||
toReturn.terrainFeature=terrainFeature
|
|
||||||
toReturn.improvementInProgress=improvementInProgress
|
|
||||||
toReturn.resource=resource
|
|
||||||
toReturn.roadStatus=roadStatus
|
|
||||||
toReturn.turnsToImprovement=turnsToImprovement
|
|
||||||
return toReturn
|
|
||||||
}
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user