Skip to content

Commit

Permalink
Refactor map room sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry282 committed Aug 13, 2024
1 parent 9258863 commit 9569260
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/funnymap/core/DungeonPlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ data class DungeonPlayer(val skin: ResourceLocation) {
fun getCurrentRoom(): String {
if (dead) return "Dead"
if (Location.inBoss) return "Boss"
val x = (mapX - MapUtils.startCorner.first) / (MapUtils.mapRoomSize + 4)
val z = (mapZ - MapUtils.startCorner.second) / (MapUtils.mapRoomSize + 4)
val x = (mapX - MapUtils.startCorner.first) / (MapUtils.roomSize + MapUtils.connectorSize)
val z = (mapZ - MapUtils.startCorner.second) / (MapUtils.roomSize + MapUtils.connectorSize)
return (Dungeon.Info.dungeonList.getOrNull(x * 2 + z * 22) as? Room)?.data?.name ?: "Error"
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/funnymap/features/dungeon/DungeonMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DungeonMap(mapColors: ByteArray) {
private val cacheTiles: Array<Tile?> = Array(121) { null }

init {
val halfRoom = MapUtils.mapRoomSize / 2
val halfRoom = MapUtils.roomSize / 2
val halfTile = halfRoom + 2
val startX = MapUtils.startCorner.first + halfRoom
val startY = MapUtils.startCorner.second + halfRoom
Expand Down
42 changes: 20 additions & 22 deletions src/main/kotlin/funnymap/features/dungeon/MapRender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import funnymap.core.map.*
import funnymap.ui.ScoreElement
import funnymap.utils.Location.inBoss
import funnymap.utils.MapUtils
import funnymap.utils.MapUtils.mapRoomSize
import funnymap.utils.MapUtils.connectorSize
import funnymap.utils.MapUtils.halfRoomSize
import funnymap.utils.MapUtils.roomSize
import funnymap.utils.RenderUtils
import funnymap.utils.RenderUtils.darken
import funnymap.utils.RenderUtils.grayScale
Expand Down Expand Up @@ -104,16 +106,14 @@ object MapRender {
GlStateManager.pushMatrix()
GlStateManager.translate(MapUtils.startCorner.first.toFloat(), MapUtils.startCorner.second.toFloat(), 0f)

val connectorSize = mapRoomSize shr 2

for (y in 0..10) {
for (x in 0..10) {
val tile = Dungeon.Info.dungeonList[y * 11 + x]
if (tile is Unknown) continue
if (legitRender && tile.state == RoomState.UNDISCOVERED) continue

val xOffset = (x shr 1) * (mapRoomSize + connectorSize)
val yOffset = (y shr 1) * (mapRoomSize + connectorSize)
val xOffset = (x shr 1) * (roomSize + connectorSize)
val yOffset = (y shr 1) * (roomSize + connectorSize)

val xEven = x and 1 == 0
val yEven = y and 1 == 0
Expand All @@ -138,8 +138,8 @@ object MapRender {
RenderUtils.renderRect(
xOffset,
yOffset,
mapRoomSize,
mapRoomSize,
roomSize,
roomSize,
color
)

Expand All @@ -152,8 +152,8 @@ object MapRender {
RenderUtils.renderRect(
xOffset,
yOffset,
(mapRoomSize + connectorSize),
(mapRoomSize + connectorSize),
(roomSize + connectorSize),
(roomSize + connectorSize),
color
)
}
Expand All @@ -171,17 +171,15 @@ object MapRender {
GlStateManager.pushMatrix()
GlStateManager.translate(MapUtils.startCorner.first.toFloat(), MapUtils.startCorner.second.toFloat(), 0f)

val connectorSize = mapRoomSize shr 2

Dungeon.Info.uniqueRooms.forEach { unique ->
val room = unique.mainRoom
if (legitRender && room.state.equalsOneOf(RoomState.UNDISCOVERED, RoomState.UNOPENED)) return@forEach
val checkPos = unique.getCheckmarkPosition()
val namePos = unique.getNamePosition()
val xOffsetCheck = (checkPos.first / 2f) * (mapRoomSize + connectorSize)
val yOffsetCheck = (checkPos.second / 2f) * (mapRoomSize + connectorSize)
val xOffsetName = (namePos.first / 2f) * (mapRoomSize + connectorSize)
val yOffsetName = (namePos.second / 2f) * (mapRoomSize + connectorSize)
val xOffsetCheck = (checkPos.first / 2f) * (roomSize + connectorSize)
val yOffsetCheck = (checkPos.second / 2f) * (roomSize + connectorSize)
val xOffsetName = (namePos.first / 2f) * (roomSize + connectorSize)
val yOffsetName = (namePos.second / 2f) * (roomSize + connectorSize)

if (Config.mapCheckmark != 0 && Config.mapRoomSecrets != 2) {
RenderUtils.drawCheckmark(xOffsetCheck, yOffsetCheck, room.state)
Expand All @@ -196,7 +194,7 @@ object MapRender {
if (Config.mapRoomSecrets == 2) {
GlStateManager.pushMatrix()
GlStateManager.translate(
xOffsetCheck + (mapRoomSize shr 1), yOffsetCheck + 2 + (mapRoomSize shr 1), 0f
xOffsetCheck + halfRoomSize, yOffsetCheck + 2 + halfRoomSize, 0f
)
GlStateManager.scale(2f, 2f, 1f)
RenderUtils.renderCenteredText(listOf(room.data.secrets.toString()), 0, 0, color)
Expand All @@ -220,8 +218,8 @@ object MapRender {
// Offset + half of roomsize
RenderUtils.renderCenteredText(
name,
xOffsetName.toInt() + (mapRoomSize shr 1),
yOffsetName.toInt() + (mapRoomSize shr 1),
xOffsetName.toInt() + halfRoomSize,
yOffsetName.toInt() + halfRoomSize,
color
)
}
Expand Down Expand Up @@ -253,10 +251,10 @@ object MapRender {
vertical: Boolean,
color: Color,
) {
val doorwayOffset = if (mapRoomSize == 16) 5 else 6
val width = if (doorway) 6 else mapRoomSize
var x1 = if (vertical) x + mapRoomSize else x
var y1 = if (vertical) y else y + mapRoomSize
val doorwayOffset = if (roomSize == 16) 5 else 6
val width = if (doorway) 6 else roomSize
var x1 = if (vertical) x + roomSize else x
var y1 = if (vertical) y else y + roomSize
if (doorway) {
if (vertical) y1 += doorwayOffset else x1 += doorwayOffset
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/funnymap/utils/MapUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ object MapUtils {

var mapData: MapData? = null
var startCorner = Pair(5, 5)
var mapRoomSize = 16
var coordMultiplier = 0.625
var roomSize = 16
var halfRoomSize = roomSize / 2
val connectorSize = 4
var calibrated = false

private fun getMapItem(): ItemStack? {
Expand Down Expand Up @@ -52,18 +54,19 @@ object MapUtils {
fun calibrateMap(): Boolean {
val (start, size) = findEntranceCorner()
if (size.equalsOneOf(16, 18)) {
mapRoomSize = size
roomSize = size
halfRoomSize = roomSize / 2
startCorner = when (Location.dungeonFloor) {
0 -> Pair(22, 22)
1 -> Pair(22, 11)
2, 3 -> Pair(11, 11)
else -> {
val startX = start and 127
val startZ = start shr 7
Pair(startX % (mapRoomSize + 4), startZ % (mapRoomSize + 4))
Pair(startX % (roomSize + 4), startZ % (roomSize + 4))
}
}
coordMultiplier = (mapRoomSize + 4.0) / DungeonScan.roomSize
coordMultiplier = (roomSize + connectorSize).toDouble() / DungeonScan.roomSize
return true
}
return false
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/funnymap/utils/RenderUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ object RenderUtils {
mc.textureManager.bindTexture(checkmark)

drawTexturedQuad(
x + (MapUtils.mapRoomSize - size) / 2,
y + (MapUtils.mapRoomSize - size) / 2,
x + (MapUtils.roomSize - size) / 2,
y + (MapUtils.roomSize - size) / 2,
size,
size
)
Expand Down

0 comments on commit 9569260

Please sign in to comment.