mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-13 09:18:43 +07:00
Small steps towards mods
This commit is contained in:
@ -1,13 +1,16 @@
|
||||
[
|
||||
{
|
||||
name:"Warrior",
|
||||
name:"Maori Warrior",
|
||||
unitType:"Melee",
|
||||
uniqueTo:"Polynesia",
|
||||
replaces:"Warrior",
|
||||
movement:2,
|
||||
strength:12,
|
||||
strength:80,
|
||||
cost: 40,
|
||||
hurryCostModifier:20,
|
||||
obsoleteTech:"Metal Casting",
|
||||
promotions:["Haka War Dance"],
|
||||
upgradesTo:"Swordsman",
|
||||
attackSound:"nonmetalhit"
|
||||
}
|
||||
},
|
||||
]
|
@ -13,7 +13,8 @@ import com.unciv.models.stats.INamed
|
||||
import kotlin.collections.set
|
||||
|
||||
class Ruleset {
|
||||
val mods = ArrayList<String>()
|
||||
var name=""
|
||||
val mods = LinkedHashSet<String>()
|
||||
val buildings = LinkedHashMap<String, Building>()
|
||||
val terrains = LinkedHashMap<String, Terrain>()
|
||||
val tileResources = LinkedHashMap<String, TileResource>()
|
||||
@ -25,7 +26,20 @@ class Ruleset {
|
||||
val policyBranches = LinkedHashMap<String, PolicyBranch>()
|
||||
val difficulties = LinkedHashMap<String, Difficulty>()
|
||||
|
||||
fun clone(): Ruleset{
|
||||
val newRuleset = Ruleset(false)
|
||||
newRuleset.add(this)
|
||||
return newRuleset
|
||||
}
|
||||
|
||||
constructor(load:Boolean=true){
|
||||
if(load) load()
|
||||
}
|
||||
|
||||
|
||||
fun <T> getFromJson(tClass: Class<T>, filePath:String): T {
|
||||
val file = Gdx.files.internal(filePath)
|
||||
if(!file.exists()) return tClass Array<>().first()
|
||||
val jsonText = Gdx.files.internal(filePath).readString(Charsets.UTF_8.name())
|
||||
return Json().apply { ignoreUnknownFields = true }.fromJson(tClass, jsonText)
|
||||
}
|
||||
@ -37,24 +51,32 @@ class Ruleset {
|
||||
return hashMap
|
||||
}
|
||||
|
||||
fun clone(): Ruleset{
|
||||
val newRuleset = Ruleset(false)
|
||||
newRuleset.buildings.putAll(buildings)
|
||||
newRuleset.difficulties.putAll(difficulties)
|
||||
newRuleset.nations .putAll(nations)
|
||||
newRuleset.policyBranches.putAll(policyBranches)
|
||||
newRuleset.technologies.putAll(technologies)
|
||||
newRuleset.buildings.putAll(buildings)
|
||||
newRuleset.terrains.putAll(terrains)
|
||||
newRuleset.tileImprovements.putAll(tileImprovements)
|
||||
newRuleset.tileResources.putAll(tileResources)
|
||||
newRuleset.unitPromotions.putAll(unitPromotions)
|
||||
newRuleset.units.putAll(units)
|
||||
return newRuleset
|
||||
fun add(ruleset: Ruleset){
|
||||
buildings.putAll(ruleset.buildings)
|
||||
difficulties.putAll(ruleset.difficulties)
|
||||
nations .putAll(ruleset.nations)
|
||||
policyBranches.putAll(ruleset.policyBranches)
|
||||
technologies.putAll(ruleset.technologies)
|
||||
buildings.putAll(ruleset.buildings)
|
||||
terrains.putAll(ruleset.terrains)
|
||||
tileImprovements.putAll(ruleset.tileImprovements)
|
||||
tileResources.putAll(ruleset.tileResources)
|
||||
unitPromotions.putAll(ruleset.unitPromotions)
|
||||
units.putAll(ruleset.units)
|
||||
}
|
||||
|
||||
constructor(load:Boolean=true){
|
||||
if(load) load()
|
||||
fun clearExceptModNames(){
|
||||
buildings.clear()
|
||||
difficulties.clear()
|
||||
nations.clear()
|
||||
policyBranches.clear()
|
||||
technologies.clear()
|
||||
buildings.clear()
|
||||
terrains.clear()
|
||||
tileImprovements.clear()
|
||||
tileResources.clear()
|
||||
unitPromotions.clear()
|
||||
units.clear()
|
||||
}
|
||||
|
||||
fun load(folderPath: String="jsons") {
|
||||
|
@ -25,7 +25,7 @@ class NewGameScreen: PickerScreen(){
|
||||
|
||||
val newGameParameters= UncivGame.Current.gameInfo.gameParameters
|
||||
val mapParameters = UncivGame.Current.gameInfo.tileMap.mapParameters
|
||||
val ruleSet = UncivGame.Current.ruleset
|
||||
val ruleSet = UncivGame.Current.ruleset.clone()
|
||||
|
||||
init {
|
||||
setDefaultCloseAction()
|
||||
|
@ -16,10 +16,11 @@ import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.toLabel
|
||||
|
||||
class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val onMultiplayerToggled:()->Unit)
|
||||
class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val updatePlayerPickerTable:()->Unit)
|
||||
: Table(CameraStageBaseScreen.skin) {
|
||||
val newGameParameters = newGameScreen.newGameParameters
|
||||
val mapParameters = newGameScreen.mapParameters
|
||||
val baseRuleset = newGameScreen.ruleSet.clone()
|
||||
val ruleset = newGameScreen.ruleSet
|
||||
|
||||
init {
|
||||
@ -133,7 +134,7 @@ class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val onMultipla
|
||||
isOnlineMultiplayerCheckbox.addListener(object : ChangeListener() {
|
||||
override fun changed(event: ChangeEvent?, actor: Actor?) {
|
||||
newGameParameters.isOnlineMultiplayer = isOnlineMultiplayerCheckbox.isChecked
|
||||
onMultiplayerToggled()
|
||||
updatePlayerPickerTable()
|
||||
}
|
||||
})
|
||||
add(isOnlineMultiplayerCheckbox).colspan(2).row()
|
||||
@ -225,20 +226,44 @@ class NewGameScreenOptionsTable(val newGameScreen: NewGameScreen, val onMultipla
|
||||
|
||||
val modCheckboxTable = Table().apply { defaults().pad(10f) }
|
||||
|
||||
val mods = Gdx.files.local("mods")
|
||||
val modFolders = Gdx.files.local("mods")
|
||||
val loadableMods = ArrayList<Ruleset>()
|
||||
|
||||
for (modFolder in mods.list()) {
|
||||
for (modFolder in modFolders.list()) {
|
||||
if (modFolder.list().any { it.name() == "jsons" }) {
|
||||
val ruleSet = Ruleset(false)
|
||||
|
||||
try {
|
||||
val modRuleset = ruleSet.load(modFolder.path() + "/jsons")
|
||||
|
||||
ruleSet.load(modFolder.path() + "/jsons")
|
||||
ruleSet.name = modFolder.nameWithoutExtension()
|
||||
loadableMods.add(ruleset)
|
||||
} catch (ex: Exception) {
|
||||
print(ex.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun reloadMods(){
|
||||
ruleset.clearExceptModNames()
|
||||
ruleset.add(baseRuleset)
|
||||
for(modName in ruleset.mods){
|
||||
val correspondingMod = loadableMods.first { it.name==modName }
|
||||
ruleset.add(correspondingMod)
|
||||
}
|
||||
}
|
||||
|
||||
for(mod in loadableMods){
|
||||
val checkBox = CheckBox(mod.name,CameraStageBaseScreen.skin)
|
||||
checkBox.addListener(object : ChangeListener() {
|
||||
override fun changed(event: ChangeEvent?, actor: Actor?) {
|
||||
if(checkBox.isChecked) ruleset.mods.add(mod.name)
|
||||
else ruleset.mods.remove(mod.name)
|
||||
reloadMods()
|
||||
updatePlayerPickerTable()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
add(modCheckboxTable).colspan(2).row()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user