Skip to content

Commit

Permalink
Mod CI - Place before "screen"-oriented logic to run on CI machines
Browse files Browse the repository at this point in the history
  • Loading branch information
yairm210 committed Jul 14, 2024
1 parent 41bd131 commit 6c9575d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
10 changes: 8 additions & 2 deletions core/src/com/unciv/ui/images/ImageGetter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,14 @@ object ImageGetter {
* @return `null` if no match found.
*/
fun findExternalImage(name: String): FileHandle? {
val folders = ruleset.mods.asSequence().map { Gdx.files.local("mods/$it/ExtraImages") } +
sequenceOf(Gdx.files.internal("ExtraImages"))
val folders = try { // For CI mod checker, we can't access "local" files
// since Gdx files are not set up
ruleset.mods.asSequence().map { Gdx.files.local("mods/$it/ExtraImages") } +
sequenceOf(Gdx.files.internal("ExtraImages"))
} catch (e: Exception) {
debug("Error loading mods: $e")
sequenceOf()
}
val extensions = sequenceOf("", ".png", ".jpg")
return folders.flatMap { folder ->
extensions.map { folder.child(name + it) }
Expand Down
20 changes: 0 additions & 20 deletions desktop/src/com/unciv/app/desktop/DesktopGame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ package com.unciv.app.desktop
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.unciv.UncivGame
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.validation.RulesetErrorSeverity
import com.unciv.models.ruleset.validation.RulesetValidator
import kotlin.system.exitProcess

class DesktopGame(config: Lwjgl3ApplicationConfiguration) : UncivGame() {

private var discordUpdater = DiscordUpdater()
private val windowListener = UncivWindowListener()
var isModCi = false

init {
config.setWindowListener(windowListener)
Expand All @@ -38,21 +33,6 @@ class DesktopGame(config: Lwjgl3ApplicationConfiguration) : UncivGame() {
discordUpdater.startUpdates()
}

override fun create() {
// The uniques checker requires the file system to be seet up, which happens after lwjgw initializes it
if (isModCi) {
ImagePacker.packImagesPerMod(".", ".")
val ruleset = Ruleset()
ruleset.folderLocation = Gdx.files.local("jsons")
ruleset.load(ruleset.folderLocation!!)
val errors = RulesetValidator(ruleset).getErrorList(true)
println(errors.getErrorText(true))
exitProcess(if (errors.any { it.errorSeverityToReport == RulesetErrorSeverity.Error }) 1 else 0)
}

super.create()
}

override fun installAudioHooks() {
(Gdx.app as HardenGdxAudio).installHooks(
musicController.getAudioLoopCallback(),
Expand Down
24 changes: 20 additions & 4 deletions desktop/src/com/unciv/app/desktop/DesktopLauncher.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.unciv.app.desktop

import com.badlogic.gdx.Gdx
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.files.FileHandle
import com.badlogic.gdx.graphics.glutils.HdpiMode
Expand All @@ -9,6 +10,9 @@ import com.unciv.logic.files.SETTINGS_FILE_NAME
import com.unciv.logic.files.UncivFiles
import com.unciv.models.metadata.GameSettings.ScreenSize
import com.unciv.models.metadata.GameSettings.WindowState
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.validation.RulesetErrorSeverity
import com.unciv.models.ruleset.validation.RulesetValidator
import com.unciv.ui.components.fonts.Fonts
import com.unciv.ui.screens.basescreen.BaseScreen
import com.unciv.utils.Display
Expand All @@ -20,6 +24,21 @@ internal object DesktopLauncher {
@JvmStatic
fun main(arg: Array<String>) {

// The uniques checker requires the file system to be seet up, which happens after lwjgw initializes it
if (arg.isNotEmpty() && arg[0] == "mod-ci") {
ImagePacker.packImagesPerMod(".", ".")
val ruleset = Ruleset()
ruleset.folderLocation = FileHandle(".")
val jsonsFolder = FileHandle("jsons")
if (jsonsFolder.exists()) {
ruleset.load(jsonsFolder)
}
ruleset.load(FileHandle("jsons"))
val errors = RulesetValidator(ruleset).getErrorList(true)
println(errors.getErrorText(true))
exitProcess(if (errors.any { it.errorSeverityToReport == RulesetErrorSeverity.Error }) 1 else 0)
}

// Setup Desktop logging
Log.backend = DesktopLogBackend()

Expand Down Expand Up @@ -68,11 +87,8 @@ internal object DesktopLauncher {
UiElementDocsWriter().write()
}

val desktopGame = DesktopGame(config)
if (arg.isNotEmpty() && arg[0] == "mod-ci") desktopGame.isModCi = true

// HardenGdxAudio extends Lwjgl3Application, and the Lwjgl3Application constructor runs as long as the game runs
HardenGdxAudio(desktopGame, config)
HardenGdxAudio(DesktopGame(config), config)
exitProcess(0)
}
}

0 comments on commit 6c9575d

Please sign in to comment.