Skip to content

Commit

Permalink
putDataAt
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Dec 19, 2023
1 parent 5c0b8de commit fc1167b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
8 changes: 6 additions & 2 deletions TestProjectGroovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ runMindustry {
}
addClient("debugging") {
official version: "v146"
useModpack("for debugging")
useModpack "for debugging"
}
addClient("custom data dir") {
official version: "v146"
putDataAt "${buildDir}/customDataDir"
}
addClient {
// anonymous 2
fooClient tag: "v8.0.0", file: "erekir-client.jar"
useModpack(modpack2nd)
useModpack modpack2nd
}
addClient("Old Mindustry") {
official version: "v126"
Expand Down
4 changes: 4 additions & 0 deletions TestProjectKt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ runMindustry {
official(version = "v146")
useModpack(name = "for debugging")
}
addClient("custom data dir") {
official(version = "v146")
putDataAt(file = buildDir.resolve("customDataDir"))
}
addClient("debugging") {
official(version = "v146")
useModpack(name = "for debugging 2")
Expand Down
4 changes: 2 additions & 2 deletions main/src/run/RunMindustry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ open class RunMindustryExtension(
fun addModpack(
name: String,
config: Action<AddModpackSpec>
): Modpack? {
): Modpack {
return addModpack(name) {
config.execute(this)
}
Expand All @@ -248,7 +248,7 @@ open class RunMindustryExtension(
* }
* ```
*/
fun addModpack(config: Action<AddModpackSpec>): Modpack? {
fun addModpack(config: Action<AddModpackSpec>): Modpack {
return addModpack(defaultModpackName, config)
}
}
Expand Down
48 changes: 34 additions & 14 deletions main/src/run/model/GameSide.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,38 @@ abstract class AddGameSideSpec<T : GameSide> {
* ## Default data directory of Mindustry server
* `./config/`
*/
var dataDir: Any?
get() = when (val dir = backend.dataDir) {
is ProjBuildDataDirLoc -> dir.name
is LocalDataDirLoc -> dir.dir
else -> null
}
var dataDir: IDataDirLoc?
get() = backend.dataDir
set(value) {
when (value) {
is File -> backend.dataDir = LocalDataDirLoc(value)
is String -> backend.dataDir = LocalDataDirLoc(File(value))
is IDataDirLoc -> backend.dataDir = value
}
backend.dataDir = value
}

fun putDataAt(props: Map<String, Any>) {
val path = props["path"]
val file = props["file"]
if (path != null) {
putDataAt(path = path.toString())
} else if (file != null) {
putDataAt(file = proj.project.file(file))
} else {
proj.logger.error(
"Neither \"path\" nor \"file\" given in putDataAt(Map<String,Any>)"
)
}
}

fun putDataAt(path: String) {
dataDir = LocalDataDirLoc(File(path))
}

fun putDataAt(file: File) {
dataDir = LocalDataDirLoc(file)
}

fun putDataAt(loc: IDataDirLoc) {
dataDir = loc
}

var modpack: String?
get() = backend.modpack
set(value) {
Expand All @@ -76,6 +95,7 @@ abstract class AddGameSideSpec<T : GameSide> {
name = props["name"] ?: defaultModpackName,
)
}

fun useModpack(name: String) {
modpack = formatValidGradleName(name)
}
Expand Down Expand Up @@ -199,12 +219,12 @@ abstract class AddGameSideSpec<T : GameSide> {
val path = props["path"]
val file = props["file"]
if (path != null) {
LocalGameLoc(File(path as String)).checkAndSet()
localFile(path = path.toString())
} else if (file != null) {
LocalGameLoc(file as File).checkAndSet()
localFile(file = file as File)
} else {
proj.logger.error(
"Neither \"path\" nor \"file\" given in fromLocalDisk(Map<String,Any>)"
"Neither \"path\" nor \"file\" given in localFile(Map<String,Any>)"
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion main/src/run/model/Modpack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class AddModpackSpec(
val path = props["path"]
val file = props["file"]
if (path != null) {
local(path as String)
local(path.toString())
} else if (file != null) {
local(file as File)
} else {
Expand Down

0 comments on commit fc1167b

Please sign in to comment.