mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Add mod folder to mod info when initializing mods so we don't have files pretending to be mods everywhere we try and find mod folders
This commit is contained in:
parent
89958e27ff
commit
6925fc6909
@ -66,6 +66,7 @@ class ModOptions : IHasUniques {
|
|||||||
class Ruleset {
|
class Ruleset {
|
||||||
|
|
||||||
private val jsonParser = JsonParser()
|
private val jsonParser = JsonParser()
|
||||||
|
var folderLocation:FileHandle?=null
|
||||||
|
|
||||||
var name = ""
|
var name = ""
|
||||||
val beliefs = LinkedHashMap<String, Belief>()
|
val beliefs = LinkedHashMap<String, Belief>()
|
||||||
@ -754,6 +755,7 @@ object RulesetCache : HashMap<String,Ruleset>() {
|
|||||||
val modRuleset = Ruleset()
|
val modRuleset = Ruleset()
|
||||||
modRuleset.load(modFolder.child("jsons"), printOutput)
|
modRuleset.load(modFolder.child("jsons"), printOutput)
|
||||||
modRuleset.name = modFolder.name()
|
modRuleset.name = modFolder.name()
|
||||||
|
modRuleset.folderLocation = modFolder
|
||||||
this[modRuleset.name] = modRuleset
|
this[modRuleset.name] = modRuleset
|
||||||
if (printOutput) {
|
if (printOutput) {
|
||||||
println("Mod loaded successfully: " + modRuleset.name)
|
println("Mod loaded successfully: " + modRuleset.name)
|
||||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx
|
|||||||
import com.badlogic.gdx.files.FileHandle
|
import com.badlogic.gdx.files.FileHandle
|
||||||
import com.unciv.JsonParser
|
import com.unciv.JsonParser
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
|
import com.unciv.models.ruleset.RulesetCache
|
||||||
import com.unciv.ui.utils.ImageGetter
|
import com.unciv.ui.utils.ImageGetter
|
||||||
|
|
||||||
object TileSetCache : HashMap<String, TileSetConfig>() {
|
object TileSetCache : HashMap<String, TileSetConfig>() {
|
||||||
@ -64,8 +65,8 @@ object TileSetCache : HashMap<String, TileSetConfig>() {
|
|||||||
|
|
||||||
//load mod TileSets
|
//load mod TileSets
|
||||||
val modsHandles =
|
val modsHandles =
|
||||||
if (consoleMode) FileHandle("mods").list()
|
if (consoleMode) FileHandle("mods").list().toList()
|
||||||
else Gdx.files.local("mods").list()
|
else RulesetCache.values.mapNotNull { it.folderLocation }
|
||||||
|
|
||||||
for (modFolder in modsHandles) {
|
for (modFolder in modsHandles) {
|
||||||
val modName = modFolder.name()
|
val modName = modFolder.name()
|
||||||
|
@ -2,6 +2,7 @@ package com.unciv.models.translations
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
|
import com.unciv.models.ruleset.RulesetCache
|
||||||
import com.unciv.models.ruleset.unique.Unique
|
import com.unciv.models.ruleset.unique.Unique
|
||||||
import com.unciv.models.stats.Stat
|
import com.unciv.models.stats.Stat
|
||||||
import com.unciv.models.stats.Stats
|
import com.unciv.models.stats.Stats
|
||||||
@ -93,7 +94,7 @@ class Translations : LinkedHashMap<String, TranslationEntry>(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// try to load the translations from the mods
|
// try to load the translations from the mods
|
||||||
for (modFolder in Gdx.files.local("mods").list()) {
|
for (modFolder in RulesetCache.values.mapNotNull { it.folderLocation }) {
|
||||||
val modTranslationFile = modFolder.child(translationFileName)
|
val modTranslationFile = modFolder.child(translationFileName)
|
||||||
if (modTranslationFile.exists()) {
|
if (modTranslationFile.exists()) {
|
||||||
var translationsForMod = modsWithTranslations[modFolder.name()]
|
var translationsForMod = modsWithTranslations[modFolder.name()]
|
||||||
|
@ -26,8 +26,8 @@ class MapOptionsTable(private val newGameScreen: NewGameScreen): Table() {
|
|||||||
|
|
||||||
private val mapFilesSequence = sequence<FileHandleWrapper> {
|
private val mapFilesSequence = sequence<FileHandleWrapper> {
|
||||||
yieldAll(MapSaver.getMaps().asSequence().map { FileHandleWrapper(it) })
|
yieldAll(MapSaver.getMaps().asSequence().map { FileHandleWrapper(it) })
|
||||||
for (mod in Gdx.files.local("mods").list()) {
|
for (modFolder in RulesetCache.values.mapNotNull { it.folderLocation }) {
|
||||||
val mapsFolder = mod.child("maps")
|
val mapsFolder = modFolder.child("maps")
|
||||||
if (mapsFolder.exists())
|
if (mapsFolder.exists())
|
||||||
yieldAll(mapsFolder.list().asSequence().map { FileHandleWrapper(it) })
|
yieldAll(mapsFolder.list().asSequence().map { FileHandleWrapper(it) })
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ class ModManagementScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (installedMod.modOptions.author.isEmpty()) {
|
if (installedMod.modOptions.author.isEmpty()) {
|
||||||
rewriteModOptions(repo, Gdx.files.local("mods").child(repo.name))
|
rewriteModOptions(repo, installedMod.folderLocation!!)
|
||||||
installedMod.modOptions.author = repo.owner.login
|
installedMod.modOptions.author = repo.owner.login
|
||||||
installedMod.modOptions.modSize = repo.size
|
installedMod.modOptions.modSize = repo.size
|
||||||
}
|
}
|
||||||
@ -520,7 +520,8 @@ class ModManagementScreen(
|
|||||||
syncInstalledSelected(mod.name, mod.button)
|
syncInstalledSelected(mod.name, mod.button)
|
||||||
refreshInstalledModActions(mod.ruleset!!)
|
refreshInstalledModActions(mod.ruleset!!)
|
||||||
rightSideButton.setText("Delete [${mod.name}]".tr())
|
rightSideButton.setText("Delete [${mod.name}]".tr())
|
||||||
rightSideButton.isEnabled = true
|
// Don't let the player think he can delete Vanilla and G&K rulesets
|
||||||
|
rightSideButton.isEnabled = mod.ruleset.folderLocation!=null
|
||||||
showModDescription(mod.name)
|
showModDescription(mod.name)
|
||||||
removeRightSideClickListeners()
|
removeRightSideClickListeners()
|
||||||
rightSideButton.onClick {
|
rightSideButton.onClick {
|
||||||
@ -528,7 +529,7 @@ class ModManagementScreen(
|
|||||||
YesNoPopup(
|
YesNoPopup(
|
||||||
question = "Are you SURE you want to delete this mod?",
|
question = "Are you SURE you want to delete this mod?",
|
||||||
action = {
|
action = {
|
||||||
deleteMod(mod.name)
|
deleteMod(mod.ruleset)
|
||||||
modActionTable.clear()
|
modActionTable.clear()
|
||||||
rightSideButton.setText("[${mod.name}] was deleted.".tr())
|
rightSideButton.setText("[${mod.name}] was deleted.".tr())
|
||||||
},
|
},
|
||||||
@ -539,12 +540,10 @@ class ModManagementScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Delete a Mod, refresh ruleset cache and update installed mod table */
|
/** Delete a Mod, refresh ruleset cache and update installed mod table */
|
||||||
private fun deleteMod(modName: String) {
|
private fun deleteMod(mod: Ruleset) {
|
||||||
val modFileHandle = Gdx.files.local("mods").child(modName)
|
mod.folderLocation!!.deleteDirectory()
|
||||||
if (modFileHandle.isDirectory) modFileHandle.deleteDirectory()
|
|
||||||
else modFileHandle.delete() // This should never happen
|
|
||||||
RulesetCache.loadRulesets()
|
RulesetCache.loadRulesets()
|
||||||
installedModInfo.remove(modName)
|
installedModInfo.remove(mod.name)
|
||||||
refreshInstalledModTable()
|
refreshInstalledModTable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user