Skip to content

Commit

Permalink
Improved recipe keys
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Dec 13, 2024
1 parent 387b044 commit 9935a05
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,22 @@ interface RecipeDeserializer<T> {
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/<addon name>/recipes/<recipe type namespace>/<recipe type name>/<recipe name>.json`, which
* would generate the following key: `<addon id>:<recipe type namespace>/<recipe type name>/<recipe name>`
*/
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
)
}

}

Expand Down

0 comments on commit 9935a05

Please sign in to comment.