Newer
Older
Twilight / src / main / kotlin / net / taehui / twilight / system / AbilityClassSystem.kt
package net.taehui.twilight.system

import com.fasterxml.jackson.annotation.JsonValue
import net.taehui.twilight.Logger
import java.nio.file.Path
import kotlin.io.path.pathString

object AbilityClassSystem : Logger {
    enum class AbilityClassVariety(@JvmField val value: Int) {
        ETC(-1), INPUT_MODE_5K(0), INPUT_MODE_7K(1), INPUT_MODE_9K(2);

        @JsonValue
        fun getValue(): Int {
            return value
        }
    }

    private var abilityClasses = arrayOf(emptyArray<Array<ByteArray>>(), emptyArray<Array<ByteArray>>(), emptyArray<Array<ByteArray>>())

    fun getAbilityClass(abilityClassVariety: AbilityClassVariety, abilityClass: Double): ByteArray {
        val abilityClasses = abilityClasses[abilityClassVariety.value]

        return when (abilityClass) {
            -1.0, -2.0, -3.0 -> abilityClasses[0][0]
            -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0 -> abilityClasses[1][0]
            else -> {
                return if (0 <= abilityClass && abilityClass < 2) {
                    abilityClasses[2][(5 * abilityClass / 2).toInt()]
                } else if (2 <= abilityClass && abilityClass < 13) {
                    abilityClasses[3][(5 * (abilityClass - 2) / 11).toInt()]
                } else if (13 <= abilityClass && abilityClass < 33) {
                    abilityClasses[4][(5 * (abilityClass - 13) / 20).toInt()]
                } else if (33 <= abilityClass && abilityClass < 62) {
                    abilityClasses[5][(5 * (abilityClass - 33) / 29).toInt()]
                } else if (62 <= abilityClass && abilityClass < 100) {
                    abilityClasses[6][(5 * (abilityClass - 62) / 38).toInt()]
                } else {
                    abilityClasses[7][0]
                }
            }
        }
    }

    fun loadAbilityClasses() {
        fun loadAbilityClass(abilityClassVariety: AbilityClassVariety) {
            fun loadDrawing(path: String): ByteArray {
                return AbilityClassSystem::class.java.classLoader.getResourceAsStream(
                    Path.of(
                        when (abilityClassVariety) {
                            AbilityClassVariety.ETC -> ""
                            AbilityClassVariety.INPUT_MODE_5K -> "abilityClass5K"
                            AbilityClassVariety.INPUT_MODE_7K -> "abilityClass7K"
                            AbilityClassVariety.INPUT_MODE_9K -> "abilityClass9K"
                        },
                        path
                    ).pathString
                )
                    .use { it!!.readAllBytes() }
            }

            abilityClasses[abilityClassVariety.value] = arrayOf(
                arrayOf(
                    loadDrawing("S+.png")
                ), arrayOf(
                    loadDrawing("S.png")
                ), arrayOf(
                    loadDrawing("A+1.png"),
                    loadDrawing("A+2.png"),
                    loadDrawing("A+3.png"),
                    loadDrawing("A+4.png"),
                    loadDrawing("A+5.png")
                ), arrayOf(
                    loadDrawing("A1.png"),
                    loadDrawing("A2.png"),
                    loadDrawing("A3.png"),
                    loadDrawing("A4.png"),
                    loadDrawing("A5.png")
                ), arrayOf(
                    loadDrawing("B1.png"),
                    loadDrawing("B2.png"),
                    loadDrawing("B3.png"),
                    loadDrawing("B4.png"),
                    loadDrawing("B5.png")
                ), arrayOf(
                    loadDrawing("C1.png"),
                    loadDrawing("C2.png"),
                    loadDrawing("C3.png"),
                    loadDrawing("C4.png"),
                    loadDrawing("C5.png")
                ), arrayOf(
                    loadDrawing("D1.png"),
                    loadDrawing("D2.png"),
                    loadDrawing("D3.png"),
                    loadDrawing("D4.png"),
                    loadDrawing("D5.png")
                ), arrayOf(
                    loadDrawing("F.png")
                )
            )
        }

        loadAbilityClass(AbilityClassVariety.INPUT_MODE_5K)
        loadAbilityClass(AbilityClassVariety.INPUT_MODE_7K)
        loadAbilityClass(AbilityClassVariety.INPUT_MODE_9K)

        logInfo("Loaded Ability Class")
    }
}