From cc9b2beaf814bd5c5b1604b8178e73fafaf5c448 Mon Sep 17 00:00:00 2001 From: Fiereu Date: Sat, 30 May 2026 10:57:44 +0200 Subject: [PATCH] fix: missing RenderUtil.kt --- .../openmmo/maps/generator/RenderUtil.kt | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 maps/src/generator/kotlin/de/fiereu/openmmo/maps/generator/RenderUtil.kt diff --git a/maps/src/generator/kotlin/de/fiereu/openmmo/maps/generator/RenderUtil.kt b/maps/src/generator/kotlin/de/fiereu/openmmo/maps/generator/RenderUtil.kt new file mode 100644 index 0000000..66da4da --- /dev/null +++ b/maps/src/generator/kotlin/de/fiereu/openmmo/maps/generator/RenderUtil.kt @@ -0,0 +1,58 @@ +package de.fiereu.openmmo.maps.generator + +object RenderUtil { + + private const val EMPTY_LIST = "emptyList()" + private const val LIST_OPEN = "listOf(\n " + private const val LIST_SEP = ",\n " + private const val LIST_CLOSE = ",\n )" + + fun borderTiles(tiles: List): String { + val take = tiles.take(4) + val filled = + if (take.size < 4) take + List(4 - take.size) { if (take.isEmpty()) 8 else take.last() } + else take + return filled.joinToString(", ", "listOf(", ")") { + "Tile2D(0x${it.toString(16).uppercase().padStart(4, '0')}, 0)" + } + } + + fun connections(conns: List): String { + if (conns.isEmpty()) return EMPTY_LIST + return conns.joinToString(LIST_SEP, LIST_OPEN, LIST_CLOSE) { + "MapData.GbaConnection(direction = ${it.direction}, unknown = ${it.offset}," + + " targetBank = ${it.targetBank}, targetMap = ${it.targetMap})" + } + } + + fun warps(warps: List): String { + if (warps.isEmpty()) return EMPTY_LIST + return warps.joinToString(LIST_SEP, LIST_OPEN, LIST_CLOSE) { + "WarpTile(x = ${it.x}, y = ${it.y}, elevation = ${it.elevation}," + + " targetRegionId = 1, targetBankId = ${it.targetBank}, targetMapId = ${it.targetMap}," + + " targetX = ${it.targetX}, targetY = ${it.targetY}, targetElevation = ${it.targetElevation})" + } + } + + fun npcs(npcs: List): String { + if (npcs.isEmpty()) return EMPTY_LIST + return npcs.joinToString(LIST_SEP, LIST_OPEN, LIST_CLOSE) { + "NpcDef(entityIdx = ${it.entityIdx}, graphicsId = ${it.graphicsId}," + + " x = ${it.x}, y = ${it.y}, elevation = ${it.elevation}," + + " movementType = ${it.movementType}, movementRangeX = ${it.movementRangeX}," + + " movementRangeY = ${it.movementRangeY}, trainerType = ${it.trainerType}," + + " facing = ${it.facing}, script = ${escapeString(it.script)})" + } + } + + fun bgEvents(events: List): String { + if (events.isEmpty()) return EMPTY_LIST + return events.joinToString(LIST_SEP, LIST_OPEN, LIST_CLOSE) { + "BgEventDef(x = ${it.x}, y = ${it.y}," + + " facingDir = ${escapeString(it.facingDir)}, script = ${escapeString(it.script)})" + } + } + + private fun escapeString(s: String): String = + "\"" + s.replace("\\", "\\\\").replace("\"", "\\\"") + "\"" +}