mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-14 01:39:40 +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
|
package com.unciv
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
|
import com.badlogic.gdx.files.FileHandle
|
||||||
import com.badlogic.gdx.utils.Json
|
import com.badlogic.gdx.utils.Json
|
||||||
|
|
||||||
class JsonParser {
|
class JsonParser {
|
||||||
|
|
||||||
private val json = Json().apply { ignoreUnknownFields = true }
|
private val json = Json().apply { ignoreUnknownFields = true }
|
||||||
|
|
||||||
fun <T> getFromJson(tClass: Class<T>, filePath: String): T {
|
fun <T> getFromJson(tClass: Class<T>, filePath: String): T = getFromJson(tClass, Gdx.files.internal(filePath))
|
||||||
val jsonText = Gdx.files.internal(filePath).readString(Charsets.UTF_8.name())
|
|
||||||
|
fun <T> getFromJson(tClass: Class<T>, file: FileHandle): T {
|
||||||
|
val jsonText = file.readString(Charsets.UTF_8.name())
|
||||||
return json.fromJson(tClass, jsonText)
|
return json.fromJson(tClass, jsonText)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package com.unciv.models.ruleset
|
package com.unciv.models.ruleset
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx
|
||||||
|
import com.badlogic.gdx.files.FileHandle
|
||||||
import com.unciv.JsonParser
|
import com.unciv.JsonParser
|
||||||
import com.unciv.models.ruleset.tech.TechColumn
|
import com.unciv.models.ruleset.tech.TechColumn
|
||||||
import com.unciv.models.ruleset.tech.Technology
|
import com.unciv.models.ruleset.tech.Technology
|
||||||
@ -36,7 +38,7 @@ class Ruleset(load: Boolean = true) {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
if (load) {
|
if (load) {
|
||||||
load()
|
load(Gdx.files.internal("jsons"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,46 +77,69 @@ class Ruleset(load: Boolean = true) {
|
|||||||
units.clear()
|
units.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun load(folderPath: String = "jsons") {
|
fun load(folderHandle :FileHandle ) {
|
||||||
val gameBasicsStartTime = System.currentTimeMillis()
|
val gameBasicsStartTime = System.currentTimeMillis()
|
||||||
val techColumns = jsonParser.getFromJson(Array<TechColumn>::class.java, "$folderPath/Techs.json")
|
|
||||||
for (techColumn in techColumns) {
|
val techFile =folderHandle.child("Techs.json")
|
||||||
for (tech in techColumn.techs) {
|
if(techFile.exists()) {
|
||||||
if (tech.cost == 0) tech.cost = techColumn.techCost
|
val techColumns = jsonParser.getFromJson(Array<TechColumn>::class.java, techFile)
|
||||||
tech.column = techColumn
|
for (techColumn in techColumns) {
|
||||||
technologies[tech.name] = tech
|
for (tech in techColumn.techs) {
|
||||||
|
if (tech.cost == 0) tech.cost = techColumn.techCost
|
||||||
|
tech.column = techColumn
|
||||||
|
technologies[tech.name] = tech
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildings += createHashmap(jsonParser.getFromJson(Array<Building>::class.java, "$folderPath/Buildings.json"))
|
val buildingsFile = folderHandle.child("Buildings.json")
|
||||||
for (building in buildings.values) {
|
if(buildingsFile.exists()) {
|
||||||
if (building.requiredTech == null) continue
|
buildings += createHashmap(jsonParser.getFromJson(Array<Building>::class.java, buildingsFile))
|
||||||
val column = technologies[building.requiredTech!!]!!.column
|
for (building in buildings.values) {
|
||||||
if (building.cost == 0)
|
if (building.requiredTech == null) continue
|
||||||
building.cost = if (building.isWonder || building.isNationalWonder) column!!.wonderCost else column!!.buildingCost
|
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"))
|
|
||||||
|
|
||||||
policyBranches += createHashmap(jsonParser.getFromJson(Array<PolicyBranch>::class.java, "$folderPath/Policies.json"))
|
|
||||||
for (branch in policyBranches.values) {
|
|
||||||
branch.requires = ArrayList()
|
|
||||||
branch.branch = branch
|
|
||||||
for (policy in branch.policies) {
|
|
||||||
policy.branch = branch
|
|
||||||
if (policy.requires == null) policy.requires = arrayListOf(branch.name)
|
|
||||||
}
|
}
|
||||||
branch.policies.last().name = branch.name + " Complete"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nations += createHashmap(jsonParser.getFromJson(Array<Nation>::class.java, "$folderPath/Nations/Nations.json"))
|
val terrainsFile = folderHandle.child("Terrains.json")
|
||||||
for (nation in nations.values) nation.setTransients()
|
if(terrainsFile.exists()) terrains += createHashmap(jsonParser.getFromJson(Array<Terrain>::class.java, terrainsFile))
|
||||||
|
|
||||||
difficulties += createHashmap(jsonParser.getFromJson(Array<Difficulty>::class.java, "$folderPath/Difficulties.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
|
||||||
|
for (policy in branch.policies) {
|
||||||
|
policy.branch = branch
|
||||||
|
if (policy.requires == null) policy.requires = arrayListOf(branch.name)
|
||||||
|
}
|
||||||
|
branch.policies.last().name = branch.name + " Complete"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
val difficultiesFile = folderHandle.child("Difficulties.json")
|
||||||
|
if(difficultiesFile.exists()) difficulties += createHashmap(jsonParser.getFromJson(Array<Difficulty>::class.java, difficultiesFile))
|
||||||
|
|
||||||
val gameBasicsLoadTime = System.currentTimeMillis() - gameBasicsStartTime
|
val gameBasicsLoadTime = System.currentTimeMillis() - gameBasicsStartTime
|
||||||
println("Loading game basics - " + gameBasicsLoadTime + "ms")
|
println("Loading game basics - " + gameBasicsLoadTime + "ms")
|
||||||
|
@ -38,7 +38,7 @@ class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val updatePlay
|
|||||||
addOneCityChallengeCheckbox()
|
addOneCityChallengeCheckbox()
|
||||||
addIsOnlineMultiplayerCheckbox()
|
addIsOnlineMultiplayerCheckbox()
|
||||||
|
|
||||||
// addModCheckboxes()
|
addModCheckboxes()
|
||||||
|
|
||||||
pack()
|
pack()
|
||||||
}
|
}
|
||||||
@ -222,21 +222,18 @@ class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val updatePlay
|
|||||||
|
|
||||||
fun addModCheckboxes() {
|
fun addModCheckboxes() {
|
||||||
|
|
||||||
add("{Mods}:".tr()).colspan(2).row()
|
|
||||||
|
|
||||||
val modCheckboxTable = Table().apply { defaults().pad(10f) }
|
|
||||||
|
|
||||||
val modFolders = Gdx.files.local("mods")
|
val modFolders = Gdx.files.local("mods")
|
||||||
val loadableMods = ArrayList<Ruleset>()
|
val loadableMods = ArrayList<Ruleset>()
|
||||||
|
|
||||||
for (modFolder in modFolders.list()) {
|
for (modFolder in modFolders.list()) {
|
||||||
if (modFolder.list().any { it.name() == "jsons" }) {
|
if (modFolder.list().any { it.name() == "jsons" }) {
|
||||||
val ruleSet = Ruleset(false)
|
val modRuleset = Ruleset(false)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ruleSet.load(modFolder.path() + "/jsons")
|
modRuleset.load(modFolder.child("jsons"))
|
||||||
ruleSet.name = modFolder.nameWithoutExtension()
|
modRuleset.name = modFolder.nameWithoutExtension()
|
||||||
loadableMods.add(ruleset)
|
loadableMods.add(modRuleset)
|
||||||
|
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
print(ex.message)
|
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){
|
for(mod in loadableMods){
|
||||||
val checkBox = CheckBox(mod.name,CameraStageBaseScreen.skin)
|
val checkBox = CheckBox(mod.name,CameraStageBaseScreen.skin)
|
||||||
checkBox.addListener(object : ChangeListener() {
|
checkBox.addListener(object : ChangeListener() {
|
||||||
@ -262,21 +264,10 @@ class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val updatePlay
|
|||||||
updatePlayerPickerTable()
|
updatePlayerPickerTable()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
modCheckboxTable.add(checkBox)
|
||||||
}
|
}
|
||||||
|
|
||||||
add(modCheckboxTable).colspan(2).row()
|
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()
|
PackrConfig config = new PackrConfig()
|
||||||
config.platform = platform
|
config.platform = platform
|
||||||
|
|
||||||
// For Travis
|
def forTravis = true // change to false for local build
|
||||||
if(true) { // change to false for local build
|
if(forTravis) {
|
||||||
if (platform == PackrConfig.Platform.Linux32 || platform == PackrConfig.Platform.Linux64)
|
if (platform == PackrConfig.Platform.Linux32 || platform == PackrConfig.Platform.Linux64)
|
||||||
config.jdk = System.env.'JAVA_HOME'
|
config.jdk = System.env.'JAVA_HOME'
|
||||||
// take the jdk straight from the building linux computer
|
// take the jdk straight from the building linux computer
|
||||||
|
Reference in New Issue
Block a user