mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-13 01:08:25 +07:00
Managed to load first mini mod, needs some work before this can work for users
(what happens if we started a game with mod A and then we want to start a game with only mod B?)
This commit is contained in:
@ -1,14 +1,17 @@
|
||||
package com.unciv
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import com.badlogic.gdx.utils.Json
|
||||
|
||||
class JsonParser {
|
||||
|
||||
private val json = Json().apply { ignoreUnknownFields = true }
|
||||
|
||||
fun <T> getFromJson(tClass: Class<T>, filePath: String): T {
|
||||
val jsonText = Gdx.files.internal(filePath).readString(Charsets.UTF_8.name())
|
||||
fun <T> getFromJson(tClass: Class<T>, filePath: String): T = getFromJson(tClass, Gdx.files.internal(filePath))
|
||||
|
||||
fun <T> getFromJson(tClass: Class<T>, file: FileHandle): T {
|
||||
val jsonText = file.readString(Charsets.UTF_8.name())
|
||||
return json.fromJson(tClass, jsonText)
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.unciv.models.ruleset
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import com.unciv.JsonParser
|
||||
import com.unciv.models.ruleset.tech.TechColumn
|
||||
import com.unciv.models.ruleset.tech.Technology
|
||||
@ -36,7 +38,7 @@ class Ruleset(load: Boolean = true) {
|
||||
|
||||
init {
|
||||
if (load) {
|
||||
load()
|
||||
load(Gdx.files.internal("jsons"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,9 +77,12 @@ class Ruleset(load: Boolean = true) {
|
||||
units.clear()
|
||||
}
|
||||
|
||||
fun load(folderPath: String = "jsons") {
|
||||
fun load(folderHandle :FileHandle ) {
|
||||
val gameBasicsStartTime = System.currentTimeMillis()
|
||||
val techColumns = jsonParser.getFromJson(Array<TechColumn>::class.java, "$folderPath/Techs.json")
|
||||
|
||||
val techFile =folderHandle.child("Techs.json")
|
||||
if(techFile.exists()) {
|
||||
val techColumns = jsonParser.getFromJson(Array<TechColumn>::class.java, techFile)
|
||||
for (techColumn in techColumns) {
|
||||
for (tech in techColumn.techs) {
|
||||
if (tech.cost == 0) tech.cost = techColumn.techCost
|
||||
@ -85,22 +90,37 @@ class Ruleset(load: Boolean = true) {
|
||||
technologies[tech.name] = tech
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildings += createHashmap(jsonParser.getFromJson(Array<Building>::class.java, "$folderPath/Buildings.json"))
|
||||
val buildingsFile = folderHandle.child("Buildings.json")
|
||||
if(buildingsFile.exists()) {
|
||||
buildings += createHashmap(jsonParser.getFromJson(Array<Building>::class.java, buildingsFile))
|
||||
for (building in buildings.values) {
|
||||
if (building.requiredTech == null) continue
|
||||
val column = technologies[building.requiredTech!!]!!.column
|
||||
if (building.cost == 0)
|
||||
building.cost = if (building.isWonder || building.isNationalWonder) column!!.wonderCost else column!!.buildingCost
|
||||
}
|
||||
}
|
||||
|
||||
terrains += createHashmap(jsonParser.getFromJson(Array<Terrain>::class.java, "$folderPath/Terrains.json"))
|
||||
tileResources += createHashmap(jsonParser.getFromJson(Array<TileResource>::class.java, "$folderPath/TileResources.json"))
|
||||
tileImprovements += createHashmap(jsonParser.getFromJson(Array<TileImprovement>::class.java, "$folderPath/TileImprovements.json"))
|
||||
units += createHashmap(jsonParser.getFromJson(Array<BaseUnit>::class.java, "$folderPath/Units.json"))
|
||||
unitPromotions += createHashmap(jsonParser.getFromJson(Array<Promotion>::class.java, "$folderPath/UnitPromotions.json"))
|
||||
val terrainsFile = folderHandle.child("Terrains.json")
|
||||
if(terrainsFile.exists()) terrains += createHashmap(jsonParser.getFromJson(Array<Terrain>::class.java, terrainsFile))
|
||||
|
||||
policyBranches += createHashmap(jsonParser.getFromJson(Array<PolicyBranch>::class.java, "$folderPath/Policies.json"))
|
||||
val resourcesFile = folderHandle.child("TileResources.json")
|
||||
if(resourcesFile.exists()) tileResources += createHashmap(jsonParser.getFromJson(Array<TileResource>::class.java, resourcesFile))
|
||||
|
||||
val improvementsFile = folderHandle.child("TileImprovements.json")
|
||||
if(improvementsFile.exists()) tileImprovements += createHashmap(jsonParser.getFromJson(Array<TileImprovement>::class.java, improvementsFile))
|
||||
|
||||
val unitsFile = folderHandle.child("Units.json")
|
||||
if(unitsFile.exists()) units += createHashmap(jsonParser.getFromJson(Array<BaseUnit>::class.java, unitsFile))
|
||||
|
||||
val promotionsFile = folderHandle.child("UnitPromotions.json")
|
||||
if(promotionsFile.exists()) unitPromotions += createHashmap(jsonParser.getFromJson(Array<Promotion>::class.java, promotionsFile))
|
||||
|
||||
val policiesFile = folderHandle.child("Policies.json")
|
||||
if(policiesFile.exists()) {
|
||||
policyBranches += createHashmap(jsonParser.getFromJson(Array<PolicyBranch>::class.java, policiesFile))
|
||||
for (branch in policyBranches.values) {
|
||||
branch.requires = ArrayList()
|
||||
branch.branch = branch
|
||||
@ -110,11 +130,16 @@ class Ruleset(load: Boolean = true) {
|
||||
}
|
||||
branch.policies.last().name = branch.name + " Complete"
|
||||
}
|
||||
}
|
||||
|
||||
nations += createHashmap(jsonParser.getFromJson(Array<Nation>::class.java, "$folderPath/Nations/Nations.json"))
|
||||
val nationsFile = folderHandle.child("Nations/Nations.json")
|
||||
if(nationsFile.exists()) {
|
||||
nations += createHashmap(jsonParser.getFromJson(Array<Nation>::class.java, nationsFile))
|
||||
for (nation in nations.values) nation.setTransients()
|
||||
}
|
||||
|
||||
difficulties += createHashmap(jsonParser.getFromJson(Array<Difficulty>::class.java, "$folderPath/Difficulties.json"))
|
||||
val difficultiesFile = folderHandle.child("Difficulties.json")
|
||||
if(difficultiesFile.exists()) difficulties += createHashmap(jsonParser.getFromJson(Array<Difficulty>::class.java, difficultiesFile))
|
||||
|
||||
val gameBasicsLoadTime = System.currentTimeMillis() - gameBasicsStartTime
|
||||
println("Loading game basics - " + gameBasicsLoadTime + "ms")
|
||||
|
@ -38,7 +38,7 @@ class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val updatePlay
|
||||
addOneCityChallengeCheckbox()
|
||||
addIsOnlineMultiplayerCheckbox()
|
||||
|
||||
// addModCheckboxes()
|
||||
addModCheckboxes()
|
||||
|
||||
pack()
|
||||
}
|
||||
@ -222,21 +222,18 @@ class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val updatePlay
|
||||
|
||||
fun addModCheckboxes() {
|
||||
|
||||
add("{Mods}:".tr()).colspan(2).row()
|
||||
|
||||
val modCheckboxTable = Table().apply { defaults().pad(10f) }
|
||||
|
||||
val modFolders = Gdx.files.local("mods")
|
||||
val loadableMods = ArrayList<Ruleset>()
|
||||
|
||||
for (modFolder in modFolders.list()) {
|
||||
if (modFolder.list().any { it.name() == "jsons" }) {
|
||||
val ruleSet = Ruleset(false)
|
||||
val modRuleset = Ruleset(false)
|
||||
|
||||
try {
|
||||
ruleSet.load(modFolder.path() + "/jsons")
|
||||
ruleSet.name = modFolder.nameWithoutExtension()
|
||||
loadableMods.add(ruleset)
|
||||
modRuleset.load(modFolder.child("jsons"))
|
||||
modRuleset.name = modFolder.nameWithoutExtension()
|
||||
loadableMods.add(modRuleset)
|
||||
|
||||
} catch (ex: Exception) {
|
||||
print(ex.message)
|
||||
}
|
||||
@ -252,6 +249,11 @@ class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val updatePlay
|
||||
}
|
||||
}
|
||||
|
||||
if(loadableMods.isEmpty()) return
|
||||
|
||||
|
||||
add("{Mods}:".tr()).colspan(2).row()
|
||||
val modCheckboxTable = Table().apply { defaults().pad(10f) }
|
||||
for(mod in loadableMods){
|
||||
val checkBox = CheckBox(mod.name,CameraStageBaseScreen.skin)
|
||||
checkBox.addListener(object : ChangeListener() {
|
||||
@ -262,21 +264,10 @@ class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val updatePlay
|
||||
updatePlayerPickerTable()
|
||||
}
|
||||
})
|
||||
modCheckboxTable.add(checkBox)
|
||||
}
|
||||
|
||||
add(modCheckboxTable).colspan(2).row()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
//class Mod(val name:String){
|
||||
// val ruleSet=Ruleset(false)
|
||||
//
|
||||
// fun tryLoadRuleset(){
|
||||
// val folderPath="mods/$name"
|
||||
// val jsonsFolderLocation = folderPath+"/jsons"
|
||||
// if(Gdx.files.local(jsonsFolderLocation).exists())
|
||||
//
|
||||
// }
|
||||
//}
|
@ -51,8 +51,8 @@ for(platform in PackrConfig.Platform.values()) {
|
||||
PackrConfig config = new PackrConfig()
|
||||
config.platform = platform
|
||||
|
||||
// For Travis
|
||||
if(true) { // change to false for local build
|
||||
def forTravis = true // change to false for local build
|
||||
if(forTravis) {
|
||||
if (platform == PackrConfig.Platform.Linux32 || platform == PackrConfig.Platform.Linux64)
|
||||
config.jdk = System.env.'JAVA_HOME'
|
||||
// take the jdk straight from the building linux computer
|
||||
|
Reference in New Issue
Block a user