From dceb80afecc26d40f5fcbf9b4f76bf9e52645b46 Mon Sep 17 00:00:00 2001 From: Daan Vanden Bosch Date: Sat, 15 May 2021 17:16:50 +0200 Subject: [PATCH] Fixed sorting bug in hunt optimizer methods tables. Tables were sorted incorrectly after changing method times. --- .../MethodsForEpisodeController.kt | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/web/src/main/kotlin/world/phantasmal/web/huntOptimizer/controllers/MethodsForEpisodeController.kt b/web/src/main/kotlin/world/phantasmal/web/huntOptimizer/controllers/MethodsForEpisodeController.kt index 9ed83f64..3c40b69e 100644 --- a/web/src/main/kotlin/world/phantasmal/web/huntOptimizer/controllers/MethodsForEpisodeController.kt +++ b/web/src/main/kotlin/world/phantasmal/web/huntOptimizer/controllers/MethodsForEpisodeController.kt @@ -57,14 +57,10 @@ class MethodsForEpisodeController( }.toTypedArray() ) - init { - observe(huntMethodStore.methods) { allMethods -> - methods.value = allMethods.filter { it.episode == episode } - } - } + private var sortColumns: List> = emptyList() - override fun sort(sortColumns: List>) { - methods.sortWith { a, b -> + private val comparator: Comparator = + Comparator { a, b -> for (sortColumn in sortColumns) { val cmp = when (sortColumn.column.key) { METHOD_COL_KEY -> @@ -79,12 +75,27 @@ class MethodsForEpisodeController( } if (cmp != 0) { - return@sortWith if (sortColumn.direction == SortDirection.Asc) cmp else -cmp + return@Comparator if (sortColumn.direction == SortDirection.Asc) cmp else -cmp } } 0 } + + init { + // TODO: Use ListCell.sortedWith when this is available. + observe(huntMethodStore.methods) { allMethods -> + methods.value = allMethods + .asSequence() + .filter { it.episode == episode } + .sortedWith(comparator) + .toList() + } + } + + override fun sort(sortColumns: List>) { + this.sortColumns = sortColumns + methods.sortWith(comparator) } suspend fun setMethodTime(method: HuntMethodModel, time: Duration) {