Skip to content

Commit

Permalink
NamedModel and GameSide
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Dec 19, 2023
1 parent c7ffbd5 commit 5c5d922
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
6 changes: 4 additions & 2 deletions main/src/run/model/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Client>() {
) : AddGameSideSpec<Client>() {

override fun official(version: String) {
github(
Expand Down
31 changes: 7 additions & 24 deletions main/src/run/model/Common.kt → main/src/run/model/GameSide.kt
Original file line number Diff line number Diff line change
@@ -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<String>()

/** @see [AddCommonSpec.jvmArgs] */
/** @see [AddGameSideSpec.jvmArgs] */
val jvmArgs = ArrayList<String>()

/** @see [AddClientSpec.dataDir] */
Expand All @@ -40,7 +23,7 @@ open class Common(
var modpack: String? = null
}

abstract class AddCommonSpec<T : Common> {
abstract class AddGameSideSpec<T : GameSide> {
protected abstract val proj: Project
protected abstract val backend: T
val latest: Notation get() = Notation.latest
Expand Down
21 changes: 21 additions & 0 deletions main/src/run/model/Model.kt
Original file line number Diff line number Diff line change
@@ -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,
)

6 changes: 3 additions & 3 deletions main/src/run/model/Modpack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<IMod>()
val fromTaskPath = ArrayList<String>()
fun isEmpty() = mods.isEmpty() && fromTaskPath.isEmpty()
Expand Down
9 changes: 4 additions & 5 deletions main/src/run/model/Server.kt
Original file line number Diff line number Diff line change
@@ -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<Server>() {
) : AddGameSideSpec<Server>() {

override fun official(version: String) {
github(
Expand Down

0 comments on commit 5c5d922

Please sign in to comment.