From 5c5d922e7ccadf821123bfddf57ec0e84323a58b Mon Sep 17 00:00:00 2001 From: Liplum Date: Tue, 19 Dec 2023 21:29:26 +0800 Subject: [PATCH] `NamedModel` and `GameSide` --- main/src/run/model/Client.kt | 6 ++-- main/src/run/model/{Common.kt => GameSide.kt} | 31 +++++-------------- main/src/run/model/Model.kt | 21 +++++++++++++ main/src/run/model/Modpack.kt | 6 ++-- main/src/run/model/Server.kt | 9 +++--- 5 files changed, 39 insertions(+), 34 deletions(-) rename main/src/run/model/{Common.kt => GameSide.kt} (89%) create mode 100644 main/src/run/model/Model.kt diff --git a/main/src/run/model/Client.kt b/main/src/run/model/Client.kt index 3ea923a..1503621 100644 --- a/main/src/run/model/Client.kt +++ b/main/src/run/model/Client.kt @@ -6,12 +6,14 @@ package io.github.liplum.mindustry import org.gradle.api.Project -class Client(name: String, isAnonymous: Boolean) : Common(name, isAnonymous) +class Client( + name: String, isAnonymous: Boolean, +) : GameSide(name, isAnonymous) class AddClientSpec( override val proj: Project, override val backend: Client, -) : AddCommonSpec() { +) : AddGameSideSpec() { override fun official(version: String) { github( diff --git a/main/src/run/model/Common.kt b/main/src/run/model/GameSide.kt similarity index 89% rename from main/src/run/model/Common.kt rename to main/src/run/model/GameSide.kt index 5337ae3..59e932b 100644 --- a/main/src/run/model/Common.kt +++ b/main/src/run/model/GameSide.kt @@ -1,37 +1,20 @@ -@file:JvmMultifileClass -@file:JvmName("ExtensionKt") @file:Suppress("RemoveRedundantBackticks") package io.github.liplum.mindustry import io.github.liplum.dsl.plusAssign import io.github.liplum.mindustry.LocalProperties.local +import io.github.liplum.mindustry.run.model.NamedModel import org.gradle.api.Project -import org.gradle.api.logging.LogLevel import java.io.File -open class Common( - /** - * *Optional* - * An empty String as default. - * It affects gradle task names. - * ``` - * runClient // if it's anonymous - * runClient2 // if second name is still anonymous - * runClientFooClient // if [name] is "FooClient" - * runServer // if it's anonymous - * ``` - */ - val name: String, - /** - * Whether this is anonymous. - */ - val isAnonymous: Boolean, -) { - /** @see [AddCommonSpec.startupArgs] */ +open class GameSide( + name: String, isAnonymous: Boolean +) : NamedModel(name, isAnonymous) { + /** @see [AddGameSideSpec.startupArgs] */ val startupArgs = ArrayList() - /** @see [AddCommonSpec.jvmArgs] */ + /** @see [AddGameSideSpec.jvmArgs] */ val jvmArgs = ArrayList() /** @see [AddClientSpec.dataDir] */ @@ -40,7 +23,7 @@ open class Common( var modpack: String? = null } -abstract class AddCommonSpec { +abstract class AddGameSideSpec { protected abstract val proj: Project protected abstract val backend: T val latest: Notation get() = Notation.latest diff --git a/main/src/run/model/Model.kt b/main/src/run/model/Model.kt new file mode 100644 index 0000000..b4fe350 --- /dev/null +++ b/main/src/run/model/Model.kt @@ -0,0 +1,21 @@ +package io.github.liplum.mindustry.run.model + +open class NamedModel( + /** + * *Optional* + * An empty String as default. + * It affects gradle task names. + * ``` + * runClient // if it's anonymous + * runClient2 // if second name is still anonymous + * runClientFooClient // if [name] is "FooClient" + * runServer // if it's anonymous + * ``` + */ + val name: String, + /** + * Whether this is anonymous. + */ + val isAnonymous: Boolean, +) + diff --git a/main/src/run/model/Modpack.kt b/main/src/run/model/Modpack.kt index 493923c..17b5a08 100644 --- a/main/src/run/model/Modpack.kt +++ b/main/src/run/model/Modpack.kt @@ -2,14 +2,14 @@ package io.github.liplum.mindustry +import io.github.liplum.mindustry.run.model.NamedModel import org.gradle.api.Project import org.gradle.api.logging.LogLevel import java.io.File class Modpack( - val name: String, - val isAnonymous: Boolean, -) { + name: String, isAnonymous: Boolean +) : NamedModel(name, isAnonymous) { val mods = ArrayList() val fromTaskPath = ArrayList() fun isEmpty() = mods.isEmpty() && fromTaskPath.isEmpty() diff --git a/main/src/run/model/Server.kt b/main/src/run/model/Server.kt index 685f5b6..c899d2d 100644 --- a/main/src/run/model/Server.kt +++ b/main/src/run/model/Server.kt @@ -1,18 +1,17 @@ -@file:JvmMultifileClass -@file:JvmName("ExtensionKt") @file:Suppress("RemoveRedundantBackticks") package io.github.liplum.mindustry import org.gradle.api.Project -import org.gradle.api.logging.LogLevel -class Server(name: String, isAnonymous: Boolean) : Common(name, isAnonymous) +class Server( + name: String, isAnonymous: Boolean, +) : GameSide(name, isAnonymous) class AddServerSpec( override val proj: Project, override val backend: Server -) : AddCommonSpec() { +) : AddGameSideSpec() { override fun official(version: String) { github(