2021-12-01 18:12:34 +01:00
|
|
|
import dev.adamko.kafkatorio.gradle.asConsumer
|
|
|
|
|
import dev.adamko.kafkatorio.gradle.factorioModAttributes
|
2021-12-01 18:31:18 +01:00
|
|
|
import dev.adamko.kafkatorio.gradle.isProcessRunning
|
|
|
|
|
import dev.adamko.kafkatorio.gradle.not
|
2021-12-01 16:57:46 +01:00
|
|
|
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
|
|
|
|
|
|
|
|
|
plugins {
|
2021-12-02 00:54:15 +01:00
|
|
|
id("dev.adamko.kafkatorio.infra.process-runner")
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-28 17:05:52 +01:00
|
|
|
description = "Start the Factorio game client"
|
|
|
|
|
|
2021-12-01 16:57:46 +01:00
|
|
|
val clientModsDirectory = file("""D:\Users\Adam\AppData\Roaming\Factorio\mods""")
|
|
|
|
|
val factorioGameId = "427520"
|
|
|
|
|
val steamExe = """C:\Program Files (x86)\Steam\steam.exe"""
|
|
|
|
|
|
|
|
|
|
val factorioMod: Configuration by configurations.creating {
|
|
|
|
|
asConsumer()
|
|
|
|
|
factorioModAttributes(objects)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dependencies {
|
|
|
|
|
factorioMod(projects.modules.eventsMod)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<editor-fold desc="Mod deployment tasks">
|
|
|
|
|
val deployModToClient by tasks.registering(Copy::class) {
|
|
|
|
|
description = "Copy the mod to the Factorio client"
|
|
|
|
|
group = project.name
|
|
|
|
|
|
|
|
|
|
from(factorioMod)
|
|
|
|
|
into(clientModsDirectory)
|
|
|
|
|
|
|
|
|
|
doLast {
|
|
|
|
|
logger.lifecycle("Copying mod from ${source.files} to $destinationDir")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//</editor-fold>
|
|
|
|
|
|
|
|
|
|
//<editor-fold desc="Factorio client lifecycle tasks">
|
|
|
|
|
fun isFactorioRunning(): Spec<Task> = isProcessRunning("factorio.exe")
|
|
|
|
|
|
|
|
|
|
val clientLaunch by tasks.registering(Exec::class) {
|
|
|
|
|
description = "Run Factorio Steam game client"
|
|
|
|
|
group = project.name
|
|
|
|
|
|
|
|
|
|
onlyIf(!isFactorioRunning())
|
|
|
|
|
|
|
|
|
|
dependsOn(deployModToClient)
|
2021-12-03 09:04:18 +01:00
|
|
|
mustRunAfter(clientKill, ":modules:infra-factorio-server:processRun")
|
2021-12-01 16:57:46 +01:00
|
|
|
|
|
|
|
|
commandLine = parseSpaceSeparatedArgs(
|
|
|
|
|
// """explorer "steam://rungameid/$factorioGameId// --mp-connect localhost/" """ // not working
|
|
|
|
|
// """explorer "steam://run/$factorioGameId//--mp-connect localhost/" """ // works! But has annoying pop-up
|
2021-12-01 18:31:18 +01:00
|
|
|
""" $steamExe -applaunch $factorioGameId --mp-connect localhost --mod-directory $clientModsDirectory """
|
2021-12-01 16:57:46 +01:00
|
|
|
)
|
|
|
|
|
doFirst { logger.lifecycle("Launching factorio.exe") }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val clientKill by tasks.registering(Exec::class) {
|
|
|
|
|
description = "Run Factorio Steam game client"
|
|
|
|
|
group = project.name
|
|
|
|
|
onlyIf(isFactorioRunning())
|
|
|
|
|
commandLine = parseSpaceSeparatedArgs(""" taskkill /im factorio.exe """)
|
|
|
|
|
doFirst { logger.lifecycle("Killing factorio.exe") }
|
|
|
|
|
}
|
|
|
|
|
//</editor-fold>
|
|
|
|
|
|
|
|
|
|
tasks.build { dependsOn(deployModToClient) }
|
|
|
|
|
|
|
|
|
|
tasks.processRun {
|
|
|
|
|
dependsOn(
|
|
|
|
|
deployModToClient,
|
|
|
|
|
clientLaunch,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tasks.processKill {
|
|
|
|
|
dependsOn(clientKill)
|
|
|
|
|
}
|