Skip to content

Commit 51fd9ac

Browse files
feat: Add center checkmarks and room names
syncs with upstream
1 parent 4511629 commit 51fd9ac

File tree

9 files changed

+179
-51
lines changed

9 files changed

+179
-51
lines changed

src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/cataclysmicmap/core/CataclysmicMapConfig.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ object CataclysmicMapConfig : Vigilant(
162162
)
163163
var mapRoomNames = 1
164164

165+
@Property(
166+
name = "Center Room Names",
167+
type = PropertyType.SWITCH,
168+
description = "Center room names.",
169+
subcategory = "Text",
170+
category = "Rooms"
171+
)
172+
var mapCenterRoomName = true
173+
165174
@Property(
166175
name = "Room Secrets",
167176
type = PropertyType.SELECTOR,
@@ -188,6 +197,15 @@ object CataclysmicMapConfig : Vigilant(
188197
)
189198
var mapCheckmark = 1
190199

200+
@Property(
201+
name = "Center Room Checkmarks",
202+
type = PropertyType.SWITCH,
203+
description = "Center room checkmarks.",
204+
subcategory = "Checkmarks",
205+
category = "Rooms"
206+
)
207+
var mapCenterCheckmark = true
208+
191209
@Property(
192210
name = "Blood Door",
193211
type = PropertyType.COLOR,

src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/cataclysmicmap/core/CataclysmicMapElement.kt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import gg.skytils.skytilsmod.core.structure.GuiElement
2525
import gg.skytils.skytilsmod.features.impl.dungeons.DungeonTimer
2626
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.*
2727
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonInfo
28+
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonMapColorParser
2829
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonScanner
2930
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils.MapUtils
3031
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils.RenderUtils
@@ -79,7 +80,7 @@ object CataclysmicMapElement : GuiElement(name = "Dungeon Map", x = 0, y = 0) {
7980
GlStateManager.pushMatrix()
8081
GlStateManager.translate(MapUtils.startCorner.first.toFloat(), MapUtils.startCorner.second.toFloat(), 0f)
8182

82-
val connectorSize = MapUtils.mapRoomSize shr 2
83+
val connectorSize = DungeonMapColorParser.quarterRoom
8384
val checkmarkSize = when (CataclysmicMapConfig.mapCheckmark) {
8485
1 -> 8.0 // default
8586
else -> 10.0 // neu
@@ -123,7 +124,7 @@ object CataclysmicMapElement : GuiElement(name = "Dungeon Map", x = 0, y = 0) {
123124
}
124125

125126
if (tile is Room && tile.state == RoomState.UNOPENED && CataclysmicMapConfig.mapCheckmark != 0) {
126-
drawCheckmark(tile, xOffset, yOffset, checkmarkSize)
127+
drawCheckmark(tile, xOffset.toFloat(), yOffset.toFloat(), checkmarkSize)
127128
}
128129
}
129130
}
@@ -134,16 +135,21 @@ object CataclysmicMapElement : GuiElement(name = "Dungeon Map", x = 0, y = 0) {
134135
GlStateManager.pushMatrix()
135136
GlStateManager.translate(MapUtils.startCorner.first.toFloat(), MapUtils.startCorner.second.toFloat(), 0f)
136137

137-
val connectorSize = MapUtils.mapRoomSize shr 2
138138
val checkmarkSize = when (CataclysmicMapConfig.mapCheckmark) {
139139
1 -> 8.0 // default
140140
else -> 10.0 // neu
141141
}
142142

143-
DungeonInfo.uniqueRooms.forEach { (room, pos) ->
143+
DungeonInfo.uniqueRooms.forEach { unq ->
144+
val room = unq.mainRoom
144145
if (room.state == RoomState.UNDISCOVERED) return@forEach
145-
val xOffset = (pos.first shr 1) * (MapUtils.mapRoomSize + connectorSize)
146-
val yOffset = (pos.second shr 1) * (MapUtils.mapRoomSize + connectorSize)
146+
val size = MapUtils.mapRoomSize + DungeonMapColorParser.quarterRoom
147+
val checkPos = unq.getCheckmarkPosition()
148+
val namePos = unq.getNamePosition()
149+
val xOffsetCheck = (checkPos.first / 2f) * size
150+
val yOffsetCheck = (checkPos.second / 2f) * size
151+
val xOffsetName = (namePos.first / 2f) * size
152+
val yOffsetName = (namePos.second / 2f) * size
147153

148154
val color = if (CataclysmicMapConfig.mapColorText) when (room.state) {
149155
RoomState.GREEN -> 0x55ff55
@@ -160,15 +166,15 @@ object CataclysmicMapElement : GuiElement(name = "Dungeon Map", x = 0, y = 0) {
160166
if (CataclysmicMapConfig.mapRoomSecrets == 2 && hasSecrets) {
161167
GlStateManager.pushMatrix()
162168
GlStateManager.translate(
163-
xOffset + (MapUtils.mapRoomSize shr 1).toFloat(),
164-
yOffset + 2 + (MapUtils.mapRoomSize shr 1).toFloat(),
169+
xOffsetCheck + (MapUtils.mapRoomSize shr 1).toFloat(),
170+
yOffsetCheck + 2 + (MapUtils.mapRoomSize shr 1).toFloat(),
165171
0f
166172
)
167173
GlStateManager.scale(2f, 2f, 1f)
168174
RenderUtils.renderCenteredText(listOf(secretCount.toString()), 0, 0, color)
169175
GlStateManager.popMatrix()
170176
} else if (CataclysmicMapConfig.mapCheckmark != 0) {
171-
drawCheckmark(room, xOffset, yOffset, checkmarkSize)
177+
drawCheckmark(room, xOffsetCheck, yOffsetCheck, checkmarkSize)
172178
}
173179

174180
val name = mutableListOf<String>()
@@ -190,8 +196,8 @@ object CataclysmicMapElement : GuiElement(name = "Dungeon Map", x = 0, y = 0) {
190196
// Offset + half of roomsize
191197
RenderUtils.renderCenteredText(
192198
name,
193-
xOffset + (MapUtils.mapRoomSize shr 1),
194-
yOffset + (MapUtils.mapRoomSize shr 1),
199+
(xOffsetName + DungeonMapColorParser.halfRoom).toInt(),
200+
(yOffsetName + DungeonMapColorParser.halfRoom).toInt(),
195201
color
196202
)
197203
}
@@ -220,7 +226,7 @@ object CataclysmicMapElement : GuiElement(name = "Dungeon Map", x = 0, y = 0) {
220226
}
221227
}
222228

223-
private fun drawCheckmark(tile: Tile, xOffset: Int, yOffset: Int, checkmarkSize: Double) {
229+
private fun drawCheckmark(tile: Tile, xOffset: Float, yOffset: Float, checkmarkSize: Double) {
224230
getCheckmark(tile.state, CataclysmicMapConfig.mapCheckmark)?.let {
225231
GlStateManager.enableAlpha()
226232
GlStateManager.color(1f, 1f, 1f, 1f)

src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/cataclysmicmap/core/map/Room.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map
2020

2121
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.CataclysmicMapConfig
22+
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonInfo
23+
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonScanner
2224
import java.awt.Color
2325

2426
class Room(override val x: Int, override val z: Int, var data: RoomData) : Tile {
@@ -40,4 +42,18 @@ class Room(override val x: Int, override val z: Int, var data: RoomData) : Tile
4042
else -> CataclysmicMapConfig.colorRoom
4143
}
4244
}
45+
46+
fun getArrayPosition(): Pair<Int, Int> {
47+
return Pair((x - DungeonScanner.startX) / 16, (z - DungeonScanner.startZ) / 16)
48+
}
49+
50+
fun addToUnique(row: Int, column: Int, roomName: String = data.name) {
51+
val unique = DungeonInfo.uniqueRooms.find { it.name == roomName }
52+
53+
if (unique == null) {
54+
DungeonInfo.uniqueRooms.add(UniqueRoom(column, row, this))
55+
} else {
56+
unique.addTile(column, row, this)
57+
}
58+
}
4359
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map
2+
3+
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.CataclysmicMapConfig
4+
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.CataclysmicMapElement
5+
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonInfo
6+
7+
8+
class UniqueRoom(arrX: Int, arrY: Int, room: Room) {
9+
val name = room.data.name
10+
private var topLeft = Pair(arrX, arrY)
11+
private var center = Pair(arrX, arrY)
12+
var mainRoom = room
13+
private val tiles = mutableListOf(room)
14+
15+
init {
16+
DungeonInfo.cryptCount += room.data.crypts
17+
DungeonInfo.secretCount += room.data.secrets
18+
when (room.data.type) {
19+
RoomType.ENTRANCE -> CataclysmicMapElement.dynamicRotation = when {
20+
arrY == 0 -> 180f
21+
arrX == 0 -> -90f
22+
arrX > arrY -> 90f
23+
else -> 0f
24+
}
25+
26+
RoomType.TRAP -> DungeonInfo.trapType = room.data.name.split(" ")[0]
27+
//RoomType.PUZZLE -> Puzzle.fromName(room.data.name)?.let { Dungeon.Info.puzzles.putIfAbsent(it, false) }
28+
29+
else -> {}
30+
}
31+
}
32+
33+
fun addTile(x: Int, y: Int, tile: Room) {
34+
tiles.removeIf { it.x == tile.x && it.z == tile.z }
35+
tiles.add(tile)
36+
37+
if (x < topLeft.first || (x == topLeft.first && y < topLeft.second)) {
38+
topLeft = Pair(x, y)
39+
mainRoom = tile
40+
}
41+
42+
if (tiles.size == 1) {
43+
center = Pair(x, y)
44+
return
45+
}
46+
47+
val positions = tiles.mapNotNull {
48+
it.getArrayPosition().takeIf { (arrX, arrZ) ->
49+
arrX % 2 == 0 && arrZ % 2 == 0
50+
}
51+
}
52+
53+
if (positions.isEmpty()) return
54+
55+
val xRooms = positions.groupBy { it.first }.entries.sortedByDescending { it.value.size }
56+
val zRooms = positions.groupBy { it.second }.entries.sortedByDescending { it.value.size }
57+
58+
center = when {
59+
zRooms.size == 1 || zRooms[0].value.size != zRooms[1].value.size -> {
60+
xRooms.sumOf { it.key } / xRooms.size to zRooms[0].key
61+
}
62+
63+
xRooms.size == 1 || xRooms[0].value.size != xRooms[1].value.size -> {
64+
xRooms[0].key to zRooms.sumOf { it.key } / zRooms.size
65+
}
66+
67+
else -> (xRooms[0].key + xRooms[1].key) / 2 to (zRooms[0].key + zRooms[1].key) / 2
68+
}
69+
}
70+
71+
fun getNamePosition(): Pair<Int, Int> {
72+
return if (CataclysmicMapConfig.mapCenterRoomName) center else topLeft
73+
}
74+
75+
fun getCheckmarkPosition(): Pair<Int, Int> {
76+
return if (CataclysmicMapConfig.mapCenterCheckmark) center else topLeft
77+
}
78+
}

src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/cataclysmicmap/handlers/DungeonInfo.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818

1919
package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers
2020

21-
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Puzzle
22-
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Room
23-
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Tile
24-
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Unknown
21+
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.*
2522
import net.minecraft.world.storage.MapData
2623

2724
object DungeonInfo {
2825
// 6 x 6 room grid, 11 x 11 with connections
2926
val dungeonList = Array<Tile>(121) { Unknown(0, 0) }
30-
val uniqueRooms = mutableListOf<Pair<Room, Pair<Int, Int>>>()
27+
val uniqueRooms = mutableSetOf<UniqueRoom>()
3128
var roomCount = 0
3229
val puzzles = mutableMapOf<Puzzle, Boolean>()
3330

src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/cataclysmicmap/handlers/DungeonMapColorParser.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,25 @@ package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers
2020

2121
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.*
2222
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils.MapUtils
23+
import net.minecraft.util.EnumFacing
2324
import net.minecraft.world.storage.MapData
2425

2526
object DungeonMapColorParser {
2627
private var centerColors: ByteArray = ByteArray(121)
2728
private var sideColors: ByteArray = ByteArray(121)
2829
private var cachedTiles: Array<Tile?> = Array(121) { null }
2930

30-
private var halfRoom = -1
31-
private var halfTile = -1
32-
private var startX = -1
33-
private var startY = -1
31+
var halfRoom = -1
32+
var halfTile = -1
33+
// connectorSize
34+
var quarterRoom = -1
35+
var startX = -1
36+
var startY = -1
3437

3538
fun calibrate() {
3639
halfRoom = MapUtils.mapRoomSize / 2
3740
halfTile = halfRoom + 2
41+
quarterRoom = halfRoom / 2
3842
startX = MapUtils.startCorner.first + halfRoom
3943
startY = MapUtils.startCorner.second + halfRoom
4044

@@ -84,6 +88,21 @@ object DungeonMapColorParser {
8488
return cachedTiles[index] ?: Unknown(0, 0)
8589
}
8690

91+
fun getConnected(arrayX: Int, arrayY: Int): List<Room> {
92+
val tile = getTile(arrayX, arrayY) as? Room ?: return emptyList()
93+
val connected = mutableListOf<Room>()
94+
val queue = ArrayDeque<Room>()
95+
queue.add(tile)
96+
while (queue.isNotEmpty()) {
97+
val current = queue.removeFirst()
98+
connected.add(current)
99+
queue.addAll(EnumFacing.HORIZONTALS.mapNotNull {
100+
getTile(current.x + it.directionVec.x, current.z + it.directionVec.z) as? Room
101+
})
102+
}
103+
return connected
104+
}
105+
87106
private fun scanTile(arrayX: Int, arrayY: Int, worldX: Int, worldZ: Int): Tile {
88107
val centerColor = centerColors[arrayY * 11 + arrayX].toInt()
89108
val sideColor = sideColors[arrayY * 11 + arrayX].toInt()

src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/cataclysmicmap/handlers/DungeonScanner.kt

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -100,37 +100,19 @@ object DungeonScanner {
100100
val roomCore = ScanUtils.getCore(x, z)
101101
Room(x, z, ScanUtils.getRoomData(roomCore) ?: return null).apply {
102102
core = roomCore
103-
// Checks if a room with the same name has already been scanned.
104-
val duplicateRoom = DungeonInfo.uniqueRooms.firstOrNull { it.first.data.name == data.name }
105-
106-
if (duplicateRoom == null) {
107-
DungeonInfo.uniqueRooms.add(this to (column to row))
108-
DungeonInfo.cryptCount += data.crypts
109-
DungeonInfo.secretCount += data.secrets
110-
when (data.type) {
111-
RoomType.ENTRANCE -> CataclysmicMapElement.dynamicRotation = when {
112-
row == 0 -> 180f
113-
column == 0 -> -90f
114-
column > row -> 90f
115-
else -> 0f
116-
}
117-
118-
RoomType.TRAP -> DungeonInfo.trapType = data.name.split(" ")[0]
119-
RoomType.PUZZLE -> {}//Puzzle.fromName(data.name)?.let { DungeonInfo.puzzles.putIfAbsent(it, false) }
120-
121-
else -> {}
122-
}
123-
} else if (x < duplicateRoom.first.x || (x == duplicateRoom.first.x && z < duplicateRoom.first.z)) {
124-
DungeonInfo.uniqueRooms.remove(duplicateRoom)
125-
DungeonInfo.uniqueRooms.add(this to (column to row))
126-
}
103+
addToUnique(row, column)
127104
}
128105
}
129106

130107
// Can only be the center "block" of a 2x2 room.
131108
!rowEven && !columnEven -> {
132109
DungeonInfo.dungeonList[column - 1 + (row - 1) * 11].let {
133-
if (it is Room) Room(x, z, it.data).apply { isSeparator = true } else null
110+
if (it is Room) {
111+
Room(x, z, it.data).apply {
112+
isSeparator = true
113+
addToUnique(row, column)
114+
}
115+
} else null
134116
}
135117
}
136118

src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/cataclysmicmap/handlers/MapUpdater.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,25 @@ object MapUpdater {
6464

6565
if (room is Unknown) {
6666
DungeonInfo.dungeonList[z * 11 + x] = mapTile
67+
if (mapTile is Room) {
68+
val connected = DungeonMapColorParser.getConnected(x, z)
69+
connected.firstOrNull { it.data.name != "Unknown" }?.let {
70+
mapTile.addToUnique(z, x, it.data.name)
71+
}
72+
}
6773
continue
6874
}
6975

7076
if (mapTile.state.ordinal < room.state.ordinal) {
7177
room.state = mapTile.state
7278
}
7379

80+
if (mapTile is Door && room is Door) {
81+
if (mapTile.type == DoorType.WITHER && room.type != DoorType.WITHER) {
82+
room.type = mapTile.type
83+
}
84+
}
85+
7486
if (room is Door && Utils.equalsOneOf(room.type, DoorType.ENTRANCE, DoorType.WITHER, DoorType.BLOOD)) {
7587
if (mapTile is Door && mapTile.type == DoorType.WITHER) {
7688
room.opened = false
@@ -84,11 +96,11 @@ object MapUpdater {
8496
room.opened = true
8597
} else if (mapTile is Door && mapTile.state == RoomState.DISCOVERED) {
8698
if (room.type == DoorType.BLOOD) {
87-
val bloodRoom = DungeonInfo.uniqueRooms.find { (r, _) ->
88-
r.data.type == RoomType.BLOOD
89-
}?.first
99+
val bloodRoom = DungeonInfo.uniqueRooms.find { r ->
100+
r.mainRoom.data.type == RoomType.BLOOD
101+
}
90102

91-
if (bloodRoom != null && bloodRoom.state != RoomState.UNOPENED) {
103+
if (bloodRoom != null && bloodRoom.mainRoom.state != RoomState.UNOPENED) {
92104
room.opened = true
93105
}
94106
} else {

src/main/kotlin/gg/skytils/skytilsmod/features/impl/dungeons/cataclysmicmap/utils/RenderUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ object RenderUtils {
144144
0.0
145145
)
146146
} else {
147-
player.teammate.player?.let { entityPlayer ->
147+
player.teammate.player?.also { entityPlayer ->
148148
// If the player is loaded in our view, use that location instead (more precise)
149149
GlStateManager.translate(
150150
(entityPlayer.posX - DungeonScanner.startX + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.first,

0 commit comments

Comments
 (0)