DEADSOFTWARE

Prettier world + ores
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / misc / utils / RenderingUtils.kt
index 28c38276650f23485ade46a73bccbe37fa4ac86a..24813acc853fe54ef5421c046a55c48cfede0b39 100644 (file)
@@ -1,6 +1,11 @@
 package ru.deadsoftware.cavedroid.misc.utils
 
+import com.badlogic.gdx.graphics.Color
+import com.badlogic.gdx.graphics.g2d.GlyphLayout
+import com.badlogic.gdx.graphics.g2d.SpriteBatch
 import com.badlogic.gdx.math.Rectangle
+import ru.deadsoftware.cavedroid.misc.Assets
+import java.awt.Color as JavaColor
 
 private fun Rectangle.shifted(shift: Float) = Rectangle(x + shift, y, width, height)
 
@@ -27,16 +32,27 @@ 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) {
             func(x, y)
         }
     }
-}
\ No newline at end of file
+}
+
+@JvmOverloads
+fun SpriteBatch.drawString(str: String, x: Float, y: Float, color: Color = Color.WHITE): GlyphLayout {
+    Assets.minecraftFont.color = color
+    return Assets.minecraftFont.draw(this, str, x, y)
+}
+
+fun colorFromHexString(hex: String): Color {
+    val rgba = (JavaColor.decode(hex).rgb shl 8) or (0xFF)
+    return Color(rgba)
+}