From 9935a0562a5318226cb2e0f6e7ee20e0ca82e6b6 Mon Sep 17 00:00:00 2001 From: NichtStudioCode <51272202+NichtStudioCode@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:47:59 +0100 Subject: [PATCH] Improved recipe keys --- .../json/serializer/RecipeDeserializer.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/nova/src/main/kotlin/xyz/xenondevs/nova/serialization/json/serializer/RecipeDeserializer.kt b/nova/src/main/kotlin/xyz/xenondevs/nova/serialization/json/serializer/RecipeDeserializer.kt index 8d5284d0ae..800defca19 100644 --- a/nova/src/main/kotlin/xyz/xenondevs/nova/serialization/json/serializer/RecipeDeserializer.kt +++ b/nova/src/main/kotlin/xyz/xenondevs/nova/serialization/json/serializer/RecipeDeserializer.kt @@ -70,8 +70,22 @@ interface RecipeDeserializer { return ItemUtils.getRecipeChoice(names) } - fun getRecipeKey(file: File): NamespacedKey = - NamespacedKey("nova", "${file.parentFile.name}.${file.nameWithoutExtension}") + /** + * Generates a [NamespacedKey] for a recipe file, assuming that is located under + * `plugins//recipes///.json`, which + * would generate the following key: `://` + */ + fun getRecipeKey(file: File): NamespacedKey { + val relativePathString = file.relativeTo(File("plugins/")).invariantSeparatorsPath + val addonId = relativePathString.substringBefore('/').lowercase() + return NamespacedKey( + addonId, + relativePathString + .substringAfter('/') // Remove the addon id + .substringAfter('/') // remove "recipes" + .substringBeforeLast('.') // remove extension + ) + } }