diff --git a/core/src/main/kotlin/io/github/chrislo27/rhre3/patternstorage/PatternStorage.kt b/core/src/main/kotlin/io/github/chrislo27/rhre3/patternstorage/PatternStorage.kt index 58369576b..08d6fee87 100644 --- a/core/src/main/kotlin/io/github/chrislo27/rhre3/patternstorage/PatternStorage.kt +++ b/core/src/main/kotlin/io/github/chrislo27/rhre3/patternstorage/PatternStorage.kt @@ -39,7 +39,7 @@ object PatternStorage { sort() } - fun persist() { + fun persist(deleteAllOthers: Boolean = false) { val values = patterns.values.toList() values.mapNotNull { pattern -> @@ -65,6 +65,8 @@ object PatternStorage { }.also { arrayNode -> FOLDER.child("list/").apply { mkdirs() }.child("list.json").writeString(JsonHandler.toJson(arrayNode), false, "UTF-8") } + val filenames = values.mapNotNull(StoredPattern::filename) + FOLDER.list().filter { it.name() !in filenames }.forEach { it.delete() } } fun addPattern(pattern: StoredPattern): PatternStorage { diff --git a/core/src/main/kotlin/io/github/chrislo27/rhre3/screen/PatternDeleteScreen.kt b/core/src/main/kotlin/io/github/chrislo27/rhre3/screen/PatternDeleteScreen.kt index 3410935f2..7b45f3ad7 100644 --- a/core/src/main/kotlin/io/github/chrislo27/rhre3/screen/PatternDeleteScreen.kt +++ b/core/src/main/kotlin/io/github/chrislo27/rhre3/screen/PatternDeleteScreen.kt @@ -51,7 +51,7 @@ class PatternDeleteScreen(main: RHRE3Application, val editor: Editor, val patter override fun onLeftClick(xPercent: Float, yPercent: Float) { super.onLeftClick(xPercent, yPercent) - PatternStorage.deletePattern(pattern).persist() + PatternStorage.deletePattern(pattern).persist(deleteAllOthers = true) editor.stage.updateSelected() main.screen = ScreenRegistry["editor"] }