mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-22 02:07:43 +07:00
Cleaned up some code from the split (#5652)
This commit is contained in:
parent
5cf5e13ffb
commit
2854d88e11
@ -129,7 +129,7 @@ class UncivGame(parameters: UncivGameParameters) : Game() {
|
||||
this.gameInfo = gameInfo
|
||||
ImageGetter.setNewRuleset(gameInfo.ruleSet)
|
||||
// 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)
|
||||
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)
|
||||
|
@ -33,7 +33,7 @@ object GameStarter {
|
||||
// We need to remove the dead mods so there aren't problems later.
|
||||
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 }
|
||||
if (baseRulesetInMods != null)
|
||||
gameSetupInfo.gameParameters.baseRuleset = baseRulesetInMods
|
||||
|
@ -73,4 +73,8 @@ class GameParameters { // Default values are the default new game
|
||||
yield(baseRuleset)
|
||||
yield(if (mods.isEmpty()) "no mods" else mods.joinToString(",", "mods=(", ")", 6) )
|
||||
}.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 */
|
||||
override fun toString() = when {
|
||||
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"
|
||||
}
|
||||
|
||||
@ -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 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],
|
||||
* then the vanilla Ruleset is included automatically.
|
||||
|
@ -41,8 +41,6 @@ class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorS
|
||||
val mods = mapParameters.mods
|
||||
val baseRuleset = mapParameters.baseRuleset
|
||||
|
||||
// FIXME
|
||||
|
||||
checkboxTable = ModCheckboxTable(mods, baseRuleset, mapEditorScreen) {
|
||||
ruleset.clear()
|
||||
val newRuleset = RulesetCache.getComplexRuleset(mods, baseRuleset)
|
||||
@ -106,25 +104,8 @@ class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorS
|
||||
private fun getBaseRulesetSelectBox(): 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,
|
||||
// and the rest is alphabetically ordered.
|
||||
val sortedBaseRulesets = baseRulesets.sortedWith(
|
||||
compareBy(
|
||||
{ ruleset ->
|
||||
BaseRuleset.values()
|
||||
.firstOrNull { br -> br.fullName == ruleset }?.ordinal
|
||||
?: BaseRuleset.values().size
|
||||
},
|
||||
{ it }
|
||||
)
|
||||
)
|
||||
val sortedBaseRulesets = RulesetCache.getSortedBaseRulesets()
|
||||
if (sortedBaseRulesets.size < 2) return null
|
||||
|
||||
rulesetSelectionBox.add("{Base Ruleset}:".toLabel()).left()
|
||||
val selectBox = TranslatedSelectBox(sortedBaseRulesets, mapParameters.baseRuleset, CameraStageBaseScreen.skin)
|
||||
|
@ -139,27 +139,10 @@ class NewMapScreen(val mapParameters: MapParameters = getDefaultParameters()) :
|
||||
|
||||
private fun getBaseRulesetSelectBox(): 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,
|
||||
// and the rest is alphabetically ordered.
|
||||
val sortedBaseRulesets = baseRulesets.sortedWith(
|
||||
compareBy(
|
||||
{ ruleset ->
|
||||
BaseRuleset.values()
|
||||
.firstOrNull { br -> br.fullName == ruleset }?.ordinal
|
||||
?: BaseRuleset.values().size
|
||||
},
|
||||
{ it }
|
||||
)
|
||||
)
|
||||
|
||||
val sortedBaseRulesets = RulesetCache.getSortedBaseRulesets()
|
||||
if (sortedBaseRulesets.size < 2) return null
|
||||
|
||||
rulesetSelectionBox.add("{Base Ruleset}:".toLabel()).left()
|
||||
val selectBox = TranslatedSelectBox(sortedBaseRulesets, mapParameters.baseRuleset, skin)
|
||||
|
||||
|
@ -141,25 +141,9 @@ class GameOptionsTable(
|
||||
}
|
||||
|
||||
private fun Table.addBaseRulesetSelectBox() {
|
||||
val baseRulesets =
|
||||
RulesetCache.values
|
||||
.filter { it.modOptions.isBaseRuleset }
|
||||
.map { it.name }
|
||||
.distinct()
|
||||
if (baseRulesets.size < 2) return
|
||||
val sortedBaseRulesets = RulesetCache.getSortedBaseRulesets()
|
||||
if (sortedBaseRulesets.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(
|
||||
"{Base Ruleset}:",
|
||||
sortedBaseRulesets,
|
||||
@ -252,7 +236,7 @@ class GameOptionsTable(
|
||||
ruleset.modOptions = newRuleset.modOptions
|
||||
|
||||
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 {
|
||||
@ -262,7 +246,7 @@ class GameOptionsTable(
|
||||
}
|
||||
|
||||
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
|
||||
reloadRuleset()
|
||||
update()
|
||||
|
@ -103,7 +103,7 @@ class MapOptionsTable(private val newGameScreen: NewGameScreen): Table() {
|
||||
mapParameters.name = mapFile.name()
|
||||
newGameScreen.gameSetupInfo.mapFile = mapFile
|
||||
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.updateTables()
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ class NewGameScreen(
|
||||
ruleset.clear()
|
||||
ruleset.add(RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters.mods, gameSetupInfo.gameParameters.baseRuleset))
|
||||
ImageGetter.setNewRuleset(ruleset)
|
||||
game.musicController.setModList(gameSetupInfo.gameParameters.mods.toHashSet().apply { add(gameSetupInfo.gameParameters.baseRuleset) })
|
||||
game.musicController.setModList(gameSetupInfo.gameParameters.getModsAndBaseRuleset())
|
||||
}
|
||||
|
||||
fun lockTables() {
|
||||
|
@ -62,7 +62,7 @@ interface CrashController {
|
||||
val zippedGameInfo = Json().toJson(gameInfo).let { Gzip.zip(it) }
|
||||
CrashReport(
|
||||
zippedGameInfo,
|
||||
LinkedHashSet(listOf(*gameInfo.gameParameters.mods.toTypedArray(), gameInfo.gameParameters.baseRuleset)),
|
||||
LinkedHashSet(gameInfo.gameParameters.getModsAndBaseRuleset()),
|
||||
version
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user