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 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 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/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/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/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/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)) 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/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") 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 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.") 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..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,20 +90,19 @@ 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.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() } diff --git a/libs.versions.toml b/libs.versions.toml index c284646a..7085be7b 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,12 +1,12 @@ [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] 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) }