mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-25 12:54:06 -04:00
Started solution for #2381 - added "ModOptions" file which can currently define techs to remove
Mods correctly overrule base ruleset
This commit is contained in:
parent
935071e206
commit
546345c353
@ -14,7 +14,11 @@ import com.unciv.models.ruleset.unit.Promotion
|
|||||||
import com.unciv.models.stats.INamed
|
import com.unciv.models.stats.INamed
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
|
|
||||||
class Ruleset() {
|
class ModOptions {
|
||||||
|
var techsToRemove = HashSet<String>()
|
||||||
|
}
|
||||||
|
|
||||||
|
class Ruleset {
|
||||||
|
|
||||||
private val jsonParser = JsonParser()
|
private val jsonParser = JsonParser()
|
||||||
|
|
||||||
@ -30,6 +34,7 @@ class Ruleset() {
|
|||||||
val policyBranches = LinkedHashMap<String, PolicyBranch>()
|
val policyBranches = LinkedHashMap<String, PolicyBranch>()
|
||||||
val difficulties = LinkedHashMap<String, Difficulty>()
|
val difficulties = LinkedHashMap<String, Difficulty>()
|
||||||
val mods = LinkedHashSet<String>()
|
val mods = LinkedHashSet<String>()
|
||||||
|
var modOptions = ModOptions()
|
||||||
|
|
||||||
fun clone(): Ruleset {
|
fun clone(): Ruleset {
|
||||||
val newRuleset = Ruleset()
|
val newRuleset = Ruleset()
|
||||||
@ -46,6 +51,7 @@ class Ruleset() {
|
|||||||
|
|
||||||
fun add(ruleset: Ruleset) {
|
fun add(ruleset: Ruleset) {
|
||||||
buildings.putAll(ruleset.buildings)
|
buildings.putAll(ruleset.buildings)
|
||||||
|
for(techToRemove in ruleset.modOptions.techsToRemove) technologies.remove(techToRemove)
|
||||||
difficulties.putAll(ruleset.difficulties)
|
difficulties.putAll(ruleset.difficulties)
|
||||||
nations.putAll(ruleset.nations)
|
nations.putAll(ruleset.nations)
|
||||||
policyBranches.putAll(ruleset.policyBranches)
|
policyBranches.putAll(ruleset.policyBranches)
|
||||||
@ -73,9 +79,18 @@ class Ruleset() {
|
|||||||
mods.clear()
|
mods.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun load(folderHandle :FileHandle ) {
|
fun load(folderHandle :FileHandle ) {
|
||||||
val gameBasicsStartTime = System.currentTimeMillis()
|
val gameBasicsStartTime = System.currentTimeMillis()
|
||||||
|
|
||||||
|
val modOptionsFile = folderHandle.child("ModOptions.json")
|
||||||
|
if(modOptionsFile.exists()){
|
||||||
|
try {
|
||||||
|
modOptions = jsonParser.getFromJson(ModOptions::class.java, modOptionsFile)
|
||||||
|
}
|
||||||
|
catch (ex:Exception){}
|
||||||
|
}
|
||||||
|
|
||||||
val techFile =folderHandle.child("Techs.json")
|
val techFile =folderHandle.child("Techs.json")
|
||||||
if(techFile.exists()) {
|
if(techFile.exists()) {
|
||||||
val techColumns = jsonParser.getFromJson(Array<TechColumn>::class.java, techFile)
|
val techColumns = jsonParser.getFromJson(Array<TechColumn>::class.java, techFile)
|
||||||
@ -168,14 +183,14 @@ object RulesetCache :HashMap<String,Ruleset>() {
|
|||||||
|
|
||||||
fun getBaseRuleset() = this[""]!!
|
fun getBaseRuleset() = this[""]!!
|
||||||
|
|
||||||
fun getComplexRuleset(mods: Collection<String>): Ruleset {
|
fun getComplexRuleset(mods: LinkedHashSet<String>): Ruleset {
|
||||||
val newRuleset = Ruleset()
|
val newRuleset = Ruleset()
|
||||||
|
newRuleset.add(getBaseRuleset())
|
||||||
for (mod in mods)
|
for (mod in mods)
|
||||||
if (containsKey(mod)) {
|
if (containsKey(mod)) {
|
||||||
newRuleset.add(this[mod]!!)
|
newRuleset.add(this[mod]!!)
|
||||||
newRuleset.mods += mod
|
newRuleset.mods += mod
|
||||||
}
|
}
|
||||||
newRuleset.add(getBaseRuleset())
|
|
||||||
return newRuleset
|
return newRuleset
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user