Skip to content

Commit

Permalink
Sort building levels recents by regular, then roof
Browse files Browse the repository at this point in the history
The new building levels recent values is great. However, I've found that
the vast majority of the buildings in the areas I map are 4 values (1|0,
1|1, 2|0, and 2|1), so my recent values seldom change. As a result, a
stabler sort order is much easier for me to scan and find the entry I'm
looking for than the current FIFO queue, where they constantly re-order.

They are still added and removed in the same order; only the display
order is changed. So it has the drawback that you can't be precisely
sure which entry will disappear, after you add a new answer. In
practice, I think it doesn't matter that much.

Originally I tried sorting by total levels first, but when testing, I
found it harder to parse "1|1, 2|0, 1|2, 2|1" than "1|1, 1|2, 2|0, 2|1".

Unfortunately, the compiler can't figure out the type of `thenBy`
without the annotation.
  • Loading branch information
smichel17 committed Aug 4, 2021
1 parent 7019275 commit c51ffd8
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class AddBuildingLevelsForm : AbstractQuestFormAnswerFragment<BuildingLevelsAnsw
private val roofLevels get() = roofLevelsInput?.text?.toString().orEmpty().trim()

private val lastPickedAnswers by lazy {
favs.get(javaClass.simpleName).map { it.toBuildingLevelAnswer() }
favs.get(javaClass.simpleName).map { it.toBuildingLevelAnswer() }.sortedWith(
compareBy<BuildingLevelsAnswer> { it.levels }.thenBy { it.roofLevels }
)
}

@Inject internal lateinit var favs: LastPickedValuesStore<String>
Expand Down

0 comments on commit c51ffd8

Please sign in to comment.