Skip to content

Commit

Permalink
extract loadMods from RunClient and RunServer
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Dec 25, 2023
1 parent 294d19f commit 3962201
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 37 deletions.
4 changes: 2 additions & 2 deletions TestProjectGroovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ dependencies {

mindustry {
dependency {
mindustry version: latest
mindustry version: "v146"
// mindustryMirror version: latest
arc version: latest
arc version: "v146"
}
modMeta {
name = 'mgpp-groovy'
Expand Down
4 changes: 2 additions & 2 deletions TestProjectKt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ tasks.register<TestOutputTask>("anyTask") {
}
mindustry {
dependency {
mindustry(version = latest)
arc(version = latestTag)
mindustry(version = "v146")
arc(version = "v146")
}
modMeta {
name = "mgpp-kt"
Expand Down
4 changes: 2 additions & 2 deletions main/src/dsl/OS.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.liplum.dsl

enum class OS {
Unknown, Windows, Linux, Mac
Unknown, Windows, Linux, MacOS
}

fun getOs(): OS = (System.getProperty("os.name").lowercase()).let {
when {
it.contains("windows") -> OS.Windows
it.contains("mac os x") || it.contains("darwin") || it.contains("osx") -> OS.Mac
it.contains("mac os x") || it.contains("darwin") || it.contains("osx") -> OS.MacOS
it.contains("linux") -> OS.Linux
else -> OS.Unknown
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ fun resolveDefaultClientDataDir(): File? {
OS.Unknown -> null
OS.Windows -> FileAt(System.getenv("AppData"), "Mindustry")
OS.Linux -> FileAt(System.getenv("XDG_DATA_HOME") ?: System.getenv("HOME"), ".local", "share", "Mindustry")
OS.Mac -> FileAt(System.getenv("HOME"), "Library", "Application Support", "Mindustry")
OS.MacOS -> FileAt(System.getenv("HOME"), "Library", "Application Support", "Mindustry")
}
}
2 changes: 1 addition & 1 deletion main/src/task/DexJar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fun List<File>.platformFindD8(): File? =
when (getOs()) {
OS.Windows -> find { File(it, "d8.bat").exists() }?.run { File(this, "d8.bat") }
OS.Linux -> find { File(it, "d8").exists() }?.run { File(this, "d8") }
OS.Mac -> find { File(it, "d8").exists() }?.run { File(this, "d8") }
OS.MacOS -> find { File(it, "d8").exists() }?.run { File(this, "d8") }
else -> null
}

Expand Down
17 changes: 2 additions & 15 deletions main/src/task/RunClient.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.liplum.mindustry

import io.github.liplum.dsl.*
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.tasks.*

open class RunClient : RunMindustryAbstract() {
Expand All @@ -15,23 +14,11 @@ open class RunClient : RunMindustryAbstract() {
logger.lifecycle("Run client in $dataDir.")
environment[R.env.mindustryDataDir] = dataDir.absoluteFile
workingDir = dataDir
if (dataDir.isDirectory) {
// TODO: Record the mod signature.
// TODO: Don't always delete all.
dataDir.deleteRecursively()
}
dataDir.mkdirs()
val modsFolder = dataDir.resolve("mods")
for (modFile in mods) {
if (modFile.isFile) {
createSymbolicLinkOrCopy(link = modsFolder.resolve(modFile.name), target = modFile)
} else {
logger.error("Mod<$modFile> doesn't exist.")
}
}
loadMods(dataDir.resolve("mods"))
standardInput = System.`in`
args = listOf(gameFile.get().absolutePath) + startupArgs.get()
if (Os.isFamily(Os.FAMILY_MAC)) {
if (getOs() == OS.MacOS) {
// Lwjgl3 application requires it to run on macOS
jvmArgs = (jvmArgs ?: mutableListOf()) + "-XstartOnFirstThread"
}
Expand Down
16 changes: 16 additions & 0 deletions main/src/task/RunMindustryAbstract.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.github.liplum.dsl.*
import io.github.liplum.dsl.fileProp
import io.github.liplum.dsl.stringsProp
import org.gradle.api.tasks.*
import java.io.File

abstract class RunMindustryAbstract : JavaExec() {
val gameFile = project.fileProp()
Expand All @@ -18,4 +19,19 @@ abstract class RunMindustryAbstract : JavaExec() {
init {
mainClass.set("-jar")
}

fun loadMods(modsDir: File) {
modsDir.mkdirs()
if (modsDir.isDirectory) {
// TODO: Record the mod signature, and don't always delete all.
modsDir.deleteRecursively()
}
for (modFile in mods) {
if (modFile.isFile) {
createSymbolicLinkOrCopy(link = modsDir.resolve(modFile.name), target = modFile)
} else {
logger.error("Mod<$modFile> doesn't exist.")
}
}
}
}
15 changes: 1 addition & 14 deletions main/src/task/RunServer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.liplum.mindustry

import io.github.liplum.dsl.createSymbolicLinkOrCopy
import org.gradle.api.tasks.*

open class RunServer : RunMindustryAbstract() {
Expand All @@ -12,20 +11,8 @@ open class RunServer : RunMindustryAbstract() {
override fun exec() {
val dataDir = dataDir.get().resolveDir(this, GameSideType.Server) ?: temporaryDir.resolve(name)
logger.lifecycle("Run server in $dataDir.")
if (dataDir.isDirectory) {
// TODO: Record the mod signature.
// TODO: Don't always delete all.
dataDir.deleteRecursively()
}
dataDir.mkdirs()
val modsFolder = dataDir.resolve("config").resolve("mods")
for (modFile in mods) {
if (modFile.exists()) {
createSymbolicLinkOrCopy(link = modsFolder.resolve(modFile.name), target = modFile)
} else {
logger.error("Mod<$modFile> doesn't exist.")
}
}
loadMods(dataDir.resolve("mods"))
standardInput = System.`in`
args = listOf(gameFile.get().absolutePath) + startupArgs.get()
workingDir = dataDir
Expand Down

0 comments on commit 3962201

Please sign in to comment.