All GameBasics are now LinkedHashLists, and so retain order as in the json files

This commit is contained in:
Yair Morgenstern 2018-03-12 18:35:57 +02:00
parent f59102a2a0
commit b659e3b37d
2 changed files with 17 additions and 18 deletions

View file

@ -1,12 +1,12 @@
package com.unciv.models.gamebasics
object GameBasics {
@JvmField var Buildings: HashMap<String, Building> = HashMap()
@JvmField var Terrains: HashMap<String, Terrain> = HashMap()
@JvmField var TileResources: HashMap<String, TileResource> = HashMap()
@JvmField var TileImprovements: HashMap<String, TileImprovement> = HashMap()
@JvmField var Technologies: HashMap<String, Technology> = HashMap()
@JvmField var Helps: HashMap<String, BasicHelp> = HashMap()
@JvmField var Units: HashMap<String, Unit> = HashMap()
@JvmField var PolicyBranches: HashMap<String, PolicyBranch> = HashMap()
val Buildings = LinkedHashMap<String, Building>()
val Terrains = LinkedHashMap<String, Terrain>()
val TileResources = LinkedHashMap<String, TileResource>()
val TileImprovements = LinkedHashMap<String, TileImprovement>()
val Technologies = LinkedHashMap<String, Technology>()
val Helps = LinkedHashMap<String, BasicHelp>()
val Units = LinkedHashMap<String, Unit>()
val PolicyBranches = LinkedHashMap<String, PolicyBranch>()
}

View file

@ -56,24 +56,23 @@ class UnCivGame : Game() {
return Json().fromJson(tClass, jsonText)
}
private fun <T : INamed> createHashmap(items: Array<T>): HashMap<String, T> {
val hashMap = HashMap<String, T>()
private fun <T : INamed> createHashmap(items: Array<T>): LinkedHashMap<String, T> {
val hashMap = LinkedHashMap<String, T>()
for (item in items)
hashMap[item.name] = item
return hashMap
}
private fun setupGameBasics() {
GameBasics.Buildings = createHashmap(getFromJson(Array<Building>::class.java, "Buildings"))
GameBasics.Terrains = createHashmap(getFromJson(Array<Terrain>::class.java, "Terrains"))
GameBasics.TileResources = createHashmap(getFromJson(Array<TileResource>::class.java, "TileResources"))
GameBasics.TileImprovements = createHashmap(getFromJson(Array<TileImprovement>::class.java, "TileImprovements"))
GameBasics.Helps = createHashmap(getFromJson(Array<BasicHelp>::class.java, "BasicHelp"))
GameBasics.Units = createHashmap(getFromJson(Array<Unit>::class.java, "Units"))
GameBasics.PolicyBranches = createHashmap(getFromJson(Array<PolicyBranch>::class.java, "Policies"))
GameBasics.Buildings += createHashmap(getFromJson(Array<Building>::class.java, "Buildings"))
GameBasics.Terrains += createHashmap(getFromJson(Array<Terrain>::class.java, "Terrains"))
GameBasics.TileResources += createHashmap(getFromJson(Array<TileResource>::class.java, "TileResources"))
GameBasics.TileImprovements += createHashmap(getFromJson(Array<TileImprovement>::class.java, "TileImprovements"))
GameBasics.Helps += createHashmap(getFromJson(Array<BasicHelp>::class.java, "BasicHelp"))
GameBasics.Units += createHashmap(getFromJson(Array<Unit>::class.java, "Units"))
GameBasics.PolicyBranches += createHashmap(getFromJson(Array<PolicyBranch>::class.java, "Policies"))
val techColumns = getFromJson(Array<TechColumn>::class.java, "Techs")
GameBasics.Technologies = HashMap()
for (techColumn in techColumns) {
for (tech in techColumn.techs) {
tech.cost = techColumn.techCost