mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-13 17:28:57 +07:00
Cleaned up some code from the split (#5652)
This commit is contained in:
@ -129,7 +129,7 @@ class UncivGame(parameters: UncivGameParameters) : Game() {
|
|||||||
this.gameInfo = gameInfo
|
this.gameInfo = gameInfo
|
||||||
ImageGetter.setNewRuleset(gameInfo.ruleSet)
|
ImageGetter.setNewRuleset(gameInfo.ruleSet)
|
||||||
// Clone the mod list and add the base ruleset to it
|
// Clone the mod list and add the base ruleset to it
|
||||||
val fullModList = (gameInfo.gameParameters.mods.toHashSet()).apply { add(gameInfo.gameParameters.baseRuleset) }
|
val fullModList = gameInfo.gameParameters.getModsAndBaseRuleset()
|
||||||
musicController.setModList(fullModList)
|
musicController.setModList(fullModList)
|
||||||
Gdx.input.inputProcessor = null // Since we will set the world screen when we're ready,
|
Gdx.input.inputProcessor = null // Since we will set the world screen when we're ready,
|
||||||
if (gameInfo.civilizations.count { it.playerType == PlayerType.Human } > 1 && !gameInfo.gameParameters.isOnlineMultiplayer)
|
if (gameInfo.civilizations.count { it.playerType == PlayerType.Human } > 1 && !gameInfo.gameParameters.isOnlineMultiplayer)
|
||||||
|
@ -33,7 +33,7 @@ object GameStarter {
|
|||||||
// We need to remove the dead mods so there aren't problems later.
|
// We need to remove the dead mods so there aren't problems later.
|
||||||
gameSetupInfo.gameParameters.mods.removeAll { !RulesetCache.containsKey(it) }
|
gameSetupInfo.gameParameters.mods.removeAll { !RulesetCache.containsKey(it) }
|
||||||
|
|
||||||
// [Temporary] If we have a base ruleset in the mod list, we make that our base ruleset
|
// [TEMPORARY] If we have a base ruleset in the mod list, we make that our base ruleset
|
||||||
val baseRulesetInMods = gameSetupInfo.gameParameters.mods.firstOrNull { RulesetCache[it]!!.modOptions.isBaseRuleset }
|
val baseRulesetInMods = gameSetupInfo.gameParameters.mods.firstOrNull { RulesetCache[it]!!.modOptions.isBaseRuleset }
|
||||||
if (baseRulesetInMods != null)
|
if (baseRulesetInMods != null)
|
||||||
gameSetupInfo.gameParameters.baseRuleset = baseRulesetInMods
|
gameSetupInfo.gameParameters.baseRuleset = baseRulesetInMods
|
||||||
|
@ -73,4 +73,8 @@ class GameParameters { // Default values are the default new game
|
|||||||
yield(baseRuleset)
|
yield(baseRuleset)
|
||||||
yield(if (mods.isEmpty()) "no mods" else mods.joinToString(",", "mods=(", ")", 6) )
|
yield(if (mods.isEmpty()) "no mods" else mods.joinToString(",", "mods=(", ")", 6) )
|
||||||
}.joinToString(prefix = "(", postfix = ")")
|
}.joinToString(prefix = "(", postfix = ")")
|
||||||
|
|
||||||
|
fun getModsAndBaseRuleset(): HashSet<String> {
|
||||||
|
return mods.toHashSet().apply { add(baseRuleset) }
|
||||||
|
}
|
||||||
}
|
}
|
@ -269,7 +269,7 @@ class Ruleset {
|
|||||||
/** Used for displaying a RuleSet's name */
|
/** Used for displaying a RuleSet's name */
|
||||||
override fun toString() = when {
|
override fun toString() = when {
|
||||||
name.isNotEmpty() -> name
|
name.isNotEmpty() -> name
|
||||||
mods.isEmpty() -> BaseRuleset.Civ_V_Vanilla.fullName //todo differentiate once more than 1 BaseRuleset
|
mods.size == 1 && RulesetCache[mods.first()]!!.modOptions.isBaseRuleset -> mods.first()
|
||||||
else -> "Combined RuleSet"
|
else -> "Combined RuleSet"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,6 +634,27 @@ object RulesetCache : HashMap<String,Ruleset>() {
|
|||||||
|
|
||||||
fun getBaseRuleset() = this[BaseRuleset.Civ_V_Vanilla.fullName]!!.clone() // safeguard, so no-one edits the base ruleset by mistake
|
fun getBaseRuleset() = this[BaseRuleset.Civ_V_Vanilla.fullName]!!.clone() // safeguard, so no-one edits the base ruleset by mistake
|
||||||
|
|
||||||
|
fun getSortedBaseRulesets(): List<String> {
|
||||||
|
val baseRulesets = values
|
||||||
|
.filter { it.modOptions.isBaseRuleset }
|
||||||
|
.map { it.name }
|
||||||
|
.distinct()
|
||||||
|
if (baseRulesets.size < 2) return baseRulesets
|
||||||
|
|
||||||
|
// We sort the base rulesets such that the ones unciv provides are on the top,
|
||||||
|
// and the rest is alphabetically ordered.
|
||||||
|
return baseRulesets.sortedWith(
|
||||||
|
compareBy(
|
||||||
|
{ ruleset ->
|
||||||
|
BaseRuleset.values()
|
||||||
|
.firstOrNull { br -> br.fullName == ruleset }?.ordinal
|
||||||
|
?: BaseRuleset.values().size
|
||||||
|
},
|
||||||
|
{ it }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a combined [Ruleset] from a list of mods. If no baseRuleset is listed in [mods],
|
* Creates a combined [Ruleset] from a list of mods. If no baseRuleset is listed in [mods],
|
||||||
* then the vanilla Ruleset is included automatically.
|
* then the vanilla Ruleset is included automatically.
|
||||||
|
@ -41,8 +41,6 @@ class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorS
|
|||||||
val mods = mapParameters.mods
|
val mods = mapParameters.mods
|
||||||
val baseRuleset = mapParameters.baseRuleset
|
val baseRuleset = mapParameters.baseRuleset
|
||||||
|
|
||||||
// FIXME
|
|
||||||
|
|
||||||
checkboxTable = ModCheckboxTable(mods, baseRuleset, mapEditorScreen) {
|
checkboxTable = ModCheckboxTable(mods, baseRuleset, mapEditorScreen) {
|
||||||
ruleset.clear()
|
ruleset.clear()
|
||||||
val newRuleset = RulesetCache.getComplexRuleset(mods, baseRuleset)
|
val newRuleset = RulesetCache.getComplexRuleset(mods, baseRuleset)
|
||||||
@ -106,25 +104,8 @@ class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorS
|
|||||||
private fun getBaseRulesetSelectBox(): Table? {
|
private fun getBaseRulesetSelectBox(): Table? {
|
||||||
val rulesetSelectionBox = Table()
|
val rulesetSelectionBox = Table()
|
||||||
|
|
||||||
val baseRulesets =
|
val sortedBaseRulesets = RulesetCache.getSortedBaseRulesets()
|
||||||
RulesetCache.values
|
if (sortedBaseRulesets.size < 2) return null
|
||||||
.filter { it.modOptions.isBaseRuleset }
|
|
||||||
.map { it.name }
|
|
||||||
.distinct()
|
|
||||||
if (baseRulesets.size < 2) return null
|
|
||||||
|
|
||||||
// We sort the base rulesets such that the ones unciv provides are on the top,
|
|
||||||
// and the rest is alphabetically ordered.
|
|
||||||
val sortedBaseRulesets = baseRulesets.sortedWith(
|
|
||||||
compareBy(
|
|
||||||
{ ruleset ->
|
|
||||||
BaseRuleset.values()
|
|
||||||
.firstOrNull { br -> br.fullName == ruleset }?.ordinal
|
|
||||||
?: BaseRuleset.values().size
|
|
||||||
},
|
|
||||||
{ it }
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
rulesetSelectionBox.add("{Base Ruleset}:".toLabel()).left()
|
rulesetSelectionBox.add("{Base Ruleset}:".toLabel()).left()
|
||||||
val selectBox = TranslatedSelectBox(sortedBaseRulesets, mapParameters.baseRuleset, CameraStageBaseScreen.skin)
|
val selectBox = TranslatedSelectBox(sortedBaseRulesets, mapParameters.baseRuleset, CameraStageBaseScreen.skin)
|
||||||
|
@ -139,27 +139,10 @@ class NewMapScreen(val mapParameters: MapParameters = getDefaultParameters()) :
|
|||||||
|
|
||||||
private fun getBaseRulesetSelectBox(): Table? {
|
private fun getBaseRulesetSelectBox(): Table? {
|
||||||
val rulesetSelectionBox = Table()
|
val rulesetSelectionBox = Table()
|
||||||
|
|
||||||
val baseRulesets =
|
|
||||||
RulesetCache.values
|
|
||||||
.filter { it.modOptions.isBaseRuleset }
|
|
||||||
.map { it.name }
|
|
||||||
.distinct()
|
|
||||||
if (baseRulesets.size < 2) return null
|
|
||||||
|
|
||||||
// We sort the base rulesets such that the ones unciv provides are on the top,
|
val sortedBaseRulesets = RulesetCache.getSortedBaseRulesets()
|
||||||
// and the rest is alphabetically ordered.
|
if (sortedBaseRulesets.size < 2) return null
|
||||||
val sortedBaseRulesets = baseRulesets.sortedWith(
|
|
||||||
compareBy(
|
|
||||||
{ ruleset ->
|
|
||||||
BaseRuleset.values()
|
|
||||||
.firstOrNull { br -> br.fullName == ruleset }?.ordinal
|
|
||||||
?: BaseRuleset.values().size
|
|
||||||
},
|
|
||||||
{ it }
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
rulesetSelectionBox.add("{Base Ruleset}:".toLabel()).left()
|
rulesetSelectionBox.add("{Base Ruleset}:".toLabel()).left()
|
||||||
val selectBox = TranslatedSelectBox(sortedBaseRulesets, mapParameters.baseRuleset, skin)
|
val selectBox = TranslatedSelectBox(sortedBaseRulesets, mapParameters.baseRuleset, skin)
|
||||||
|
|
||||||
|
@ -141,25 +141,9 @@ class GameOptionsTable(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun Table.addBaseRulesetSelectBox() {
|
private fun Table.addBaseRulesetSelectBox() {
|
||||||
val baseRulesets =
|
val sortedBaseRulesets = RulesetCache.getSortedBaseRulesets()
|
||||||
RulesetCache.values
|
if (sortedBaseRulesets.size < 2) return
|
||||||
.filter { it.modOptions.isBaseRuleset }
|
|
||||||
.map { it.name }
|
|
||||||
.distinct()
|
|
||||||
if (baseRulesets.size < 2) return
|
|
||||||
|
|
||||||
// We sort the base rulesets such that the ones unciv provides are on the top,
|
|
||||||
// and the rest is alphabetically ordered.
|
|
||||||
val sortedBaseRulesets = baseRulesets.sortedWith(
|
|
||||||
compareBy(
|
|
||||||
{ ruleset ->
|
|
||||||
BaseRuleset.values()
|
|
||||||
.firstOrNull { br -> br.fullName == ruleset }?.ordinal
|
|
||||||
?: BaseRuleset.values().size
|
|
||||||
},
|
|
||||||
{ it }
|
|
||||||
)
|
|
||||||
)
|
|
||||||
addSelectBox(
|
addSelectBox(
|
||||||
"{Base Ruleset}:",
|
"{Base Ruleset}:",
|
||||||
sortedBaseRulesets,
|
sortedBaseRulesets,
|
||||||
@ -252,7 +236,7 @@ class GameOptionsTable(
|
|||||||
ruleset.modOptions = newRuleset.modOptions
|
ruleset.modOptions = newRuleset.modOptions
|
||||||
|
|
||||||
ImageGetter.setNewRuleset(ruleset)
|
ImageGetter.setNewRuleset(ruleset)
|
||||||
UncivGame.Current.musicController.setModList(gameParameters.mods.toHashSet().apply { add(gameParameters.baseRuleset) })
|
UncivGame.Current.musicController.setModList(gameParameters.getModsAndBaseRuleset())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getModCheckboxes(isPortrait: Boolean = false): ModCheckboxTable {
|
fun getModCheckboxes(isPortrait: Boolean = false): ModCheckboxTable {
|
||||||
@ -262,7 +246,7 @@ class GameOptionsTable(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onChooseMod(mod: String) {
|
private fun onChooseMod(mod: String) {
|
||||||
val activeMods: LinkedHashSet<String> = LinkedHashSet(gameParameters.mods + gameParameters.baseRuleset)
|
val activeMods: LinkedHashSet<String> = LinkedHashSet(gameParameters.getModsAndBaseRuleset())
|
||||||
UncivGame.Current.translations.translationActiveMods = activeMods
|
UncivGame.Current.translations.translationActiveMods = activeMods
|
||||||
reloadRuleset()
|
reloadRuleset()
|
||||||
update()
|
update()
|
||||||
|
@ -103,7 +103,7 @@ class MapOptionsTable(private val newGameScreen: NewGameScreen): Table() {
|
|||||||
mapParameters.name = mapFile.name()
|
mapParameters.name = mapFile.name()
|
||||||
newGameScreen.gameSetupInfo.mapFile = mapFile
|
newGameScreen.gameSetupInfo.mapFile = mapFile
|
||||||
newGameScreen.gameSetupInfo.gameParameters.mods = LinkedHashSet(map.mapParameters.mods.filter { RulesetCache[it]?.modOptions?.isBaseRuleset != true })
|
newGameScreen.gameSetupInfo.gameParameters.mods = LinkedHashSet(map.mapParameters.mods.filter { RulesetCache[it]?.modOptions?.isBaseRuleset != true })
|
||||||
newGameScreen.gameSetupInfo.gameParameters.baseRuleset = map.mapParameters.mods.firstOrNull { RulesetCache[it]?.modOptions?.isBaseRuleset == true } ?: RulesetCache.getBaseRuleset().name
|
newGameScreen.gameSetupInfo.gameParameters.baseRuleset = map.mapParameters.mods.firstOrNull { RulesetCache[it]?.modOptions?.isBaseRuleset == true } ?: map.mapParameters.baseRuleset
|
||||||
newGameScreen.updateRuleset()
|
newGameScreen.updateRuleset()
|
||||||
newGameScreen.updateTables()
|
newGameScreen.updateTables()
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ class NewGameScreen(
|
|||||||
ruleset.clear()
|
ruleset.clear()
|
||||||
ruleset.add(RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters.mods, gameSetupInfo.gameParameters.baseRuleset))
|
ruleset.add(RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters.mods, gameSetupInfo.gameParameters.baseRuleset))
|
||||||
ImageGetter.setNewRuleset(ruleset)
|
ImageGetter.setNewRuleset(ruleset)
|
||||||
game.musicController.setModList(gameSetupInfo.gameParameters.mods.toHashSet().apply { add(gameSetupInfo.gameParameters.baseRuleset) })
|
game.musicController.setModList(gameSetupInfo.gameParameters.getModsAndBaseRuleset())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun lockTables() {
|
fun lockTables() {
|
||||||
|
@ -62,7 +62,7 @@ interface CrashController {
|
|||||||
val zippedGameInfo = Json().toJson(gameInfo).let { Gzip.zip(it) }
|
val zippedGameInfo = Json().toJson(gameInfo).let { Gzip.zip(it) }
|
||||||
CrashReport(
|
CrashReport(
|
||||||
zippedGameInfo,
|
zippedGameInfo,
|
||||||
LinkedHashSet(listOf(*gameInfo.gameParameters.mods.toTypedArray(), gameInfo.gameParameters.baseRuleset)),
|
LinkedHashSet(gameInfo.gameParameters.getModsAndBaseRuleset()),
|
||||||
version
|
version
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user