If it ever happens, avoid dividing by zero
This commit is contained in:
parent
37974d40b9
commit
6105ca797b
@ -362,9 +362,15 @@ fun IMatteryEnergyStorage.transferChecked(other: IMatteryEnergyStorage, amount:
|
||||
}
|
||||
|
||||
fun IMatteryEnergyStorage.getBarWidth(): Int {
|
||||
return ((batteryLevel / maxBatteryLevel).toFloat().coerceAtLeast(0f).coerceAtMost(1f) * 13f).roundToInt()
|
||||
if (!maxBatteryLevel.isPositive)
|
||||
return 0
|
||||
|
||||
return ((batteryLevel / maxBatteryLevel).toFloat().coerceIn(0f, 1f) * 13f).roundToInt()
|
||||
}
|
||||
|
||||
fun IMatteryEnergyStorage.getBarColor(): Int {
|
||||
if (!maxBatteryLevel.isPositive)
|
||||
return 0
|
||||
|
||||
return RGBAColor.LOW_POWER.linearInterpolation((batteryLevel / maxBatteryLevel).toFloat(), RGBAColor.FULL_POWER).toRGB()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user