Skip to content

Commit

Permalink
includeMyMod
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Dec 20, 2023
1 parent 3b74836 commit 91abb6f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 58 deletions.
43 changes: 0 additions & 43 deletions main/src/Anotations.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.github.liplum.mindustry

import org.gradle.api.Project

/**
* It indicates this property will inherit value from its parent project by default.
*/
Expand All @@ -11,44 +9,3 @@ import org.gradle.api.Project
)
@MustBeDocumented
annotation class InheritFromParent
/**
* It represents the default value of this property.
*/
@Target(
AnnotationTarget.FIELD,
AnnotationTarget.PROPERTY
)
@MustBeDocumented
annotation class DefaultValue(
val default: String,
)
/**
* It indicates this property corresponds to a key in `local.properties` file.
*/
@Target(
AnnotationTarget.FIELD,
AnnotationTarget.PROPERTY
)
annotation class LocalProperty(
/**
* The key in `local.properties` file
*/
val key: String,
)
/**
* It indicates this property will read default value from [Project.getProperties]
*/
@Target(
AnnotationTarget.FIELD,
AnnotationTarget.PROPERTY
)
annotation class PropertyAsDefault(
/**
* The key in [Project.getProperties]
*/
val key: String,
/**
* If the key doesn't exist, this value will be truly default.
*/
val default: String,
)
2 changes: 0 additions & 2 deletions main/src/mindustry/model/Dependency.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class DependencySpec(
* DO NOT trust this behavior, it may change later.
*/
@InheritFromParent
@DefaultValue("on \"v135\"")
val arcDependency = target.prop<IDependency>().apply {
convention(ArcDependency())
}
Expand All @@ -62,7 +61,6 @@ class DependencySpec(
* Default: official "v135"
*/
@InheritFromParent
@DefaultValue("on \"v135\"")
val mindustryDependency = target.prop<IDependency>().apply {
convention(MindustryDependency())
}
Expand Down
4 changes: 3 additions & 1 deletion main/src/plugin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class MindustryPlugin : Plugin<Project> {
parent?.let {
if (it.plugins.hasPlugin<MindustryPlugin>()) {
val parentEx = it.extensions.getOrCreate<MindustryExtension>(R.x.mindustry)
val parentRun = it.extensions.getOrCreate<RunMindustryExtension>(R.x.runMindustry)
ex._dependency.mindustryDependency.set(parentEx._dependency.mindustryDependency)
ex._dependency.arcDependency.set(parentEx._dependency.arcDependency)
run._includeMyMod.set(parentRun._includeMyMod)
}
}
// Register this for dynamically configure tasks without class reference in groovy.
Expand All @@ -53,7 +55,7 @@ class MindustryPlugin : Plugin<Project> {
deployX._version.convention(provider {
ex._modMeta.get().version
})
plugins.apply<MindustryAppPlugin>()
plugins.apply<MindustryRunPlugin>()
GroovyBridge.attach(target)
}
}
Expand Down
26 changes: 15 additions & 11 deletions main/src/plugin/App.kt → main/src/plugin/Run.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.gradle.api.plugins.JavaPlugin
/**
* For downloading and running game.
*/
class MindustryAppPlugin : Plugin<Project> {
class MindustryRunPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.tasks.register<CleanMindustrySharedCache>(R.task.cleanMindustrySharedCache) {
group = BasePlugin.BUILD_GROUP
Expand Down Expand Up @@ -59,11 +59,13 @@ class MindustryAppPlugin : Plugin<Project> {
dependsOn(resolveModpackTask)
mods.from(resolveModpackTask)
}
if (proj.plugins.hasPlugin<MindustryJavaPlugin>()) {
mods.from(proj.tasks.getByPath(JavaPlugin.JAR_TASK_NAME))
}
if (proj.plugins.hasPlugin<MindustryJsonPlugin>()) {
mods.from(proj.tasks.getByPath(R.task.zipMod))
if (x.includeMyMod) {
if (proj.plugins.hasPlugin<MindustryJavaPlugin>()) {
mods.from(proj.tasks.getByPath(JavaPlugin.JAR_TASK_NAME))
}
if (proj.plugins.hasPlugin<MindustryJsonPlugin>()) {
mods.from(proj.tasks.getByPath(R.task.zipMod))
}
}
}
}
Expand All @@ -90,11 +92,13 @@ class MindustryAppPlugin : Plugin<Project> {
dependsOn(resolveModpackTask)
mods.from(resolveModpackTask)
}
if (proj.plugins.hasPlugin<MindustryJavaPlugin>()) {
mods.from(proj.tasks.getByPath(JavaPlugin.JAR_TASK_NAME))
}
if (proj.plugins.hasPlugin<MindustryJsonPlugin>()) {
mods.from(proj.tasks.getByPath(R.task.zipMod))
if (x.includeMyMod) {
if (proj.plugins.hasPlugin<MindustryJavaPlugin>()) {
mods.from(proj.tasks.getByPath(JavaPlugin.JAR_TASK_NAME))
}
if (proj.plugins.hasPlugin<MindustryJsonPlugin>()) {
mods.from(proj.tasks.getByPath(R.task.zipMod))
}
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion main/src/run/RunMindustry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

package io.github.liplum.mindustry

import io.github.liplum.dsl.prop
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.JavaPlugin

/**
* Retrieves the `runMindustry`: [RunMindustryExtension] extension.
Expand All @@ -30,6 +32,22 @@ open class RunMindustryExtension(
val clients = ArrayList<Client>()
val servers = ArrayList<Server>()
val modpacks = ArrayList<Modpack>()
val _includeMyMod = proj.prop<Boolean>().apply {
convention(true)
}

/**
* Whether to include the mod that this project output in [R.task.zipMod] and [JavaPlugin.JAR_TASK_NAME].
* `true` by default.
*
* TODO: maybe configurable for each client/server?
*/
@InheritFromParent
var includeMyMod: Boolean
get() = _includeMyMod.getOrElse(true)
set(value) {
_includeMyMod.set(value)
}

/**
* ### Kotlin DSL
Expand All @@ -38,7 +56,7 @@ open class RunMindustryExtension(
* official(version="v141")
* }
* addClient("my name") {
* be latest
* be(latest)
* }
* addClient {
* github(
Expand Down

0 comments on commit 91abb6f

Please sign in to comment.