mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-16 18:59:15 +07:00
Refactor UncivGame initialization - add UncivGameParameters. (#2779)
This commit is contained in:

committed by
GitHub

parent
79ff8c2ecf
commit
5356e63249
@ -7,6 +7,7 @@ import androidx.work.WorkManager
|
|||||||
import com.badlogic.gdx.backends.android.AndroidApplication
|
import com.badlogic.gdx.backends.android.AndroidApplication
|
||||||
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration
|
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
|
import com.unciv.UncivGameParameters
|
||||||
import com.unciv.logic.GameSaver
|
import com.unciv.logic.GameSaver
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@ -23,12 +24,13 @@ class AndroidLauncher : AndroidApplication() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val config = AndroidApplicationConfiguration().apply { useImmersiveMode = true }
|
val config = AndroidApplicationConfiguration().apply { useImmersiveMode = true }
|
||||||
val game = UncivGame (
|
val androidParameters = UncivGameParameters(
|
||||||
version = BuildConfig.VERSION_NAME,
|
version = BuildConfig.VERSION_NAME,
|
||||||
crashReportSender = CrashReportSenderAndroid(this),
|
crashReportSender = CrashReportSenderAndroid(this),
|
||||||
exitEvent = this::finish,
|
exitEvent = this::finish,
|
||||||
fontImplementation = NativeFontAndroid(45)
|
fontImplementation = NativeFontAndroid(45)
|
||||||
)
|
)
|
||||||
|
val game = UncivGame ( androidParameters )
|
||||||
initialize(game, config)
|
initialize(game, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,15 +18,16 @@ import com.unciv.ui.worldscreen.WorldScreen
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class UncivGame(
|
class UncivGame(parameters: UncivGameParameters) : Game() {
|
||||||
val version: String,
|
|
||||||
private val crashReportSender: CrashReportSender? = null,
|
|
||||||
val exitEvent: (()->Unit)? = null,
|
|
||||||
val cancelDiscordEvent: (()->Unit)? = null,
|
|
||||||
val fontImplementation: NativeFontImplementation? = null
|
|
||||||
) : Game() {
|
|
||||||
// we need this secondary constructor because Java code for iOS can't handle Kotlin lambda parameters
|
// 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
|
lateinit var gameInfo: GameInfo
|
||||||
fun isGameInfoInitialized() = this::gameInfo.isInitialized
|
fun isGameInfoInitialized() = this::gameInfo.isInitialized
|
||||||
|
12
core/src/com/unciv/UncivGameParameters.kt
Normal file
12
core/src/com/unciv/UncivGameParameters.kt
Normal file
@ -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) {
|
||||||
|
}
|
@ -9,6 +9,7 @@ import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
|
|||||||
import com.badlogic.gdx.graphics.Texture
|
import com.badlogic.gdx.graphics.Texture
|
||||||
import com.badlogic.gdx.tools.texturepacker.TexturePacker
|
import com.badlogic.gdx.tools.texturepacker.TexturePacker
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
|
import com.unciv.UncivGameParameters
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import io.ktor.application.call
|
import io.ktor.application.call
|
||||||
import io.ktor.http.HttpStatusCode
|
import io.ktor.http.HttpStatusCode
|
||||||
@ -41,7 +42,14 @@ internal object DesktopLauncher {
|
|||||||
|
|
||||||
val versionFromJar = DesktopLauncher.javaClass.`package`.specificationVersion ?: "Desktop"
|
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
|
if(!RaspberryPiDetector.isRaspberryPi()) // No discord RPC for Raspberry Pi, see https://github.com/yairm210/Unciv/issues/1624
|
||||||
tryActivateDiscord(game)
|
tryActivateDiscord(game)
|
||||||
|
@ -3,6 +3,7 @@ package com.unciv.testing
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
|
import com.unciv.UncivGameParameters
|
||||||
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.ruleset.unit.BaseUnit
|
import com.unciv.models.ruleset.unit.BaseUnit
|
||||||
@ -35,13 +36,16 @@ class BasicTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun gameIsNotRunWithDebugModes() {
|
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",
|
Assert.assertTrue("This test will only pass if the game is not run with debug modes",
|
||||||
!game.superchargedForDebug
|
!game.superchargedForDebug
|
||||||
&& !game.viewEntireMapForDebug
|
&& !game.viewEntireMapForDebug
|
||||||
&& game.simulateUntilTurnForDebug <= 0
|
&& game.simulateUntilTurnForDebug <= 0
|
||||||
&& !game.simulateUntilWin
|
&& !game.simulateUntilWin
|
||||||
&& !game.scenarioDebugSwitch)
|
&& !game.scenarioDebugSwitch
|
||||||
|
&& !game.consoleMode
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's a unit that obsoletes with no upgrade then when it obsoletes
|
// If there's a unit that obsoletes with no upgrade then when it obsoletes
|
||||||
|
Reference in New Issue
Block a user