mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-16 18:59:15 +07:00
Code cleanup
This commit is contained in:
@ -16,7 +16,7 @@ import kotlin.random.Random
|
||||
|
||||
|
||||
class MapGenerator(val ruleset: Ruleset) {
|
||||
var randomness = MapGenerationRandomness()
|
||||
private var randomness = MapGenerationRandomness()
|
||||
|
||||
fun generateMap(mapParameters: MapParameters, seed: Long = System.currentTimeMillis()): TileMap {
|
||||
val mapRadius = mapParameters.size.radius
|
||||
@ -185,9 +185,11 @@ class MapGenerator(val ruleset: Ruleset) {
|
||||
var elevation = randomness.getPerlinNoise(tile, elevationSeed, scale = 2.0)
|
||||
elevation = abs(elevation).pow(1.0 - tileMap.mapParameters.elevationExponent.toDouble()) * elevation.sign
|
||||
|
||||
if (elevation <= 0.5) tile.baseTerrain = Constants.plains
|
||||
else if (elevation <= 0.7) tile.baseTerrain = Constants.hill
|
||||
else if (elevation <= 1.0) tile.baseTerrain = Constants.mountain
|
||||
when {
|
||||
elevation <= 0.5 -> tile.baseTerrain = Constants.plains
|
||||
elevation <= 0.7 -> tile.baseTerrain = Constants.hill
|
||||
elevation <= 1.0 -> tile.baseTerrain = Constants.mountain
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -342,10 +344,11 @@ class MapGenerationRandomness{
|
||||
}
|
||||
|
||||
|
||||
class RiverCoordinate(val position: Vector2, val bottomRightOrLeft: BottomRightOrLeft){
|
||||
enum class BottomRightOrLeft{
|
||||
class RiverCoordinate(val position: Vector2, val bottomRightOrLeft: BottomRightOrLeft) {
|
||||
enum class BottomRightOrLeft {
|
||||
/** 7 O'Clock of the tile */
|
||||
BottomLeft,
|
||||
|
||||
/** 5 O'Clock of the tile */
|
||||
BottomRight
|
||||
}
|
||||
@ -365,5 +368,4 @@ class RiverCoordinate(val position: Vector2, val bottomRightOrLeft: BottomRightO
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -13,7 +13,7 @@ import kotlin.math.pow
|
||||
class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
|
||||
fun generateLand(tileMap: TileMap, ruleset: Ruleset) {
|
||||
if(ruleset.terrains.values.none { it.type== TerrainType.Water }) {
|
||||
if (ruleset.terrains.values.none { it.type == TerrainType.Water }) {
|
||||
for (tile in tileMap.values)
|
||||
tile.baseTerrain = Constants.grassland
|
||||
return
|
||||
@ -50,7 +50,7 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
private fun createPerlin(tileMap: TileMap) {
|
||||
val elevationSeed = randomness.RNG.nextInt().toDouble()
|
||||
for (tile in tileMap.values) {
|
||||
var elevation = randomness.getPerlinNoise(tile, elevationSeed)
|
||||
val elevation = randomness.getPerlinNoise(tile, elevationSeed)
|
||||
spawnLandOrWater(tile, elevation, tileMap.mapParameters.waterThreshold.toDouble())
|
||||
}
|
||||
}
|
||||
@ -58,7 +58,7 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
private fun createArchipelago(tileMap: TileMap) {
|
||||
val elevationSeed = randomness.RNG.nextInt().toDouble()
|
||||
for (tile in tileMap.values) {
|
||||
var elevation = getRidgedPerlinNoise(tile, elevationSeed)
|
||||
val elevation = getRidgedPerlinNoise(tile, elevationSeed)
|
||||
spawnLandOrWater(tile, elevation, 0.25 + tileMap.mapParameters.waterThreshold.toDouble())
|
||||
}
|
||||
}
|
||||
@ -67,7 +67,7 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
val elevationSeed = randomness.RNG.nextInt().toDouble()
|
||||
for (tile in tileMap.values) {
|
||||
var elevation = randomness.getPerlinNoise(tile, elevationSeed)
|
||||
elevation = (elevation + getCircularNoise(tile, tileMap) ) / 2.0
|
||||
elevation = (elevation + getCircularNoise(tile, tileMap)) / 2.0
|
||||
spawnLandOrWater(tile, elevation, tileMap.mapParameters.waterThreshold.toDouble())
|
||||
}
|
||||
}
|
||||
@ -83,7 +83,7 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
|
||||
private fun getCircularNoise(tileInfo: TileInfo, tileMap: TileMap): Double {
|
||||
val randomScale = randomness.RNG.nextDouble()
|
||||
val distanceFactor = percentualDistanceToCenter(tileInfo, tileMap)
|
||||
val distanceFactor = percentualDistanceToCenter(tileInfo, tileMap)
|
||||
|
||||
return min(0.3, 1.0 - (5.0 * distanceFactor * distanceFactor + randomScale) / 3.0)
|
||||
}
|
||||
@ -98,7 +98,7 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
private fun percentualDistanceToCenter(tileInfo: TileInfo, tileMap: TileMap): Double {
|
||||
val mapRadius = tileMap.mapParameters.size.radius
|
||||
if (tileMap.mapParameters.shape == MapShape.hexagonal)
|
||||
return HexMath.getDistance(Vector2.Zero, tileInfo.position).toDouble()/mapRadius
|
||||
return HexMath.getDistance(Vector2.Zero, tileInfo.position).toDouble() / mapRadius
|
||||
else {
|
||||
val size = HexMath.getEquivalentRectangularSize(mapRadius)
|
||||
return HexMath.getDistance(Vector2.Zero, tileInfo.position).toDouble() / HexMath.getDistance(Vector2.Zero, Vector2(size.x / 2, size.y / 2))
|
||||
@ -120,8 +120,6 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
|
||||
// region Cellular automata
|
||||
private fun generateLandCellularAutomata(tileMap: TileMap) {
|
||||
val mapRadius = tileMap.mapParameters.size.radius
|
||||
val mapType = tileMap.mapParameters.type
|
||||
val numSmooth = 4
|
||||
|
||||
//init
|
||||
|
@ -9,7 +9,7 @@ import com.unciv.models.ruleset.tile.TerrainType
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.round
|
||||
|
||||
class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
class NaturalWonderGenerator(val ruleset: Ruleset) {
|
||||
|
||||
/*
|
||||
https://gaming.stackexchange.com/questions/95095/do-natural-wonders-spawn-more-closely-to-city-states/96479
|
||||
@ -31,7 +31,7 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
val random = randomness.RNG.nextDouble()
|
||||
var sum = 0f
|
||||
for (wonder in allNaturalWonders) {
|
||||
sum += wonder.weight/totalWeight
|
||||
sum += wonder.weight / totalWeight
|
||||
if (random <= sum) {
|
||||
toBeSpawned.add(wonder)
|
||||
allNaturalWonders.remove(wonder)
|
||||
@ -78,11 +78,12 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnBarringerCrater(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.barringerCrater]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.grassland }
|
||||
&& it.neighbors.count{ neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } <= 2
|
||||
&& it.neighbors.count{ neighbor -> neighbor.getBaseTerrain().name == Constants.mountain || neighbor.isHill() } <= 4
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.grassland }
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } <= 2
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain || neighbor.isHill() } <= 4
|
||||
}
|
||||
|
||||
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
@ -94,13 +95,14 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnMountFuji(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.mountFuji]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.tundra }
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.desert }
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain }
|
||||
&& it.neighbors.none { neighbor -> neighbor.getLastTerrain().name == Constants.marsh }
|
||||
&& it.neighbors.count{ neighbor -> neighbor.isHill() } <= 2
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.tundra }
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.desert }
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain }
|
||||
&& it.neighbors.none { neighbor -> neighbor.getLastTerrain().name == Constants.marsh }
|
||||
&& it.neighbors.count { neighbor -> neighbor.isHill() } <= 2
|
||||
}
|
||||
|
||||
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
@ -112,11 +114,12 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnGrandMesa(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.grandMesa]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.count{ neighbor -> neighbor.isHill() } >= 2
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.grassland }
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } <= 2
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.count { neighbor -> neighbor.isHill() } >= 2
|
||||
&& it.neighbors.none { neighbor -> neighbor.getBaseTerrain().name == Constants.grassland }
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } <= 2
|
||||
}
|
||||
|
||||
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
@ -128,23 +131,27 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnGreatBarrierReef(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.greatBarrierReef]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& abs(it.latitude) > tileMap.maxLatitude * 0.1
|
||||
&& abs(it.latitude) < tileMap.maxLatitude * 0.7
|
||||
&& it.neighbors.all {neighbor -> neighbor.isWater}
|
||||
&& it.neighbors.any {neighbor ->
|
||||
neighbor.resource == null && neighbor.improvement == null
|
||||
&& wonder.occursOn.contains(neighbor.getLastTerrain().name)
|
||||
&& neighbor.neighbors.all{ it.isWater } }
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& abs(it.latitude) > tileMap.maxLatitude * 0.1
|
||||
&& abs(it.latitude) < tileMap.maxLatitude * 0.7
|
||||
&& it.neighbors.all { neighbor -> neighbor.isWater }
|
||||
&& it.neighbors.any { neighbor ->
|
||||
neighbor.resource == null && neighbor.improvement == null
|
||||
&& wonder.occursOn.contains(neighbor.getLastTerrain().name)
|
||||
&& neighbor.neighbors.all { it.isWater }
|
||||
}
|
||||
}
|
||||
|
||||
val location = trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
if (location != null) {
|
||||
val location2 = location.neighbors
|
||||
.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.all{ it.isWater } }
|
||||
.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.all { it.isWater }
|
||||
}
|
||||
.toList().random()
|
||||
|
||||
location2.naturalWonder = wonder.name
|
||||
@ -159,10 +166,11 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnKrakatoa(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.krakatoa]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.getBaseTerrain().name == Constants.coast }
|
||||
&& it.neighbors.none { neighbor -> neighbor.getLastTerrain().name == Constants.ice }
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.getBaseTerrain().name == Constants.coast }
|
||||
&& it.neighbors.none { neighbor -> neighbor.getLastTerrain().name == Constants.ice }
|
||||
}
|
||||
|
||||
val location = trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
@ -185,10 +193,11 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnRockOfGibraltar(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.rockOfGibraltar]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.getBaseTerrain().name == Constants.coast }
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } == 1
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.getBaseTerrain().name == Constants.coast }
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } == 1
|
||||
}
|
||||
|
||||
val location = trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
@ -220,14 +229,16 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnOldFaithful(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.oldFaithful]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } <= 4
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain ||
|
||||
neighbor.isHill()
|
||||
} >= 3
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.desert } <= 3
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.tundra } <= 3
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.mountain } <= 4
|
||||
&& it.neighbors.count { neighbor ->
|
||||
neighbor.getBaseTerrain().name == Constants.mountain ||
|
||||
neighbor.isHill()
|
||||
} >= 3
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.desert } <= 3
|
||||
&& it.neighbors.count { neighbor -> neighbor.getBaseTerrain().name == Constants.tundra } <= 3
|
||||
}
|
||||
|
||||
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
@ -238,9 +249,10 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnCerroDePotosi(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.cerroDePotosi]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.isHill() }
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.isHill() }
|
||||
}
|
||||
|
||||
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
@ -251,9 +263,10 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnElDorado(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.elDorado]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.getLastTerrain().name == Constants.jungle }
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
&& it.neighbors.any { neighbor -> neighbor.getLastTerrain().name == Constants.jungle }
|
||||
}
|
||||
|
||||
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
@ -264,8 +277,10 @@ class NaturalWonderGenerator(val ruleset: Ruleset){
|
||||
*/
|
||||
private fun spawnFountainOfYouth(tileMap: TileMap) {
|
||||
val wonder = ruleset.terrains[Constants.fountainOfYouth]!!
|
||||
val suitableLocations = tileMap.values.filter { it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name) }
|
||||
val suitableLocations = tileMap.values.filter {
|
||||
it.resource == null && it.improvement == null
|
||||
&& wonder.occursOn.contains(it.getLastTerrain().name)
|
||||
}
|
||||
|
||||
trySpawnOnSuitableLocation(suitableLocations, wonder)
|
||||
}
|
||||
|
@ -119,19 +119,20 @@ class BaseUnit : INamed, IConstruction {
|
||||
|| rejectionReason.startsWith("Consumes")
|
||||
}
|
||||
|
||||
fun getRejectionReason(construction: CityConstructions): String {
|
||||
if (unitType.isWaterUnit() && !construction.cityInfo.getCenterTile().isCoastalTile())
|
||||
fun getRejectionReason(cityConstructions: CityConstructions): String {
|
||||
if (unitType.isWaterUnit() && !cityConstructions.cityInfo.getCenterTile().isCoastalTile())
|
||||
return "Can only build water units in coastal cities"
|
||||
val civInfo = cityConstructions.cityInfo.civInfo
|
||||
for (unique in uniqueObjects.filter { it.placeholderText == "Not displayed as an available construction without []" }) {
|
||||
val filter = unique.params[0]
|
||||
if (filter in construction.cityInfo.civInfo.gameInfo.ruleSet.tileResources && !construction.cityInfo.civInfo.hasResource(filter)
|
||||
|| filter in construction.cityInfo.civInfo.gameInfo.ruleSet.buildings && !construction.containsBuildingOrEquivalent(filter))
|
||||
if (filter in civInfo.gameInfo.ruleSet.tileResources && !civInfo.hasResource(filter)
|
||||
|| filter in civInfo.gameInfo.ruleSet.buildings && !cityConstructions.containsBuildingOrEquivalent(filter))
|
||||
return "Should not be displayed"
|
||||
}
|
||||
val civRejectionReason = getRejectionReason(construction.cityInfo.civInfo)
|
||||
val civRejectionReason = getRejectionReason(civInfo)
|
||||
if (civRejectionReason != "") return civRejectionReason
|
||||
for (unique in uniqueObjects.filter { it.placeholderText == "Requires at least [] population" })
|
||||
if (unique.params[0].toInt() > construction.cityInfo.population.population)
|
||||
if (unique.params[0].toInt() > cityConstructions.cityInfo.population.population)
|
||||
return unique.text
|
||||
return ""
|
||||
}
|
||||
|
@ -1,21 +1,15 @@
|
||||
package com.unciv.ui.mapeditor
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent
|
||||
import com.badlogic.gdx.scenes.scene2d.InputListener
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin
|
||||
import com.badlogic.gdx.utils.Array
|
||||
import com.unciv.logic.MapSaver
|
||||
import com.unciv.logic.map.ScenarioMap
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.RulesetCache
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.newgamescreen.GameSetupInfo
|
||||
import com.unciv.ui.utils.*
|
||||
|
||||
@ -34,25 +28,6 @@ class MapEditorScreen(): CameraStageBaseScreen() {
|
||||
private val showHideEditorOptionsButton = ">".toTextButton()
|
||||
|
||||
|
||||
constructor(mapNameToLoad: String?) : this() {
|
||||
var mapToLoad = mapNameToLoad
|
||||
if (mapToLoad == null) {
|
||||
val existingSaves = MapSaver.getMaps()
|
||||
if (existingSaves.isNotEmpty())
|
||||
mapToLoad = existingSaves.first().name()
|
||||
}
|
||||
|
||||
if (mapToLoad != null) {
|
||||
mapName = mapToLoad
|
||||
scenarioName = mapToLoad
|
||||
tileMap = MapSaver.loadMap(mapName)
|
||||
}
|
||||
|
||||
initialize()
|
||||
}
|
||||
|
||||
constructor(mapFile:FileHandle):this()
|
||||
|
||||
constructor(map: TileMap) : this() {
|
||||
tileMap = map
|
||||
initialize()
|
||||
@ -178,24 +153,7 @@ class MapEditorScreen(): CameraStageBaseScreen() {
|
||||
}
|
||||
}
|
||||
|
||||
fun hasScenario(): Boolean {
|
||||
return this.scenarioMap != null
|
||||
}
|
||||
}
|
||||
|
||||
class TranslatedSelectBox(values : Collection<String>, default:String, skin: Skin) : SelectBox<TranslatedSelectBox.TranslatedString>(skin) {
|
||||
class TranslatedString(val value: String) {
|
||||
val translation = value.tr()
|
||||
override fun toString() = translation
|
||||
}
|
||||
|
||||
init {
|
||||
val array = Array<TranslatedString>()
|
||||
values.forEach { array.add(TranslatedString(it)) }
|
||||
items = array
|
||||
val defaultItem = array.firstOrNull { it.value == default }
|
||||
selected = if (defaultItem != null) defaultItem else array.first()
|
||||
}
|
||||
fun hasScenario() = this.scenarioMap != null
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user