Can put maps in mods!

All Map based logic changed to by-FileHandle instead of by-name  to support this
This commit is contained in:
Yair Morgenstern
2020-08-27 14:43:49 +03:00
parent d2e914473a
commit 2a8202d8b6
11 changed files with 103 additions and 77 deletions

View File

@ -23,8 +23,10 @@ object GameStarter {
if (gameSetupInfo.mapParameters.type == MapType.scenarioMap) if (gameSetupInfo.mapParameters.type == MapType.scenarioMap)
gameInfo.tileMap = MapSaver.loadScenario(gameSetupInfo.mapParameters.name).tileMap gameInfo.tileMap = MapSaver.loadScenario(gameSetupInfo.mapParameters.name).tileMap
else if (gameSetupInfo.mapParameters.name != "") else if (gameSetupInfo.mapParameters.name != "") {
gameInfo.tileMap = MapSaver.loadMap(gameSetupInfo.mapParameters.name) gameInfo.tileMap = MapSaver.loadMap(gameSetupInfo.mapFile!!)
}
else gameInfo.tileMap = MapGenerator(ruleset).generateMap(gameSetupInfo.mapParameters) else gameInfo.tileMap = MapGenerator(ruleset).generateMap(gameSetupInfo.mapParameters)
gameInfo.tileMap.mapParameters = gameSetupInfo.mapParameters gameInfo.tileMap.mapParameters = gameSetupInfo.mapParameters

View File

@ -1,7 +1,8 @@
package com.unciv.logic package com.unciv.logic
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.unciv.logic.map.Scenario import com.badlogic.gdx.files.FileHandle
import com.unciv.logic.map.ScenarioMap
import com.unciv.logic.map.TileMap import com.unciv.logic.map.TileMap
import com.unciv.ui.saves.Gzip import com.unciv.ui.saves.Gzip
@ -19,29 +20,33 @@ object MapSaver {
getMap(mapName).writeString(Gzip.zip(json().toJson(tileMap)), false) getMap(mapName).writeString(Gzip.zip(json().toJson(tileMap)), false)
} }
fun saveScenario(scenarioName:String, scenario: Scenario) { fun saveScenario(scenarioName:String, scenarioMap: ScenarioMap) {
getScenario(scenarioName).writeString(Gzip.zip(json().toJson(scenario)), false) getScenario(scenarioName).writeString(Gzip.zip(json().toJson(scenarioMap)), false)
} }
fun loadMap(mapName: String): TileMap { fun loadMap(mapName: String) = loadMap(getMap(mapName))
val gzippedString = getMap(mapName).readString()
fun loadMap(mapFile:FileHandle):TileMap{
val gzippedString = mapFile.readString()
val unzippedJson = Gzip.unzip(gzippedString) val unzippedJson = Gzip.unzip(gzippedString)
return json().fromJson(TileMap::class.java, unzippedJson) return json().fromJson(TileMap::class.java, unzippedJson)
} }
fun loadScenario(scenarioName: String): Scenario { fun loadScenario(scenarioName: String) = loadScenario(getScenario(scenarioName))
val gzippedString = getScenario(scenarioName).readString()
fun loadScenario(scenarioFile: FileHandle): ScenarioMap {
val gzippedString = scenarioFile.readString()
val unzippedJson = Gzip.unzip(gzippedString) val unzippedJson = Gzip.unzip(gzippedString)
return json().fromJson(Scenario::class.java, unzippedJson) return json().fromJson(ScenarioMap::class.java, unzippedJson)
} }
fun deleteMap(mapName: String) = getMap(mapName).delete() fun deleteMap(mapName: String) = getMap(mapName).delete()
fun deleteScenario(scenarioName: String) = getScenario(scenarioName).delete() fun deleteScenario(scenarioName: String) = getScenario(scenarioName).delete()
fun getMaps() = Gdx.files.local(mapsFolder).list().map { it.name() } fun getMaps() = Gdx.files.local(mapsFolder).list()
fun getScenarios() = Gdx.files.local(scenariosFolder).list().map { it.name() } fun getScenarios() = Gdx.files.local(scenariosFolder).list()
fun mapFromJson(json:String): TileMap = json().fromJson(TileMap::class.java, json) fun mapFromJson(json:String): TileMap = json().fromJson(TileMap::class.java, json)
} }

