From 930c17dc5781e65e3234ef6018a85ec2323bd7f0 Mon Sep 17 00:00:00 2001 From: Ayfri Date: Sun, 19 May 2024 07:09:31 +0200 Subject: [PATCH 01/11] fix(functions): Fix output path of functions inside Zip, fix error when 2 functions with same name is generated inside a zip, fix tests. --- kore/src/main/kotlin/io/github/ayfri/kore/DataPack.kt | 9 ++++----- .../kotlin/io/github/ayfri/kore/functions/Function.kt | 2 ++ .../io/github/ayfri/kore/serialization/Datapack.kt | 9 ++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/kore/src/main/kotlin/io/github/ayfri/kore/DataPack.kt b/kore/src/main/kotlin/io/github/ayfri/kore/DataPack.kt index bd604e1a..02ad1de2 100644 --- a/kore/src/main/kotlin/io/github/ayfri/kore/DataPack.kt +++ b/kore/src/main/kotlin/io/github/ayfri/kore/DataPack.kt @@ -158,15 +158,14 @@ class DataPack(val name: String) { zipOutputStream.write(it.toFile().readBytes()) } - functions.forEach { function -> - zipOutputStream.putNextEntry(ZipEntry("data/${function.namespace}/functions/${function.directory}/${function.name}.mcfunction")) + functions.distinctBy(Function::getFinalPath).forEach { function -> + zipOutputStream.putNextEntry(ZipEntry(function.getFinalPath())) zipOutputStream.write(function.lines.joinToString("\n").toByteArray()) zipOutputStream.closeEntry() } - generatedFunctions.forEach { function -> - function.directory = function.directory.removePrefix(configuration.generatedFunctionsFolder) - zipOutputStream.putNextEntry(ZipEntry("data/${function.namespace}/functions/${configuration.generatedFunctionsFolder}/${function.directory}/${function.name}.mcfunction")) + generatedFunctions.distinctBy(Function::getFinalPath).forEach { function -> + zipOutputStream.putNextEntry(ZipEntry(function.getFinalPath())) zipOutputStream.write(function.lines.joinToString("\n").toByteArray()) zipOutputStream.closeEntry() } diff --git a/kore/src/main/kotlin/io/github/ayfri/kore/functions/Function.kt b/kore/src/main/kotlin/io/github/ayfri/kore/functions/Function.kt index b1b6af2c..611caa2d 100644 --- a/kore/src/main/kotlin/io/github/ayfri/kore/functions/Function.kt +++ b/kore/src/main/kotlin/io/github/ayfri/kore/functions/Function.kt @@ -65,6 +65,8 @@ open class Function( lines.add("# $comment") } + fun getFinalPath() = "data/$namespace/functions/${directory.ifNotEmpty { "$it/" }}$name.mcfunction" + fun generate(directory: File) { val file = File(directory, "${this.directory}/$name.mcfunction") file.parentFile.mkdirs() diff --git a/kore/src/test/kotlin/io/github/ayfri/kore/serialization/Datapack.kt b/kore/src/test/kotlin/io/github/ayfri/kore/serialization/Datapack.kt index ad7a5930..27471f75 100644 --- a/kore/src/test/kotlin/io/github/ayfri/kore/serialization/Datapack.kt +++ b/kore/src/test/kotlin/io/github/ayfri/kore/serialization/Datapack.kt @@ -93,17 +93,16 @@ fun zipTests() = testDataPack("zip_tests") { assertFileGenerated("test.zip") val myFunction = dp.functions[0] - assertFileGeneratedInZip("data/${myFunction.namespace}/functions/${myFunction.directory}/${myFunction.name}.mcfunction") + assertFileGeneratedInZip("data/${myFunction.namespace}/functions/${myFunction.name}.mcfunction") val myFunction2 = dp.functions[1] assertFileGeneratedInZip("data/${myFunction2.namespace}/functions/${myFunction2.directory}/${myFunction2.name}.mcfunction") val loadFunction = dp.generatedFunctions[0] - val directory = loadFunction.directory.removePrefix(dp.configuration.generatedFunctionsFolder) - assertFileGeneratedInZip("data/${loadFunction.namespace}/functions/${dp.configuration.generatedFunctionsFolder}/$directory/${loadFunction.name}.mcfunction") + assertFileGeneratedInZip("data/${loadFunction.namespace}/functions/${dp.configuration.generatedFunctionsFolder}/${loadFunction.name}.mcfunction") val tickFunction = dp.generatedFunctions[1] - val tickDirectory = tickFunction.directory.removePrefix(dp.configuration.generatedFunctionsFolder) - assertFileGeneratedInZip("data/${tickFunction.namespace}/functions/${dp.configuration.generatedFunctionsFolder}/$tickDirectory/${tickFunction.name}.mcfunction") + val tickDirectory = tickFunction.directory.removePrefix(dp.configuration.generatedFunctionsFolder + "/") + assertFileGeneratedInZip("data/${tickFunction.namespace}/functions/${dp.configuration.generatedFunctionsFolder}/${tickDirectory}/${tickFunction.name}.mcfunction") generateZip() } From e5ce9d277f98645e372a441614e9af9a5c389cba Mon Sep 17 00:00:00 2001 From: Ayfri Date: Tue, 21 May 2024 21:50:29 +0200 Subject: [PATCH 02/11] chore(dependencies): Update kotlin version to 2.0.0. --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f7e2b84a..54ac372e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ kotlin.code.style=official -kotlin.version=1.9.22 +kotlin.version=2.0.0 minecraft.version=1.20.5-pre1 # Gradle optimization flags org.gradle.caching=true From fcca915c174a782549524e9aa60df5c4dc4228e7 Mon Sep 17 00:00:00 2001 From: Ayfri Date: Tue, 21 May 2024 21:50:47 +0200 Subject: [PATCH 03/11] chore(dependencies): Update jetbrains-compose to 1.6.10, kobweb to version 0.18.0, kotlinx-serialization to 1.7.0-RC, and ktor to 2.3.11. --- libs.versions.toml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libs.versions.toml b/libs.versions.toml index c284646a..91c6731c 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,12 +1,13 @@ [versions] jetbrains-compose = "1.6.0" +jetbrains-compose = "1.6.10" joml = "1.10.5" knbt = "0.11.5" -kobweb = "0.17.0" +kobweb = "0.18.0" kotlin-dotenv = "6.4.1" kotlinpoet = "1.16.0" -kotlinx-serialization = "1.6.3" -ktor = "2.3.5" +kotlinx-serialization = "1.7.0-RC" +ktor = "2.3.11" nexus-publish = "1.3.0" [libraries] From 821497f474033fc1f50ec8a9d5f6327731e51c9a Mon Sep 17 00:00:00 2001 From: Ayfri Date: Tue, 21 May 2024 21:51:36 +0200 Subject: [PATCH 04/11] chore(gradle): Add new Kotlin Compose Plugin. --- settings.gradle.kts | 1 + website/build.gradle.kts | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index f172fd61..b13dfb47 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -13,6 +13,7 @@ pluginManagement { kotlin("jvm") version kotlinVersion kotlin("multiplatform") version kotlinVersion kotlin("plugin.serialization") version kotlinVersion + kotlin("plugin.compose") version kotlinVersion } } diff --git a/website/build.gradle.kts b/website/build.gradle.kts index 2ca4e43e..fa13d812 100644 --- a/website/build.gradle.kts +++ b/website/build.gradle.kts @@ -1,17 +1,18 @@ import com.varabyte.kobweb.gradle.application.util.configAsKobwebApplication import com.varabyte.kobwebx.gradle.markdown.children import com.varabyte.kobwebx.gradle.markdown.yamlStringToKotlinString +import kotlinx.html.link +import kotlinx.html.script +import kotlinx.html.unsafe import org.commonmark.ext.front.matter.YamlFrontMatterBlock import org.commonmark.ext.front.matter.YamlFrontMatterVisitor import org.commonmark.node.AbstractVisitor import org.commonmark.node.CustomBlock import org.commonmark.node.Text -import kotlinx.html.link -import kotlinx.html.script -import kotlinx.html.unsafe plugins { kotlin("multiplatform") + kotlin("plugin.compose") alias(libs.plugins.jetbrains.compose) alias(libs.plugins.kobweb.application) alias(libs.plugins.kobwebx.markdown) @@ -217,7 +218,7 @@ val generateDocSourceTask = task("generateDocSource") { kotlin { configAsKobwebApplication("website") - js(IR) { + js { browser { commonWebpackConfig { devServer?.open = false @@ -228,13 +229,13 @@ kotlin { } sourceSets { - jsMain { + commonMain { kotlin.srcDir(generateDocSourceTask) dependencies { implementation(compose.html.core) - implementation(libs.kobweb.core) implementation(compose.runtime) + implementation(libs.kobweb.core) implementation(libs.kobwebx.markdown) implementation(libs.kobwebx.silk.icons.mdi) } From 5c0105a9f529b62d1d5e2d05510967e3ed13d4b9 Mon Sep 17 00:00:00 2001 From: Ayfri Date: Tue, 21 May 2024 21:52:03 +0200 Subject: [PATCH 05/11] chore(buildSrc): Update gradle kotlin DSL accessor imports. --- buildSrc/src/main/kotlin/utils.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/utils.kt b/buildSrc/src/main/kotlin/utils.kt index 89370ef2..c3e5a2d3 100644 --- a/buildSrc/src/main/kotlin/utils.kt +++ b/buildSrc/src/main/kotlin/utils.kt @@ -1,4 +1,4 @@ -import gradle.kotlin.dsl.accessors._adc73c88e0a124c97e28fdd97139246a.ext +import gradle.kotlin.dsl.accessors._59ba98f56c77a2c46552bf0ab3713b77.ext import org.gradle.api.Project import org.gradle.kotlin.dsl.extra From 1bb71aef69c30653acd5c250a86186ce5ed627ab Mon Sep 17 00:00:00 2001 From: Ayfri Date: Tue, 21 May 2024 21:53:06 +0200 Subject: [PATCH 06/11] chore(dependencies): Update jetbrains-compose to version 1.6.10. --- libs.versions.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/libs.versions.toml b/libs.versions.toml index 91c6731c..7085be7b 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,5 +1,4 @@ [versions] -jetbrains-compose = "1.6.0" jetbrains-compose = "1.6.10" joml = "1.10.5" knbt = "0.11.5" From c6ca1f5009a97f2ff30f19cdd13add523f6b5aa6 Mon Sep 17 00:00:00 2001 From: Ayfri Date: Tue, 21 May 2024 22:48:12 +0200 Subject: [PATCH 07/11] refactor(assertions): Use `normalize().absolute()` for file path resolution in assertFileGenerated method. --- .../test/kotlin/io/github/ayfri/kore/assertions/assertions.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kore/src/test/kotlin/io/github/ayfri/kore/assertions/assertions.kt b/kore/src/test/kotlin/io/github/ayfri/kore/assertions/assertions.kt index fe8c021e..f739c9af 100644 --- a/kore/src/test/kotlin/io/github/ayfri/kore/assertions/assertions.kt +++ b/kore/src/test/kotlin/io/github/ayfri/kore/assertions/assertions.kt @@ -10,6 +10,7 @@ import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.Json import org.intellij.lang.annotations.Language import java.util.zip.ZipInputStream +import kotlin.io.path.absolute import kotlin.io.path.absolutePathString import kotlin.io.path.exists @@ -43,7 +44,7 @@ infix fun Generator.assertsIs(@Language("json") expected: String) { } fun TestDataPack.assertFileGenerated(path: String) { - val file = dp.path.resolve(path) + val file = dp.path.resolve(path).normalize().absolute() callAfterGeneration { if (!file.exists()) { error("File for datapack '${dp.name}' at '${file.absolutePathString()}' was not found.") From eefe6ff71015851c2a67bf2e9791774b52022254 Mon Sep 17 00:00:00 2001 From: Ayfri Date: Tue, 21 May 2024 22:48:54 +0200 Subject: [PATCH 08/11] fix(tests): Fix incorrect name of file to try in a test. --- .../test/kotlin/io/github/ayfri/kore/serialization/Datapack.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kore/src/test/kotlin/io/github/ayfri/kore/serialization/Datapack.kt b/kore/src/test/kotlin/io/github/ayfri/kore/serialization/Datapack.kt index 27471f75..5ec8969c 100644 --- a/kore/src/test/kotlin/io/github/ayfri/kore/serialization/Datapack.kt +++ b/kore/src/test/kotlin/io/github/ayfri/kore/serialization/Datapack.kt @@ -90,7 +90,7 @@ fun zipTests() = testDataPack("zip_tests") { say("Hello, tick!") } }.apply { - assertFileGenerated("test.zip") + assertFileGenerated("zip_tests.zip") val myFunction = dp.functions[0] assertFileGeneratedInZip("data/${myFunction.namespace}/functions/${myFunction.name}.mcfunction") From 72bd53905dea9893b683d117e8d7fb40090b2d30 Mon Sep 17 00:00:00 2001 From: Ayfri Date: Tue, 21 May 2024 23:09:33 +0200 Subject: [PATCH 09/11] refactor(serializers): Adjust how lists are serialized in Predicate and ItemModifier. --- .../ayfri/kore/features/itemmodifiers/ItemModifier.kt | 9 +++++++-- .../github/ayfri/kore/features/predicates/Predicate.kt | 5 +++-- .../ayfri/kore/serializers/InlinableListSerializer.kt | 3 +-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/kore/src/main/kotlin/io/github/ayfri/kore/features/itemmodifiers/ItemModifier.kt b/kore/src/main/kotlin/io/github/ayfri/kore/features/itemmodifiers/ItemModifier.kt index 257abca9..91463f08 100644 --- a/kore/src/main/kotlin/io/github/ayfri/kore/features/itemmodifiers/ItemModifier.kt +++ b/kore/src/main/kotlin/io/github/ayfri/kore/features/itemmodifiers/ItemModifier.kt @@ -5,10 +5,14 @@ import io.github.ayfri.kore.Generator import io.github.ayfri.kore.arguments.types.resources.ItemModifierArgument import io.github.ayfri.kore.features.itemmodifiers.functions.ItemFunction import io.github.ayfri.kore.serializers.InlinableList -import kotlinx.serialization.* +import io.github.ayfri.kore.serializers.inlinableListSerializer +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient import kotlinx.serialization.descriptors.buildClassSerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.serializer typealias ItemModifierAsList = @Serializable(with = ItemModifier.Companion.ItemModifierAsListSerializer::class) ItemModifier @@ -18,7 +22,8 @@ data class ItemModifier( override var fileName: String = "item_modifier", var modifiers: InlinableList = emptyList(), ) : Generator("item_modifier") { - override fun generateJson(dataPack: DataPack) = dataPack.jsonEncoder.encodeToString(modifiers) + override fun generateJson(dataPack: DataPack) = + dataPack.jsonEncoder.encodeToString(inlinableListSerializer(ItemFunction.serializer()), modifiers) companion object { object ItemModifierAsListSerializer : KSerializer { diff --git a/kore/src/main/kotlin/io/github/ayfri/kore/features/predicates/Predicate.kt b/kore/src/main/kotlin/io/github/ayfri/kore/features/predicates/Predicate.kt index ee7c7d78..09782953 100644 --- a/kore/src/main/kotlin/io/github/ayfri/kore/features/predicates/Predicate.kt +++ b/kore/src/main/kotlin/io/github/ayfri/kore/features/predicates/Predicate.kt @@ -5,11 +5,11 @@ import io.github.ayfri.kore.Generator import io.github.ayfri.kore.arguments.types.resources.PredicateArgument import io.github.ayfri.kore.features.predicates.conditions.PredicateCondition import io.github.ayfri.kore.serializers.InlinableList +import io.github.ayfri.kore.serializers.inlinableListSerializer import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.descriptors.buildClassSerialDescriptor -import kotlinx.serialization.encodeToString import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.serializer @@ -20,7 +20,8 @@ data class Predicate( override var fileName: String = "predicate", var predicateConditions: InlinableList = emptyList(), ) : Generator("predicates") { - override fun generateJson(dataPack: DataPack) = dataPack.jsonEncoder.encodeToString(predicateConditions) + override fun generateJson(dataPack: DataPack) = + dataPack.jsonEncoder.encodeToString(inlinableListSerializer(PredicateCondition.serializer()), predicateConditions) companion object { object PredicateAsListSerializer : KSerializer by serializer() { diff --git a/kore/src/main/kotlin/io/github/ayfri/kore/serializers/InlinableListSerializer.kt b/kore/src/main/kotlin/io/github/ayfri/kore/serializers/InlinableListSerializer.kt index df1961f9..d7a59739 100644 --- a/kore/src/main/kotlin/io/github/ayfri/kore/serializers/InlinableListSerializer.kt +++ b/kore/src/main/kotlin/io/github/ayfri/kore/serializers/InlinableListSerializer.kt @@ -6,7 +6,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import kotlinx.serialization.json.JsonElement typealias InlinableList = @Serializable(with = InlinableListSerializer::class) List @@ -14,7 +13,7 @@ fun inlinableListSerializer(kSerializer: KSerializer): KSerializer(private val kSerializer: KSerializer) : KSerializer> { - override val descriptor = ListSerializer(JsonElement.serializer()).descriptor + override val descriptor = ListSerializer(kSerializer).descriptor override fun deserialize(decoder: Decoder) = error("List of ${kSerializer.descriptor.serialName} cannot be deserialized") From d0232d05e8b67e5684c4264cecbcc992de6b616d Mon Sep 17 00:00:00 2001 From: Ayfri Date: Wed, 22 May 2024 23:17:01 +0200 Subject: [PATCH 10/11] refactor(test): Update the minecraftSaveTestPath to have a default value. --- kore/src/test/kotlin/io/github/ayfri/kore/Main.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kore/src/test/kotlin/io/github/ayfri/kore/Main.kt b/kore/src/test/kotlin/io/github/ayfri/kore/Main.kt index 52428e09..42b8d921 100644 --- a/kore/src/test/kotlin/io/github/ayfri/kore/Main.kt +++ b/kore/src/test/kotlin/io/github/ayfri/kore/Main.kt @@ -12,7 +12,7 @@ import io.github.cdimascio.dotenv.dotenv import kotlin.io.path.Path val configuration = dotenv() -val minecraftSaveTestPath = Path(configuration["TEST_FOLDER"]) +val minecraftSaveTestPath = Path(configuration["TEST_FOLDER", "out"]) fun DataPack.setTestPath() { path = minecraftSaveTestPath From 2c6af7b088371103264f571e889949e03b85a80f Mon Sep 17 00:00:00 2001 From: Ayfri Date: Wed, 22 May 2024 23:50:49 +0200 Subject: [PATCH 11/11] refactor(code): Replace usages of IntOrIntNumberProvidersRange with IntOrNumberProvidersRange. --- .../features/itemmodifiers/functions/LimitCount.kt | 6 +++--- .../providers/IntOrIntNumberProvidersRange.kt | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kore/src/main/kotlin/io/github/ayfri/kore/features/itemmodifiers/functions/LimitCount.kt b/kore/src/main/kotlin/io/github/ayfri/kore/features/itemmodifiers/functions/LimitCount.kt index 2c5ef2aa..6f497a44 100644 --- a/kore/src/main/kotlin/io/github/ayfri/kore/features/itemmodifiers/functions/LimitCount.kt +++ b/kore/src/main/kotlin/io/github/ayfri/kore/features/itemmodifiers/functions/LimitCount.kt @@ -2,7 +2,7 @@ package io.github.ayfri.kore.features.itemmodifiers.functions import io.github.ayfri.kore.features.itemmodifiers.ItemModifier import io.github.ayfri.kore.features.predicates.PredicateAsList -import io.github.ayfri.kore.features.predicates.providers.IntOrIntNumberProvidersRange +import io.github.ayfri.kore.features.predicates.providers.IntOrNumberProvidersRange import io.github.ayfri.kore.features.predicates.providers.int import io.github.ayfri.kore.features.predicates.providers.intRange import kotlinx.serialization.Serializable @@ -10,10 +10,10 @@ import kotlinx.serialization.Serializable @Serializable data class LimitCount( override var conditions: PredicateAsList? = null, - val limit: IntOrIntNumberProvidersRange, + val limit: IntOrNumberProvidersRange, ) : ItemFunction() -fun ItemModifier.limitCount(limit: IntOrIntNumberProvidersRange, block: LimitCount.() -> Unit = {}) { +fun ItemModifier.limitCount(limit: IntOrNumberProvidersRange, block: LimitCount.() -> Unit = {}) { modifiers += LimitCount(limit = limit).apply(block) } diff --git a/kore/src/main/kotlin/io/github/ayfri/kore/features/predicates/providers/IntOrIntNumberProvidersRange.kt b/kore/src/main/kotlin/io/github/ayfri/kore/features/predicates/providers/IntOrIntNumberProvidersRange.kt index ec0318ae..28ac8bdc 100644 --- a/kore/src/main/kotlin/io/github/ayfri/kore/features/predicates/providers/IntOrIntNumberProvidersRange.kt +++ b/kore/src/main/kotlin/io/github/ayfri/kore/features/predicates/providers/IntOrIntNumberProvidersRange.kt @@ -29,10 +29,10 @@ class IntOrIntNumberProvidersRange internal constructor( } } -fun int(value: Int) = IntOrIntNumberProvidersRange(value) -fun providersRange(min: NumberProvider, max: NumberProvider) = IntOrIntNumberProvidersRange(range = min to max) -fun providersRange(min: Float, max: NumberProvider) = IntOrIntNumberProvidersRange(range = constant(min) to max) -fun providersRange(min: NumberProvider, max: Float) = IntOrIntNumberProvidersRange(range = min to constant(max)) -fun intRange(min: Float, max: Float) = IntOrIntNumberProvidersRange(range = constant(min) to constant(max)) +fun int(value: Int) = IntOrNumberProvidersRange(value) +fun providersRange(min: NumberProvider, max: NumberProvider) = IntOrNumberProvidersRange(range = min to max) +fun providersRange(min: Float, max: NumberProvider) = IntOrNumberProvidersRange(range = constant(min) to max) +fun providersRange(min: NumberProvider, max: Float) = IntOrNumberProvidersRange(range = min to constant(max)) +fun intRange(min: Float, max: Float) = IntOrNumberProvidersRange(range = constant(min) to constant(max)) fun intRange(range: ClosedFloatingPointRange) = - IntOrIntNumberProvidersRange(range = constant(range.start) to constant(range.endInclusive)) + IntOrNumberProvidersRange(range = constant(range.start) to constant(range.endInclusive))