mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 10:54:19 -04:00
Mod CI step 1 - allow running Unciv as a cli tool for linting etc
This commit is contained in:
parent
767759f42c
commit
41bd1314b9
@ -89,7 +89,7 @@ class Ruleset {
|
|||||||
|
|
||||||
val tileRemovals by lazy { tileImprovements.values.filter { it.name.startsWith(Constants.remove) } }
|
val tileRemovals by lazy { tileImprovements.values.filter { it.name.startsWith(Constants.remove) } }
|
||||||
val nonRoadTileRemovals by lazy { tileRemovals.filter { rulesetImprovement ->
|
val nonRoadTileRemovals by lazy { tileRemovals.filter { rulesetImprovement ->
|
||||||
RoadStatus.values().none { it.removeAction == rulesetImprovement.name } } }
|
RoadStatus.entries.toTypedArray().none { it.removeAction == rulesetImprovement.name } } }
|
||||||
|
|
||||||
/** Contains all happiness levels that moving *from* them, to one *below* them, can change uniques that apply */
|
/** Contains all happiness levels that moving *from* them, to one *below* them, can change uniques that apply */
|
||||||
val allHappinessLevelsThatAffectUniques by lazy {
|
val allHappinessLevelsThatAffectUniques by lazy {
|
||||||
@ -244,7 +244,7 @@ class Ruleset {
|
|||||||
fun allICivilopediaText(): Sequence<ICivilopediaText> =
|
fun allICivilopediaText(): Sequence<ICivilopediaText> =
|
||||||
allRulesetObjects() + events.values + events.values.flatMap { it.choices }
|
allRulesetObjects() + events.values + events.values.flatMap { it.choices }
|
||||||
|
|
||||||
internal fun load(folderHandle: FileHandle) {
|
fun load(folderHandle: FileHandle) {
|
||||||
// Note: Most files are loaded using createHashmap, which sets originRuleset automatically.
|
// Note: Most files are loaded using createHashmap, which sets originRuleset automatically.
|
||||||
// For other files containing IRulesetObject's we'll have to remember to do so manually - e.g. Tech.
|
// For other files containing IRulesetObject's we'll have to remember to do so manually - e.g. Tech.
|
||||||
val modOptionsFile = folderHandle.child("ModOptions.json")
|
val modOptionsFile = folderHandle.child("ModOptions.json")
|
||||||
|
@ -16,7 +16,6 @@ import com.unciv.models.ruleset.nation.Nation
|
|||||||
import com.unciv.models.skins.SkinCache
|
import com.unciv.models.skins.SkinCache
|
||||||
import com.unciv.models.tilesets.TileSetCache
|
import com.unciv.models.tilesets.TileSetCache
|
||||||
import com.unciv.utils.Log
|
import com.unciv.utils.Log
|
||||||
import java.util.LinkedHashSet
|
|
||||||
import kotlin.time.ExperimentalTime
|
import kotlin.time.ExperimentalTime
|
||||||
|
|
||||||
internal object ConsoleLauncher {
|
internal object ConsoleLauncher {
|
||||||
@ -39,7 +38,12 @@ internal object ConsoleLauncher {
|
|||||||
TileSetCache.loadTileSetConfigs(true)
|
TileSetCache.loadTileSetConfigs(true)
|
||||||
SkinCache.loadSkinConfigs(true)
|
SkinCache.loadSkinConfigs(true)
|
||||||
|
|
||||||
val ruleset = RulesetCache[BaseRuleset.Civ_V_GnK.fullName]!!
|
runSimulation()
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExperimentalTime
|
||||||
|
private fun runSimulation() {
|
||||||
|
val ruleset = RulesetCache[BaseRuleset.Civ_V_GnK.fullName]!!
|
||||||
|
|
||||||
ruleset.nations[simulationCiv1] = Nation().apply { name = simulationCiv1 }
|
ruleset.nations[simulationCiv1] = Nation().apply { name = simulationCiv1 }
|
||||||
ruleset.nations[simulationCiv2] = Nation().apply { name = simulationCiv2 }
|
ruleset.nations[simulationCiv2] = Nation().apply { name = simulationCiv2 }
|
||||||
@ -52,7 +56,7 @@ internal object ConsoleLauncher {
|
|||||||
UncivGame.Current.gameInfo = newGame
|
UncivGame.Current.gameInfo = newGame
|
||||||
|
|
||||||
|
|
||||||
val simulation = Simulation(newGame,10,4)
|
val simulation = Simulation(newGame, 10, 4)
|
||||||
|
|
||||||
simulation.start()
|
simulation.start()
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,16 @@ package com.unciv.app.desktop
|
|||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
|
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
|
||||||
import com.unciv.UncivGame
|
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() {
|
class DesktopGame(config: Lwjgl3ApplicationConfiguration) : UncivGame() {
|
||||||
|
|
||||||
private var discordUpdater = DiscordUpdater()
|
private var discordUpdater = DiscordUpdater()
|
||||||
private val windowListener = UncivWindowListener()
|
private val windowListener = UncivWindowListener()
|
||||||
|
var isModCi = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
config.setWindowListener(windowListener)
|
config.setWindowListener(windowListener)
|
||||||
@ -33,6 +38,21 @@ class DesktopGame(config: Lwjgl3ApplicationConfiguration) : UncivGame() {
|
|||||||
discordUpdater.startUpdates()
|
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() {
|
override fun installAudioHooks() {
|
||||||
(Gdx.app as HardenGdxAudio).installHooks(
|
(Gdx.app as HardenGdxAudio).installHooks(
|
||||||
musicController.getAudioLoopCallback(),
|
musicController.getAudioLoopCallback(),
|
||||||
|
@ -37,7 +37,7 @@ internal object DesktopLauncher {
|
|||||||
// For more info see https://github.com/yairm210/Unciv/pull/3202 and https://github.com/LWJGL/lwjgl/issues/119
|
// For more info see https://github.com/yairm210/Unciv/pull/3202 and https://github.com/LWJGL/lwjgl/issues/119
|
||||||
System.setProperty("org.lwjgl.opengl.Display.allowSoftwareOpenGL", "true")
|
System.setProperty("org.lwjgl.opengl.Display.allowSoftwareOpenGL", "true")
|
||||||
|
|
||||||
val isRunFromJAR = DesktopLauncher.javaClass.`package`.specificationVersion != null
|
val isRunFromJAR = true//DesktopLauncher.javaClass.`package`.specificationVersion != null
|
||||||
ImagePacker.packImages(isRunFromJAR)
|
ImagePacker.packImages(isRunFromJAR)
|
||||||
|
|
||||||
val config = Lwjgl3ApplicationConfiguration()
|
val config = Lwjgl3ApplicationConfiguration()
|
||||||
@ -68,8 +68,11 @@ internal object DesktopLauncher {
|
|||||||
UiElementDocsWriter().write()
|
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 extends Lwjgl3Application, and the Lwjgl3Application constructor runs as long as the game runs
|
||||||
HardenGdxAudio(DesktopGame(config), config)
|
HardenGdxAudio(desktopGame, config)
|
||||||
exitProcess(0)
|
exitProcess(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ internal object ImagePacker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scan multiple image folders and generate an atlas for each - if outdated
|
// Scan multiple image folders and generate an atlas for each - if outdated
|
||||||
private fun packImagesPerMod(input: String, output: String, defaultSettings: TexturePacker.Settings) {
|
fun packImagesPerMod(input: String, output: String, defaultSettings: TexturePacker.Settings = getDefaultSettings()) {
|
||||||
val baseDir = File(input)
|
val baseDir = File(input)
|
||||||
if (!File(baseDir, imagesPathBase).exists() && !File(baseDir, existCheck2).exists()) return // So we don't run this from within a fat JAR
|
if (!File(baseDir, imagesPathBase).exists() && !File(baseDir, existCheck2).exists()) return // So we don't run this from within a fat JAR
|
||||||
val atlasList = mutableListOf<String>()
|
val atlasList = mutableListOf<String>()
|
||||||
|
@ -10,3 +10,4 @@ nav:
|
|||||||
- uniques.md
|
- uniques.md
|
||||||
- Type-checking.md
|
- Type-checking.md
|
||||||
- Scenarios.md
|
- Scenarios.md
|
||||||
|
- CI-automation.md
|
||||||
|
7
docs/Modders/CI-automation.md
Normal file
7
docs/Modders/CI-automation.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# AI automation
|
||||||
|
|
||||||
|
Unciv contains built-in capabilities for packing images and autoupdating uniques.
|
||||||
|
You can use Unciv as a command-line tool by running it with the command
|
||||||
|
|
||||||
|
`java -jar <folder location>/Unciv.jar mod-ci`
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user