Skip to content

Commit b228504

Browse files
committed
why do you throw an error..
1 parent 86d41d7 commit b228504

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/main/kotlin/org/polyfrost/polyplus/client/gui/CartControls.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@file:Suppress("FunctionName")
1+
@file:Suppress("FunctionName", "UnstableApiUsage")
22

33
package org.polyfrost.polyplus.client.gui
44

@@ -20,6 +20,8 @@ import org.polyfrost.polyui.unit.Align
2020
import org.polyfrost.polyui.unit.Vec2
2121
import org.polyfrost.polyui.utils.image
2222

23+
private val ICON_SIZE = Vec2(16f, 16f)
24+
2325
fun CartControls(count: State<Int>): Drawable {
2426
var cartButton: Drawable? = null
2527
var checkoutButton: Drawable? = null
@@ -41,7 +43,7 @@ fun CartControls(count: State<Int>): Drawable {
4143
val currentCartCount = count.value
4244
return Group(
4345
PlusButton(
44-
image = createCartIconPath(currentCartCount).image(),
46+
image = createCartIcon(currentCartCount),
4547
text = "Cart",
4648
radii = floatArrayOf(6f),
4749
size = Vec2(146f, 32f)
@@ -81,17 +83,19 @@ private fun PlusButton(
8183
).withHoverStates().namedId("PlusButton")
8284
}
8385

84-
private fun createCartIconPath(count: Int): String {
85-
if (true) {
86-
// Just until the rest are done
87-
return "/assets/polyplus/ico/shopping-cart/0.svg"
88-
}
89-
90-
return when {
86+
private fun createCartIcon(count: Int): PolyImage {
87+
val image = if (true) {
88+
"/assets/polyplus/ico/shopping-cart/0.svg".image()
89+
} else when {
9190
count <= 0 -> "/assets/polyplus/ico/shopping-cart/0.svg"
9291
count in 1..9 -> "/assets/polyplus/ico/shopping-cart/$count.svg"
9392
else -> "/assets/polyplus/ico/shopping-cart/9+.svg"
93+
}.image()
94+
if (image.size != ICON_SIZE) {
95+
PolyImage.setImageSize(image, ICON_SIZE)
9496
}
97+
98+
return image
9599
}
96100

97101
private fun updateCartIcon(button: Drawable, count: Int) {
@@ -100,7 +104,7 @@ private fun updateCartIcon(button: Drawable, count: Int) {
100104
icon = button[1]
101105
}
102106

103-
(icon as? Image)?.image = createCartIconPath(count).image()
107+
(icon as? Image)?.image = createCartIcon(count)
104108
}
105109

106110
private fun createCheckoutButtonText(count: Int): String {

0 commit comments

Comments
 (0)