mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-31 15:19:29 +07:00
Vanilla and G&K rulesets now coexist - this is a big step towards multiple base rulesets!
This commit is contained in:
@ -231,7 +231,7 @@ class GameInfo {
|
||||
// will be done here, and not in CivInfo.setTransients or CityInfo
|
||||
fun setTransients() {
|
||||
tileMap.gameInfo = this
|
||||
ruleSet = RulesetCache.getComplexRuleset(gameParameters.mods)
|
||||
ruleSet = RulesetCache.getComplexRuleset(gameParameters)
|
||||
// any mod the saved game lists that is currently not installed causes null pointer
|
||||
// exceptions in this routine unless it contained no new objects or was very simple.
|
||||
// Player's fault, so better complain early:
|
||||
|
@ -19,7 +19,7 @@ object GameStarter {
|
||||
val gameInfo = GameInfo()
|
||||
|
||||
gameInfo.gameParameters = gameSetupInfo.gameParameters
|
||||
val ruleset = RulesetCache.getComplexRuleset(gameInfo.gameParameters.mods)
|
||||
val ruleset = RulesetCache.getComplexRuleset(gameInfo.gameParameters)
|
||||
|
||||
if (gameSetupInfo.mapParameters.type == MapType.scenario)
|
||||
gameInfo.tileMap = MapSaver.loadScenario(gameSetupInfo.mapParameters.name).tileMap
|
||||
|
@ -4,6 +4,11 @@ import com.unciv.Constants
|
||||
import com.unciv.logic.civilization.PlayerType
|
||||
import com.unciv.models.ruleset.VictoryType
|
||||
|
||||
enum class BaseRuleset(val fullName:String){
|
||||
Civ_V_Vanilla("Civ V - Vanilla"),
|
||||
Civ_V_GaK("Civ V - G&K"),
|
||||
}
|
||||
|
||||
class GameParameters { // Default values are the default new game
|
||||
var difficulty = "Prince"
|
||||
var gameSpeed = GameSpeed.Standard
|
||||
@ -21,6 +26,7 @@ class GameParameters { // Default values are the default new game
|
||||
var startingEra = Constants.ancientEra
|
||||
|
||||
var isOnlineMultiplayer = false
|
||||
var baseRuleset: BaseRuleset = BaseRuleset.Civ_V_Vanilla
|
||||
var mods = LinkedHashSet<String>()
|
||||
|
||||
fun clone(): GameParameters {
|
||||
|
@ -5,7 +5,10 @@ import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import com.unciv.Constants
|
||||
import com.unciv.JsonParser
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.UncivShowableException
|
||||
import com.unciv.models.metadata.BaseRuleset
|
||||
import com.unciv.models.metadata.GameParameters
|
||||
import com.unciv.models.ruleset.tech.TechColumn
|
||||
import com.unciv.models.ruleset.tech.Technology
|
||||
import com.unciv.models.ruleset.tile.Terrain
|
||||
@ -180,12 +183,12 @@ class Ruleset {
|
||||
* save all of the loaded rulesets somewhere for later use
|
||||
* */
|
||||
object RulesetCache :HashMap<String,Ruleset>() {
|
||||
val vanillaRuleset = "Civ V - Vanilla"
|
||||
fun loadRulesets() {
|
||||
try {
|
||||
this[""] = Ruleset().apply { load(Gdx.files.internal("jsons/$vanillaRuleset")) }
|
||||
} catch (e: NullPointerException) {
|
||||
this[""] = Ruleset().apply { load(FileHandle("jsons/$vanillaRuleset")) }
|
||||
for(ruleset in BaseRuleset.values()){
|
||||
val fileName = "jsons/${ruleset.fullName}"
|
||||
val fileHandle = if(UncivGame.Current.consoleMode) FileHandle(fileName)
|
||||
else Gdx.files.internal(fileName)
|
||||
this[ruleset.fullName] = Ruleset().apply { load(fileHandle) }
|
||||
}
|
||||
|
||||
var modsHandles: Array<FileHandle>
|
||||
@ -211,13 +214,13 @@ object RulesetCache :HashMap<String,Ruleset>() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getBaseRuleset() = this[""]!!
|
||||
fun getBaseRuleset() = this[BaseRuleset.Civ_V_Vanilla.fullName]!!
|
||||
|
||||
fun getComplexRuleset(mods: LinkedHashSet<String>): Ruleset {
|
||||
fun getComplexRuleset(gameParameters: GameParameters): Ruleset {
|
||||
val newRuleset = Ruleset()
|
||||
val loadedMods = mods.filter { containsKey(it) }.map { this[it]!! }
|
||||
val loadedMods = gameParameters.mods.filter { containsKey(it) }.map { this[it]!! }
|
||||
if (loadedMods.none { it.modOptions.isBaseRuleset })
|
||||
newRuleset.add(getBaseRuleset())
|
||||
newRuleset.add(this[gameParameters.baseRuleset.fullName]!!)
|
||||
for (mod in loadedMods.sortedByDescending { it.modOptions.isBaseRuleset }) {
|
||||
newRuleset.add(mod)
|
||||
newRuleset.mods += mod.name
|
||||
|
@ -152,7 +152,7 @@ class GameOptionsTable(previousScreen: IPreviousScreen, val updatePlayerPickerTa
|
||||
|
||||
fun reloadMods() {
|
||||
ruleset.clear()
|
||||
val newRuleset = RulesetCache.getComplexRuleset(gameParameters.mods)
|
||||
val newRuleset = RulesetCache.getComplexRuleset(gameParameters)
|
||||
ruleset.add(newRuleset)
|
||||
ruleset.mods += gameParameters.mods
|
||||
ruleset.modOptions = newRuleset.modOptions
|
||||
|
@ -29,7 +29,7 @@ class GameSetupInfo(var gameId:String, var gameParameters: GameParameters, var m
|
||||
|
||||
class NewGameScreen(previousScreen:CameraStageBaseScreen, _gameSetupInfo: GameSetupInfo?=null): IPreviousScreen, PickerScreen() {
|
||||
override val gameSetupInfo = _gameSetupInfo ?: GameSetupInfo()
|
||||
override val ruleset = RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters.mods)
|
||||
override val ruleset = RulesetCache.getComplexRuleset(gameSetupInfo.gameParameters)
|
||||
var playerPickerTable = PlayerPickerTable(this, gameSetupInfo.gameParameters)
|
||||
var newGameOptionsTable = GameOptionsTable(this) { desiredCiv: String -> playerPickerTable.update(desiredCiv) }
|
||||
var mapOptionsTable = MapOptionsTable(this)
|
||||
|
Reference in New Issue
Block a user