2022-10-02 12:11:06 +02:00
|
|
|
import dev.adamko.gradle.factorio.FactorioModPlugin
|
|
|
|
|
import dev.adamko.gradle.factorio.factorioModAttributes
|
2022-09-18 20:49:32 +02:00
|
|
|
import kafkatorio.extensions.not
|
|
|
|
|
import kafkatorio.tasks.ProcessRunningSpec
|
2022-04-24 21:01:16 +02:00
|
|
|
import org.gradle.kotlin.dsl.support.serviceOf
|
2021-12-01 16:57:46 +01:00
|
|
|
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
|
|
|
|
|
|
|
|
|
plugins {
|
2022-09-18 20:49:32 +02:00
|
|
|
id("kafkatorio.conventions.infra.process-runner")
|
2022-10-02 12:11:06 +02:00
|
|
|
id("dev.adamko.factorio-mod")
|
2021-12-01 16:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-28 17:05:52 +01:00
|
|
|
description = "Start the Factorio game client"
|
|
|
|
|
|
2022-06-23 23:59:48 +02:00
|
|
|
val clientModsDirectory: DirectoryProperty = objects.directoryProperty().apply {
|
|
|
|
|
val modDir = File("""D:\Users\Adam\AppData\Roaming\Factorio\mods""")
|
|
|
|
|
if (modDir.exists()) {
|
|
|
|
|
set(modDir)
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-01 16:57:46 +01:00
|
|
|
val factorioGameId = "427520"
|
2022-06-23 23:59:48 +02:00
|
|
|
val steamExe: RegularFileProperty = objects.fileProperty().apply {
|
|
|
|
|
val steam = File("""C:\Program Files (x86)\Steam\steam.exe""")
|
|
|
|
|
if (steam.exists()) {
|
|
|
|
|
set(steam)
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2022-10-02 12:11:06 +02:00
|
|
|
//val factorioMod: Configuration by configurations.creating {
|
|
|
|
|
// asConsumer()
|
|
|
|
|
// factorioModAttributes(objects)
|
|
|
|
|
//}
|
2021-12-01 16:57:46 +01:00
|
|
|
|
|
|
|
|
dependencies {
|
|
|
|
|
factorioMod(projects.modules.eventsMod)
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-26 14:56:53 +02:00
|
|
|
|
2021-12-01 16:57:46 +01:00
|
|
|
//<editor-fold desc="Mod deployment tasks">
|
2022-06-26 15:45:59 +02:00
|
|
|
val deployModToLocalClient by tasks.registering(Copy::class) {
|
2021-12-01 16:57:46 +01:00
|
|
|
description = "Copy the mod to the Factorio client"
|
2022-10-02 12:11:06 +02:00
|
|
|
group = FactorioModPlugin.TASK_GROUP
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2022-07-05 23:44:23 +02:00
|
|
|
val clientModsDirectory123 = clientModsDirectory
|
|
|
|
|
|
|
|
|
|
onlyIf { clientModsDirectory123.orNull?.asFile?.exists() == true }
|
2022-06-23 23:59:48 +02:00
|
|
|
|
2022-10-18 21:36:22 +02:00
|
|
|
from(configurations.factorioMod.map { it.incoming.artifactView { lenient(true) }.files })
|
2021-12-01 16:57:46 +01:00
|
|
|
into(clientModsDirectory)
|
|
|
|
|
|
|
|
|
|
doLast {
|
|
|
|
|
logger.lifecycle("Copying mod from ${source.files} to $destinationDir")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//</editor-fold>
|
|
|
|
|
|
2022-06-26 14:56:53 +02:00
|
|
|
|
2021-12-01 16:57:46 +01:00
|
|
|
//<editor-fold desc="Factorio client lifecycle tasks">
|
2022-04-24 21:01:16 +02:00
|
|
|
fun ExecOperations.isFactorioRunning(): Spec<Task> = ProcessRunningSpec(this, "factorio.exe")
|
|
|
|
|
|
2021-12-01 16:57:46 +01:00
|
|
|
|
|
|
|
|
val clientLaunch by tasks.registering(Exec::class) {
|
2022-06-26 14:56:53 +02:00
|
|
|
description = "Run local Factorio Steam game client"
|
2022-10-02 12:11:06 +02:00
|
|
|
group = FactorioModPlugin.TASK_GROUP
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2022-07-05 23:44:23 +02:00
|
|
|
val steamExe123 = steamExe
|
|
|
|
|
val clientModsDirectory444 = clientModsDirectory
|
|
|
|
|
|
2022-04-24 21:01:16 +02:00
|
|
|
onlyIf(!serviceOf<ExecOperations>().isFactorioRunning())
|
2022-07-05 23:44:23 +02:00
|
|
|
onlyIf { steamExe123.orNull?.asFile?.exists() == true }
|
|
|
|
|
onlyIf { clientModsDirectory444.orNull?.asFile?.exists() == true }
|
2021-12-01 16:57:46 +01:00
|
|
|
|
2022-06-26 15:45:59 +02:00
|
|
|
dependsOn(deployModToLocalClient)
|
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
|
2022-06-24 00:04:50 +02:00
|
|
|
""" ${steamExe.asFile.orNull?.canonicalPath} -applaunch $factorioGameId --mp-connect localhost --mod-directory ${clientModsDirectory.asFile.orNull?.canonicalPath} """
|
2021-12-01 16:57:46 +01:00
|
|
|
)
|
|
|
|
|
doFirst { logger.lifecycle("Launching factorio.exe") }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val clientKill by tasks.registering(Exec::class) {
|
2022-06-26 14:56:53 +02:00
|
|
|
description = "Stop the local Factorio Steam game client"
|
2022-10-02 12:11:06 +02:00
|
|
|
group = FactorioModPlugin.TASK_GROUP
|
2022-04-24 21:01:16 +02:00
|
|
|
|
|
|
|
|
onlyIf(serviceOf<ExecOperations>().isFactorioRunning())
|
|
|
|
|
|
2021-12-01 16:57:46 +01:00
|
|
|
commandLine = parseSpaceSeparatedArgs(""" taskkill /im factorio.exe """)
|
|
|
|
|
doFirst { logger.lifecycle("Killing factorio.exe") }
|
|
|
|
|
}
|
|
|
|
|
//</editor-fold>
|
|
|
|
|
|
2022-06-26 14:56:53 +02:00
|
|
|
|
2022-10-02 12:11:06 +02:00
|
|
|
tasks.register(FactorioModPlugin.PUBLISH_MOD_LOCAL_TASK_NAME) {
|
|
|
|
|
group = FactorioModPlugin.TASK_GROUP
|
2022-06-26 15:45:59 +02:00
|
|
|
dependsOn(deployModToLocalClient)
|
2022-06-26 14:56:53 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-01 16:57:46 +01:00
|
|
|
|
|
|
|
|
tasks.processRun {
|
|
|
|
|
dependsOn(
|
2022-06-26 15:45:59 +02:00
|
|
|
deployModToLocalClient,
|
2021-12-01 16:57:46 +01:00
|
|
|
clientLaunch,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tasks.processKill {
|
|
|
|
|
dependsOn(clientKill)
|
|
|
|
|
}
|
2022-09-13 17:56:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
val runFactorioClient by tasks.registering {
|
|
|
|
|
group = rootProject.name
|
|
|
|
|
|
|
|
|
|
dependsOn(tasks.processRun)
|
|
|
|
|
}
|