X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fmisc%2Futils%2FRenderingUtils.kt;h=8976c9963cd8935d64a373ee54db088513537662;hb=ca4dfc9c8252d4222f778db27e7505909420da39;hp=5849f03c79f02356a2e14a3f3c58df7102421f0a;hpb=409a22b3fe7c43b7f686f33cc2f01b6277edec78;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/misc/utils/RenderingUtils.kt b/core/src/ru/deadsoftware/cavedroid/misc/utils/RenderingUtils.kt index 5849f03..8976c99 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/utils/RenderingUtils.kt +++ b/core/src/ru/deadsoftware/cavedroid/misc/utils/RenderingUtils.kt @@ -31,12 +31,12 @@ fun Rectangle.cycledInsideWorld( fun forEachBlockInArea( area: Rectangle, - func: (x: Int, y: Int) -> Unit + func: (x: Int, y: Int) -> Unit, ) { val startMapX = area.x.bl - val endMapX = startMapX + area.width.bl + 1 + val endMapX = (area.x + area.width - 1f).bl val startMapY = area.y.bl - val endMapY = startMapY + area.height.bl + 1 + val endMapY = (area.y + area.height - 1f).bl for (x in startMapX..endMapX) { for (y in startMapY..endMapY) { @@ -50,3 +50,22 @@ fun SpriteBatch.drawString(str: String, x: Float, y: Float, color: Color = Color Assets.minecraftFont.color = color return Assets.minecraftFont.draw(this, str, x, y) } + +/** + * Parses hex color string into [Color] + * Format is strictly #FFFFFF + */ +fun colorFromHexString(hex: String): Color { + if (hex[0] != '#' || hex.length != 7) { + return Color.WHITE + } + + var rgba = try { + hex.substring(1).toInt(16) + } catch (e: NumberFormatException) { + 0xffffff + } + + rgba = (rgba shl 8) or 0xFF + return Color(rgba) +}