View File

@ -2,7 +2,7 @@ package com.unciv.logic.map
import com.unciv.models.metadata.GameParameters import com.unciv.models.metadata.GameParameters
class Scenario { class ScenarioMap {
lateinit var tileMap: TileMap lateinit var tileMap: TileMap
lateinit var gameParameters: GameParameters lateinit var gameParameters: GameParameters

View File

@ -1,12 +1,10 @@
package com.unciv.ui.mapeditor package com.unciv.ui.mapeditor
import com.unciv.UncivGame import com.unciv.UncivGame
import com.unciv.logic.map.Scenario import com.unciv.logic.map.ScenarioMap
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.RulesetCache import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.newgamescreen.GameOptionsTable import com.unciv.ui.newgamescreen.GameOptionsTable
import com.unciv.ui.newgamescreen.GameSetupInfo
import com.unciv.ui.newgamescreen.PlayerPickerTable import com.unciv.ui.newgamescreen.PlayerPickerTable
import com.unciv.ui.newgamescreen.IPreviousScreen import com.unciv.ui.newgamescreen.IPreviousScreen
import com.unciv.ui.pickerscreens.PickerScreen import com.unciv.ui.pickerscreens.PickerScreen
@ -36,7 +34,7 @@ class GameParametersScreen(var mapEditorScreen: MapEditorScreen): IPreviousScree
rightSideButton.setText("OK".tr()) rightSideButton.setText("OK".tr())
rightSideButton.onClick { rightSideButton.onClick {
mapEditorScreen.gameSetupInfo = gameSetupInfo mapEditorScreen.gameSetupInfo = gameSetupInfo
mapEditorScreen.scenario = Scenario(mapEditorScreen.tileMap, mapEditorScreen.gameSetupInfo.gameParameters) mapEditorScreen.scenarioMap = ScenarioMap(mapEditorScreen.tileMap, mapEditorScreen.gameSetupInfo.gameParameters)
mapEditorScreen.ruleset.clear() mapEditorScreen.ruleset.clear()
mapEditorScreen.ruleset.add(ruleset) mapEditorScreen.ruleset.add(ruleset)
mapEditorScreen.tileEditorOptions.update() mapEditorScreen.tileEditorOptions.update()

View File

@ -1,6 +1,7 @@
package com.unciv.ui.mapeditor package com.unciv.ui.mapeditor
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.files.FileHandle
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.badlogic.gdx.scenes.scene2d.ui.TextButton
@ -15,7 +16,7 @@ import com.unciv.ui.utils.*
import com.unciv.ui.utils.AutoScrollPane as ScrollPane import com.unciv.ui.utils.AutoScrollPane as ScrollPane
class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
var chosenMap = "" var chosenMap:FileHandle? = null
val deleteButton = "Delete map".toTextButton() val deleteButton = "Delete map".toTextButton()
var scenarioMap = false var scenarioMap = false
val mapsTable = Table().apply { defaults().pad(10f) } val mapsTable = Table().apply { defaults().pad(10f) }
@ -34,8 +35,8 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
rightSideButton.setText("Load map".tr()) rightSideButton.setText("Load map".tr())
rightSideButton.onClick { rightSideButton.onClick {
val mapEditorScreen = if (scenarioMap) MapEditorScreen(MapSaver.loadScenario(chosenMap), chosenMap) val mapEditorScreen = if (scenarioMap) MapEditorScreen(MapSaver.loadScenario(chosenMap!!), chosenMap!!.name())
else MapEditorScreen(chosenMap) else MapEditorScreen(chosenMap!!)
UncivGame.Current.setScreen(mapEditorScreen) UncivGame.Current.setScreen(mapEditorScreen)
dispose() dispose()
} }
@ -71,8 +72,7 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
deleteButton.onClick { deleteButton.onClick {
YesNoPopup("Are you sure you want to delete this map?", { YesNoPopup("Are you sure you want to delete this map?", {
if (scenarioMap) MapSaver.deleteScenario(chosenMap) chosenMap!!.delete()
else MapSaver.deleteMap(chosenMap)
UncivGame.Current.setScreen(LoadMapScreen(previousMap)) UncivGame.Current.setScreen(LoadMapScreen(previousMap))
}, this).open() }, this).open()
} }
@ -86,7 +86,7 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
} }
fun update() { fun update() {
chosenMap = "" chosenMap = null
deleteButton.disable() deleteButton.disable()
deleteButton.color = Color.RED deleteButton.color = Color.RED
@ -96,7 +96,7 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
mapsTable.clear() mapsTable.clear()
for (scenario in MapSaver.getScenarios()) { for (scenario in MapSaver.getScenarios()) {
val loadScenarioButton = TextButton(scenario, skin) val loadScenarioButton = TextButton(scenario.name(), skin)
loadScenarioButton.onClick { loadScenarioButton.onClick {
rightSideButton.enable() rightSideButton.enable()
chosenMap = scenario chosenMap = scenario
@ -111,7 +111,7 @@ class LoadMapScreen(previousMap: TileMap?) : PickerScreen(){
mapsTable.clear() mapsTable.clear()
for (map in MapSaver.getMaps()) { for (map in MapSaver.getMaps()) {
val loadMapButton = TextButton(map, skin) val loadMapButton = TextButton(map.name(), skin)
loadMapButton.onClick { loadMapButton.onClick {
rightSideButton.enable() rightSideButton.enable()
chosenMap = map chosenMap = map

View File

@ -9,7 +9,7 @@ import com.unciv.UncivGame
import com.unciv.logic.MapSaver import com.unciv.logic.MapSaver
import com.unciv.logic.map.MapType import com.unciv.logic.map.MapType
import com.unciv.logic.map.RoadStatus import com.unciv.logic.map.RoadStatus
import com.unciv.logic.map.Scenario import com.unciv.logic.map.ScenarioMap
import com.unciv.logic.map.TileMap import com.unciv.logic.map.TileMap
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.models.metadata.Player import com.unciv.models.metadata.Player
@ -82,10 +82,10 @@ class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorS
try { try {
if(mapEditorScreen.hasScenario()) { if(mapEditorScreen.hasScenario()) {
mapEditorScreen.tileMap.mapParameters.type = MapType.scenarioMap mapEditorScreen.tileMap.mapParameters.type = MapType.scenarioMap
mapEditorScreen.scenario = Scenario(mapEditorScreen.tileMap, mapEditorScreen.gameSetupInfo.gameParameters) mapEditorScreen.scenarioMap = ScenarioMap(mapEditorScreen.tileMap, mapEditorScreen.gameSetupInfo.gameParameters)
mapEditorScreen.scenario!!.gameParameters.godMode = true // so we can edit this scenario when loading from the map mapEditorScreen.scenarioMap!!.gameParameters.godMode = true // so we can edit this scenario when loading from the map
mapEditorScreen.scenarioName = mapNameEditor.text mapEditorScreen.scenarioName = mapNameEditor.text
MapSaver.saveScenario(mapNameEditor.text, mapEditorScreen.scenario!!) MapSaver.saveScenario(mapNameEditor.text, mapEditorScreen.scenarioMap!!)
} }
else { else {
MapSaver.saveMap(mapEditorScreen.mapName, mapEditorScreen.tileMap) MapSaver.saveMap(mapEditorScreen.mapName, mapEditorScreen.tileMap)

View File

@ -1,5 +1,6 @@
package com.unciv.ui.mapeditor package com.unciv.ui.mapeditor
import com.badlogic.gdx.files.FileHandle
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.InputEvent import com.badlogic.gdx.scenes.scene2d.InputEvent
@ -9,21 +10,20 @@ import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
import com.badlogic.gdx.scenes.scene2d.ui.Skin import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.utils.Array import com.badlogic.gdx.utils.Array
import com.unciv.logic.MapSaver import com.unciv.logic.MapSaver
import com.unciv.logic.map.Scenario import com.unciv.logic.map.ScenarioMap
import com.unciv.logic.map.TileInfo import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.TileMap import com.unciv.logic.map.TileMap
import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.RulesetCache import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.newgamescreen.GameSetupInfo import com.unciv.ui.newgamescreen.GameSetupInfo
import com.unciv.ui.newgamescreen.IPreviousScreen
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
class MapEditorScreen(): CameraStageBaseScreen() { class MapEditorScreen(): CameraStageBaseScreen() {
var mapName = "" var mapName = ""
var tileMap = TileMap() var tileMap = TileMap()
var scenarioName = "" // when loading map: mapName is taken as default for scenarioName var scenarioName = "" // when loading map: mapName is taken as default for scenarioName
var scenario: Scenario? = null // main indicator whether scenario information is present var scenarioMap: ScenarioMap? = null // main indicator whether scenario information is present
var ruleset = Ruleset().apply { add(RulesetCache.getBaseRuleset()) } // Since we change this in scenarios, we can't take the base ruleset directly var ruleset = Ruleset().apply { add(RulesetCache.getBaseRuleset()) } // Since we change this in scenarios, we can't take the base ruleset directly
var gameSetupInfo = GameSetupInfo() var gameSetupInfo = GameSetupInfo()
@ -39,7 +39,7 @@ class MapEditorScreen(): CameraStageBaseScreen() {
if (mapToLoad == null) { if (mapToLoad == null) {
val existingSaves = MapSaver.getMaps() val existingSaves = MapSaver.getMaps()
if (existingSaves.isNotEmpty()) if (existingSaves.isNotEmpty())
mapToLoad = existingSaves.first() mapToLoad = existingSaves.first().name()
} }
if (mapToLoad != null) { if (mapToLoad != null) {
@ -51,22 +51,24 @@ class MapEditorScreen(): CameraStageBaseScreen() {
initialize() initialize()
} }
constructor(mapFile:FileHandle):this(MapSaver.loadMap(mapFile))
constructor(map: TileMap) : this() { constructor(map: TileMap) : this() {
tileMap = map tileMap = map
initialize() initialize()
} }
constructor(scenario: Scenario, scenarioName: String = "") : this() { constructor(scenarioMap: ScenarioMap, scenarioName: String = "") : this() {
tileMap = scenario.tileMap tileMap = scenarioMap.tileMap
mapName = scenarioName mapName = scenarioName
this.scenario = scenario this.scenarioMap = scenarioMap
this.scenarioName = scenarioName this.scenarioName = scenarioName
gameSetupInfo.gameParameters = scenario.gameParameters gameSetupInfo.gameParameters = scenarioMap.gameParameters
// Since the ruleset is referenced directly from other places, we can't just replace it directly // Since the ruleset is referenced directly from other places, we can't just replace it directly
ruleset.clear() ruleset.clear()
ruleset.add(RulesetCache.getComplexRuleset(scenario.gameParameters)) ruleset.add(RulesetCache.getComplexRuleset(scenarioMap.gameParameters))
initialize() initialize()
} }
@ -177,7 +179,7 @@ class MapEditorScreen(): CameraStageBaseScreen() {
} }
fun hasScenario(): Boolean { fun hasScenario(): Boolean {
return this.scenario != null return this.scenarioMap != null
} }
} }

View File

@ -178,7 +178,8 @@ class GameOptionsTable(val previousScreen: IPreviousScreen, val updatePlayerPick
} }
fun Table.addModCheckboxes() { fun Table.addModCheckboxes() {
val modRulesets = RulesetCache.values.filter { it.name != "" } val modRulesets = RulesetCache.values.filter { it.name != ""
&& (it.name in gameParameters.mods || !it.modOptions.uniques.contains("Scenario only")) } // Don't allow scenario mods for a regular 'new game'
if (modRulesets.isEmpty()) return if (modRulesets.isEmpty()) return
add("Mods:".toLabel(fontSize = 24)).padTop(16f).colspan(2).row() add("Mods:".toLabel(fontSize = 24)).padTop(16f).colspan(2).row()

View File

@ -74,11 +74,6 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
scenarioMapOptionsTable.add(scenarioMapSelectBox).maxWidth(newGameScreen.stage.width / 2) scenarioMapOptionsTable.add(scenarioMapSelectBox).maxWidth(newGameScreen.stage.width / 2)
.right().row() .right().row()
// The SelectBox auto displays the text a object.toString(), which on the FileHandle itself includes the folder path.
// So we wrap it in another object with a custom toString()
class FileHandleWrapper(val fileHandle: FileHandle){
override fun toString() = fileHandle.name()
}
val scenarioFiles = getScenarioFiles() val scenarioFiles = getScenarioFiles()
val scenarioSelectBox = SelectBox<FileHandleWrapper>(CameraStageBaseScreen.skin) val scenarioSelectBox = SelectBox<FileHandleWrapper>(CameraStageBaseScreen.skin)
@ -98,14 +93,14 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
mapTypeSpecificTable.clear() mapTypeSpecificTable.clear()
if (mapTypeSelectBox.selected.value == MapType.custom) { if (mapTypeSelectBox.selected.value == MapType.custom) {
mapParameters.type = MapType.custom mapParameters.type = MapType.custom
mapParameters.name = mapFileSelectBox.selected mapParameters.name = mapFileSelectBox.selected.toString()
mapTypeSpecificTable.add(savedMapOptionsTable) mapTypeSpecificTable.add(savedMapOptionsTable)
newGameScreen.gameSetupInfo.gameParameters.godMode = false newGameScreen.gameSetupInfo.gameParameters.godMode = false
newGameScreen.unlockTables() newGameScreen.unlockTables()
newGameScreen.updateTables() newGameScreen.updateTables()
} else if (mapTypeSelectBox.selected.value == MapType.scenarioMap) { } else if (mapTypeSelectBox.selected.value == MapType.scenarioMap) {
mapParameters.type = MapType.scenarioMap mapParameters.type = MapType.scenarioMap
mapParameters.name = scenarioMapSelectBox.selected mapParameters.name = scenarioMapSelectBox.selected.toString()
mapTypeSpecificTable.add(scenarioMapOptionsTable) mapTypeSpecificTable.add(scenarioMapOptionsTable)
val scenario = MapSaver.loadScenario(mapParameters.name) val scenario = MapSaver.loadScenario(mapParameters.name)
newGameScreen.gameSetupInfo.gameParameters = scenario.gameParameters newGameScreen.gameSetupInfo.gameParameters = scenario.gameParameters
@ -137,26 +132,39 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
add(mapTypeSpecificTable).colspan(2).row() add(mapTypeSpecificTable).colspan(2).row()
} }
private fun getMapFileSelectBox(): SelectBox<String> { private fun getMapFileSelectBox(): SelectBox<FileHandleWrapper> {
val mapFileSelectBox = SelectBox<String>(CameraStageBaseScreen.skin) val mapFileSelectBox = SelectBox<FileHandleWrapper>(CameraStageBaseScreen.skin)
val mapNames = Array<String>() val mapFiles = Array<FileHandleWrapper>()
for (mapName in MapSaver.getMaps()) mapNames.add(mapName) for (mapFile in MapSaver.getMaps())
mapFileSelectBox.items = mapNames mapFiles.add(FileHandleWrapper(mapFile))
if (mapParameters.name in mapNames) mapFileSelectBox.selected = mapParameters.name for(mod in Gdx.files.local("mods").list()){
val mapsFolder = mod.child("maps")
if(mapsFolder.exists())
for(map in mapsFolder.list())
mapFiles.add(FileHandleWrapper(map))
}
mapFileSelectBox.items = mapFiles
val selectedItem = mapFiles.firstOrNull { it.fileHandle.name()==mapParameters.name }
if(selectedItem!=null) mapFileSelectBox.selected = selectedItem
mapFileSelectBox.onChange { mapParameters.name = mapFileSelectBox.selected!! } mapFileSelectBox.onChange {
val mapFile = mapFileSelectBox.selected.fileHandle
mapParameters.name = mapFile.name()
newGameScreen.gameSetupInfo.mapFile = mapFile
}
return mapFileSelectBox return mapFileSelectBox
} }
private fun getScenarioFileSelectBox(): SelectBox<String> { private fun getScenarioFileSelectBox(): SelectBox<FileHandleWrapper> {
val scenarioFileSelectBox = SelectBox<String>(CameraStageBaseScreen.skin) val scenarioFileSelectBox = SelectBox<FileHandleWrapper>(CameraStageBaseScreen.skin)
val scenarioNames = Array<String>() val scenarioFiles = Array<FileHandleWrapper>()
for (scenarioName in MapSaver.getScenarios()) scenarioNames.add(scenarioName) for (scenarioName in MapSaver.getScenarios()) scenarioFiles.add(FileHandleWrapper(scenarioName))
scenarioFileSelectBox.items = scenarioNames scenarioFileSelectBox.items = scenarioFiles
if (mapParameters.name in scenarioNames) scenarioFileSelectBox.selected = mapParameters.name val selectedItem = scenarioFiles.firstOrNull { it.fileHandle.name()==mapParameters.name }
if(selectedItem!=null ) scenarioFileSelectBox.selected = selectedItem
scenarioFileSelectBox.onChange { scenarioFileSelectBox.onChange {
mapParameters.name = scenarioFileSelectBox.selected!! mapParameters.name = scenarioFileSelectBox.selected!!.fileHandle.name()
val scenario = MapSaver.loadScenario(mapParameters.name) val scenario = MapSaver.loadScenario(mapParameters.name)
newGameScreen.apply { newGameScreen.apply {
gameSetupInfo.gameParameters = scenario.gameParameters gameSetupInfo.gameParameters = scenario.gameParameters
@ -168,5 +176,9 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() {
return scenarioFileSelectBox return scenarioFileSelectBox
} }
// The SelectBox auto displays the text a object.toString(), which on the FileHandle itself includes the folder path.
// So we wrap it in another object with a custom toString()
class FileHandleWrapper(val fileHandle: FileHandle){
override fun toString() = fileHandle.name()
}
} }

View File

@ -2,6 +2,7 @@ package com.unciv.ui.newgamescreen
import com.unciv.ui.utils.AutoScrollPane as ScrollPane import com.unciv.ui.utils.AutoScrollPane as ScrollPane
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.files.FileHandle
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
import com.badlogic.gdx.scenes.scene2d.ui.Skin import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.utils.Array import com.badlogic.gdx.utils.Array
@ -21,6 +22,7 @@ import kotlin.concurrent.thread
class GameSetupInfo(var gameId:String, var gameParameters: GameParameters, var mapParameters: MapParameters) { class GameSetupInfo(var gameId:String, var gameParameters: GameParameters, var mapParameters: MapParameters) {
var mapFile: FileHandle? = null
constructor() : this("", GameParameters(), MapParameters()) constructor() : this("", GameParameters(), MapParameters())
constructor(gameInfo: GameInfo) : this("", gameInfo.gameParameters.clone(), gameInfo.tileMap.mapParameters) constructor(gameInfo: GameInfo) : this("", gameInfo.gameParameters.clone(), gameInfo.tileMap.mapParameters)
constructor(gameParameters: GameParameters, mapParameters: MapParameters) : this("", gameParameters, mapParameters) constructor(gameParameters: GameParameters, mapParameters: MapParameters) : this("", gameParameters, mapParameters)

View File

@ -31,12 +31,15 @@ class ModManagementScreen: PickerScreen() {
repoList = Github.tryGetGithubReposWithTopic() repoList = Github.tryGetGithubReposWithTopic()
} catch (ex: Exception) { } catch (ex: Exception) {
Gdx.app.postRunnable {
ResponsePopup("Could not download mod list", this) ResponsePopup("Could not download mod list", this)
}
return@thread return@thread
} }
Gdx.app.postRunnable {
for (repo in repoList) { for (repo in repoList) {
repo.name = repo.name.replace('-',' ') repo.name = repo.name.replace('-', ' ')
val downloadButton = repo.name.toTextButton() val downloadButton = repo.name.toTextButton()
downloadButton.onClick { downloadButton.onClick {
descriptionLabel.setText(repo.description + "\n" + "[${repo.stargazers_count}] Stars".tr()) descriptionLabel.setText(repo.description + "\n" + "[${repo.stargazers_count}] Stars".tr())
@ -46,7 +49,7 @@ class ModManagementScreen: PickerScreen() {
rightSideButton.onClick { rightSideButton.onClick {
rightSideButton.setText("Downloading...") rightSideButton.setText("Downloading...")
rightSideButton.disable() rightSideButton.disable()
downloadMod(repo.svn_url){ downloadMod(repo.svn_url) {
rightSideButton.setText("Done!".tr()) rightSideButton.setText("Done!".tr())
} }
} }
@ -54,6 +57,7 @@ class ModManagementScreen: PickerScreen() {
downloadTable.add(downloadButton).row() downloadTable.add(downloadButton).row()
} }
} }
}
topTable.add(downloadTable) topTable.add(downloadTable)
} }