diff --git a/android/src/com/unciv/app/AndroidLauncher.kt b/android/src/com/unciv/app/AndroidLauncher.kt index cf500c92c3..a5ef1f02d7 100644 --- a/android/src/com/unciv/app/AndroidLauncher.kt +++ b/android/src/com/unciv/app/AndroidLauncher.kt @@ -7,6 +7,7 @@ import androidx.work.WorkManager import com.badlogic.gdx.backends.android.AndroidApplication import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration import com.unciv.UncivGame +import com.unciv.UncivGameParameters import com.unciv.logic.GameSaver import java.io.File @@ -23,12 +24,13 @@ class AndroidLauncher : AndroidApplication() { } val config = AndroidApplicationConfiguration().apply { useImmersiveMode = true } - val game = UncivGame ( + val androidParameters = UncivGameParameters( version = BuildConfig.VERSION_NAME, crashReportSender = CrashReportSenderAndroid(this), exitEvent = this::finish, fontImplementation = NativeFontAndroid(45) - ) + ) + val game = UncivGame ( androidParameters ) initialize(game, config) } diff --git a/core/src/com/unciv/UncivGame.kt b/core/src/com/unciv/UncivGame.kt index 5031aa720a..e4c754bc08 100644 --- a/core/src/com/unciv/UncivGame.kt +++ b/core/src/com/unciv/UncivGame.kt @@ -18,15 +18,16 @@ import com.unciv.ui.worldscreen.WorldScreen import java.util.* import kotlin.concurrent.thread -class UncivGame( - val version: String, - private val crashReportSender: CrashReportSender? = null, - val exitEvent: (()->Unit)? = null, - val cancelDiscordEvent: (()->Unit)? = null, - val fontImplementation: NativeFontImplementation? = null -) : Game() { +class UncivGame(parameters: UncivGameParameters) : Game() { // we need this secondary constructor because Java code for iOS can't handle Kotlin lambda parameters - constructor(version: String) : this(version, null) + constructor(version: String) : this(UncivGameParameters(version, null)) + + val version = parameters.version + private val crashReportSender = parameters.crashReportSender + val exitEvent = parameters.exitEvent + val cancelDiscordEvent = parameters.cancelDiscordEvent + val fontImplementation = parameters.fontImplementation + val consoleMode = parameters.consoleMode lateinit var gameInfo: GameInfo fun isGameInfoInitialized() = this::gameInfo.isInitialized diff --git a/core/src/com/unciv/UncivGameParameters.kt b/core/src/com/unciv/UncivGameParameters.kt new file mode 100644 index 0000000000..6e7f85be61 --- /dev/null +++ b/core/src/com/unciv/UncivGameParameters.kt @@ -0,0 +1,12 @@ +package com.unciv + +import com.unciv.ui.utils.CrashReportSender +import com.unciv.ui.utils.NativeFontImplementation + +class UncivGameParameters(val version: String, + val crashReportSender: CrashReportSender? = null, + val exitEvent: (()->Unit)? = null, + val cancelDiscordEvent: (()->Unit)? = null, + val fontImplementation: NativeFontImplementation? = null, + val consoleMode: Boolean = false) { +} \ No newline at end of file diff --git a/desktop/src/com/unciv/app/desktop/DesktopLauncher.kt b/desktop/src/com/unciv/app/desktop/DesktopLauncher.kt index 972a8a8fb3..d8b0910d0c 100644 --- a/desktop/src/com/unciv/app/desktop/DesktopLauncher.kt +++ b/desktop/src/com/unciv/app/desktop/DesktopLauncher.kt @@ -9,6 +9,7 @@ import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.tools.texturepacker.TexturePacker import com.unciv.UncivGame +import com.unciv.UncivGameParameters import com.unciv.models.translations.tr import io.ktor.application.call import io.ktor.http.HttpStatusCode @@ -41,7 +42,14 @@ internal object DesktopLauncher { val versionFromJar = DesktopLauncher.javaClass.`package`.specificationVersion ?: "Desktop" - val game = UncivGame ( versionFromJar, null, { exitProcess(0) }, { discordTimer?.cancel() }, NativeFontDesktop(45) ) + val desktopParameters = UncivGameParameters( + versionFromJar, + exitEvent = { exitProcess(0) }, + cancelDiscordEvent = { discordTimer?.cancel() }, + fontImplementation = NativeFontDesktop(45) + ) + + val game = UncivGame ( desktopParameters ) if(!RaspberryPiDetector.isRaspberryPi()) // No discord RPC for Raspberry Pi, see https://github.com/yairm210/Unciv/issues/1624 tryActivateDiscord(game) diff --git a/tests/src/com/unciv/testing/BasicTests.kt b/tests/src/com/unciv/testing/BasicTests.kt index e1c54b423e..b08f2f239d 100644 --- a/tests/src/com/unciv/testing/BasicTests.kt +++ b/tests/src/com/unciv/testing/BasicTests.kt @@ -3,6 +3,7 @@ package com.unciv.testing import com.badlogic.gdx.Gdx import com.unciv.UncivGame +import com.unciv.UncivGameParameters import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.RulesetCache import com.unciv.models.ruleset.unit.BaseUnit @@ -35,13 +36,16 @@ class BasicTests { @Test fun gameIsNotRunWithDebugModes() { - val game = UncivGame("", null, null) + val params = UncivGameParameters("", null, null) + val game = UncivGame(params) Assert.assertTrue("This test will only pass if the game is not run with debug modes", !game.superchargedForDebug && !game.viewEntireMapForDebug && game.simulateUntilTurnForDebug <= 0 && !game.simulateUntilWin - && !game.scenarioDebugSwitch) + && !game.scenarioDebugSwitch + && !game.consoleMode + ) } // If there's a unit that obsoletes with no upgrade then when it obsoletes