aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/ambientaddons/utils/DungeonFloor.kt
blob: ab11d7f23f603c0540be8d40c06f8873789276ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.ambientaddons.utils

data class DungeonFloor(
    val mode: Mode,
    val floor: Int
) {
    override fun toString(): String {
        return when {
            floor == 0 -> "E"
            mode == Mode.Normal -> "F$floor"
            else -> "M$floor"
        }
    }

    companion object {
        fun String.toDungeonFloor(): DungeonFloor? {
            if (this.isEmpty()) return null
            if (this == "E") return DungeonFloor(Mode.Normal, 0)
            val floorInt = this.last().digitToIntOrNull() ?: return null
            if (floorInt !in 1..7) return null
            return when (this.first()) {
                'F' -> DungeonFloor(Mode.Normal, floorInt)
                'M' -> DungeonFloor(Mode.Master, floorInt)
                else -> null
            }
        }
    }

    enum class Mode { Normal, Master }
}