From 21fadf13df106bfa76c8e9a2e735ea346aba8cba Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 12 Mar 2024 18:05:10 +0100 Subject: Technical Detail: code cleanup in LaneSwitchUtils.isBoundaryPlot (#1143) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/garden/farming/LaneSwitchUtils.kt | 37 ++++++++++------------ 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/LaneSwitchUtils.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/LaneSwitchUtils.kt index 43926f096..aab0ff4ff 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/LaneSwitchUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/LaneSwitchUtils.kt @@ -67,38 +67,33 @@ object LaneSwitchUtils { } private fun isBoundaryPlot(plotIndex: Int, direction: Direction, value: Value): Boolean { - if (direction == Direction.WEST_EAST) { - val isNextNewRow: Boolean - val isNextUnlocked: Boolean - val isNextBarn: Boolean + return if (direction == Direction.WEST_EAST) { if (value == Value.MIN) { if (plotIndex - 1 == -1) return true // check if next plot is out of bounds //Check if the next plot's border is 240 and therefore in the previous row - isNextNewRow = GardenPlotAPI.plots[plotIndex - 1].box.maxX.absoluteValue.round(0) == 240.0 - isNextUnlocked = GardenPlotAPI.plots[plotIndex - 1].unlocked - isNextBarn = GardenPlotAPI.plots[plotIndex - 1].isBarn() + val isNextNewRow = GardenPlotAPI.plots[plotIndex - 1].box.maxX.absoluteValue.round(0) == 240.0 + val isNextUnlocked = GardenPlotAPI.plots[plotIndex - 1].unlocked + val isNextBarn = GardenPlotAPI.plots[plotIndex - 1].isBarn() + isNextNewRow || !isNextUnlocked || isNextBarn } else { if (plotIndex + 1 == 25) return true // check if next plot is out of bounds - isNextNewRow = (plotIndex + 1) % 5 == 0 - isNextUnlocked = GardenPlotAPI.plots[plotIndex + 1].unlocked - isNextBarn = GardenPlotAPI.plots[plotIndex + 1].isBarn() + val isNextNewRow = (plotIndex + 1) % 5 == 0 + val isNextUnlocked = GardenPlotAPI.plots[plotIndex + 1].unlocked + val isNextBarn = GardenPlotAPI.plots[plotIndex + 1].isBarn() + isNextNewRow || !isNextUnlocked || isNextBarn } - return isNextNewRow || !isNextUnlocked || isNextBarn } else if (direction == Direction.NORTH_SOUTH) { - val isNextUnlocked: Boolean - val isNextBarn: Boolean - if (value == Value.TOP) { if (plotIndex - 1 == -1 || (plotIndex - 5) < 0) return true // check if next plot is out of bounds - isNextUnlocked = GardenPlotAPI.plots[plotIndex - 5].unlocked - isNextBarn = GardenPlotAPI.plots[plotIndex - 5].isBarn() + val isNextUnlocked = GardenPlotAPI.plots[plotIndex - 5].unlocked + val isNextBarn = GardenPlotAPI.plots[plotIndex - 5].isBarn() + !isNextUnlocked || isNextBarn } else { if (plotIndex + 5 > 24) return true // check if next plot is out of bounds - isNextUnlocked = GardenPlotAPI.plots[plotIndex + 5].unlocked - isNextBarn = GardenPlotAPI.plots[plotIndex + 5].isBarn() + val isNextUnlocked = GardenPlotAPI.plots[plotIndex + 5].unlocked + val isNextBarn = GardenPlotAPI.plots[plotIndex + 5].isBarn() + !isNextUnlocked || isNextBarn } - return !isNextUnlocked || isNextBarn - } - return false + } else false } } -- cgit