From 06baf86add9c4db28fe96d4facae13cf3bcaad43 Mon Sep 17 00:00:00 2001 From: Paint_Ninja Date: Wed, 17 Jul 2024 22:14:20 +0100 Subject: [PATCH 1/3] Remove some Fabric shorthands Shorthands can be nice, but too many can introduce ambiguity and inconsistency --- .../fabric/CustomPropertyBuilder.groovy | 21 ------------------- .../fabric/DependenciesBuilder.groovy | 4 ---- .../fabric/FabricModsDotGroovy.groovy | 9 +++++--- test/fabric/src/main/resources/mods.groovy | 2 -- 4 files changed, 6 insertions(+), 30 deletions(-) delete mode 100644 frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/CustomPropertyBuilder.groovy diff --git a/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/CustomPropertyBuilder.groovy b/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/CustomPropertyBuilder.groovy deleted file mode 100644 index 6a1a1598..00000000 --- a/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/CustomPropertyBuilder.groovy +++ /dev/null @@ -1,21 +0,0 @@ -package org.groovymc.modsdotgroovy.frontend.fabric - -import groovy.transform.CompileDynamic -import groovy.transform.CompileStatic -import groovy.util.logging.Log4j2 -import org.groovymc.modsdotgroovy.core.ModsDotGroovyCore -import org.groovymc.modsdotgroovy.frontend.DslBuilder -import org.groovymc.modsdotgroovy.frontend.PropertyInterceptor - -@CompileStatic -@Log4j2(category = 'MDG - Fabric Frontend') -class CustomPropertyBuilder extends DslBuilder implements PropertyInterceptor { - @CompileDynamic - void property(final String name, final String value) { - this."$name" = value - } - - CustomPropertyBuilder(final ModsDotGroovyCore core) { - super(core) - } -} diff --git a/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/DependenciesBuilder.groovy b/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/DependenciesBuilder.groovy index e9e4ffc9..c5c6b538 100644 --- a/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/DependenciesBuilder.groovy +++ b/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/DependenciesBuilder.groovy @@ -11,10 +11,6 @@ import org.groovymc.modsdotgroovy.frontend.PropertyInterceptor @CompileStatic @Log4j2(category = 'MDG - Fabric Frontend') class DependenciesBuilder extends DslBuilder implements PropertyInterceptor { - void mod(final String modId, def versionRange) { - core.put(modId, versionRange) - } - void mod(@DelegatesTo(value = DependencyBuilder, strategy = Closure.DELEGATE_FIRST) @ClosureParams(value = SimpleType, options = 'org.groovymc.modsdotgroovy.frontend.fabric.DependencyBuilder') final Closure closure) { diff --git a/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/FabricModsDotGroovy.groovy b/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/FabricModsDotGroovy.groovy index 5da44588..0c5a00e9 100644 --- a/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/FabricModsDotGroovy.groovy +++ b/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/FabricModsDotGroovy.groovy @@ -81,6 +81,9 @@ class FabricModsDotGroovy extends ModsDotGroovyFrontend implements PropertyInter @Nullable String accessWidener = null + /**@ + * A shorthand for a single icon file of a given size. Prefer using {@link #icon(Closure)} if you need multiple sizes. + */ void icon(final int size, final String path) { log.debug "icon(int, string)" core.push('icon') @@ -257,12 +260,12 @@ class FabricModsDotGroovy extends ModsDotGroovyFrontend implements PropertyInter * You can add any field you want to add inside custom field. Loader would ignore them. However it's highly recommended * to namespace your fields to avoid conflicts if your fields (names) would be added to the standard specification. */ - void custom(@DelegatesTo(value = CustomPropertyBuilder, strategy = Closure.DELEGATE_FIRST) - @ClosureParams(value = SimpleType, options = 'org.groovymc.modsdotgroovy.frontend.fabric.CustomPropertyBuilder') + void custom(@DelegatesTo(value = SimpleBuilder, strategy = Closure.DELEGATE_FIRST) + @ClosureParams(value = SimpleType, options = 'org.groovymc.modsdotgroovy.frontend.fabric.SimpleBuilder') final Closure closure) { log.debug "custom(closure)" core.push('custom') - final customPropertyBuilder = new CustomPropertyBuilder(core) + final customPropertyBuilder = new SimpleBuilder(core) closure.resolveStrategy = Closure.DELEGATE_FIRST closure.delegate = customPropertyBuilder closure.call(customPropertyBuilder) diff --git a/test/fabric/src/main/resources/mods.groovy b/test/fabric/src/main/resources/mods.groovy index 1ffe1c8f..880377ba 100644 --- a/test/fabric/src/main/resources/mods.groovy +++ b/test/fabric/src/main/resources/mods.groovy @@ -54,8 +54,6 @@ final mdg = FabricModsDotGroovy.make { java = ">=17" it.'fabric-api' = "*" - mod "another-mod", ">=1.5.0" - mod("something-else", v(">0.5") & v('<1.0')) mod { modId = "rats" versionRange = "*" From 2dc62514135d48ca0095650641b5d3aab15a5b96 Mon Sep 17 00:00:00 2001 From: Paint_Ninja Date: Wed, 17 Jul 2024 22:22:10 +0100 Subject: [PATCH 2/3] Add back CustomPropertyBuilder --- .../fabric/CustomPropertyBuilder.groovy | 21 +++++++++++++++++++ .../fabric/FabricModsDotGroovy.groovy | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/CustomPropertyBuilder.groovy diff --git a/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/CustomPropertyBuilder.groovy b/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/CustomPropertyBuilder.groovy new file mode 100644 index 00000000..6a1a1598 --- /dev/null +++ b/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/CustomPropertyBuilder.groovy @@ -0,0 +1,21 @@ +package org.groovymc.modsdotgroovy.frontend.fabric + +import groovy.transform.CompileDynamic +import groovy.transform.CompileStatic +import groovy.util.logging.Log4j2 +import org.groovymc.modsdotgroovy.core.ModsDotGroovyCore +import org.groovymc.modsdotgroovy.frontend.DslBuilder +import org.groovymc.modsdotgroovy.frontend.PropertyInterceptor + +@CompileStatic +@Log4j2(category = 'MDG - Fabric Frontend') +class CustomPropertyBuilder extends DslBuilder implements PropertyInterceptor { + @CompileDynamic + void property(final String name, final String value) { + this."$name" = value + } + + CustomPropertyBuilder(final ModsDotGroovyCore core) { + super(core) + } +} diff --git a/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/FabricModsDotGroovy.groovy b/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/FabricModsDotGroovy.groovy index 0c5a00e9..6695999f 100644 --- a/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/FabricModsDotGroovy.groovy +++ b/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/FabricModsDotGroovy.groovy @@ -260,12 +260,12 @@ class FabricModsDotGroovy extends ModsDotGroovyFrontend implements PropertyInter * You can add any field you want to add inside custom field. Loader would ignore them. However it's highly recommended * to namespace your fields to avoid conflicts if your fields (names) would be added to the standard specification. */ - void custom(@DelegatesTo(value = SimpleBuilder, strategy = Closure.DELEGATE_FIRST) - @ClosureParams(value = SimpleType, options = 'org.groovymc.modsdotgroovy.frontend.fabric.SimpleBuilder') + void custom(@DelegatesTo(value = CustomPropertyBuilder, strategy = Closure.DELEGATE_FIRST) + @ClosureParams(value = SimpleType, options = 'org.groovymc.modsdotgroovy.frontend.fabric.CustomPropertyBuilder') final Closure closure) { log.debug "custom(closure)" core.push('custom') - final customPropertyBuilder = new SimpleBuilder(core) + final customPropertyBuilder = new CustomPropertyBuilder(core) closure.resolveStrategy = Closure.DELEGATE_FIRST closure.delegate = customPropertyBuilder closure.call(customPropertyBuilder) From 857016d7b8d49989dcaee2c41a176020fd076e87 Mon Sep 17 00:00:00 2001 From: Paint_Ninja Date: Wed, 17 Jul 2024 22:24:05 +0100 Subject: [PATCH 3/3] Remove mixin(String, Environment) in favour of the closure method --- .../modsdotgroovy/frontend/fabric/MixinsBuilder.groovy | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/MixinsBuilder.groovy b/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/MixinsBuilder.groovy index e444230f..b29dd0a1 100644 --- a/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/MixinsBuilder.groovy +++ b/frontend-dsl/fabric/src/main/groovy/org/groovymc/modsdotgroovy/frontend/fabric/MixinsBuilder.groovy @@ -12,13 +12,10 @@ import org.groovymc.rootpackagetransformer.RootPackage @Log4j2(category = 'MDG - Fabric Frontend') @RootPackage class MixinsBuilder extends DslBuilder { - void mixin(final String config, final Environment environment = null) { + void mixin(final String config) { log.debug "mixin(config: $config)" core.push('mixin') core.put('config', config) - if (environment !== null) { - core.put('environment', environment) - } core.pop() }