All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.elderscrollslegends.CardCache.kt Maven / Gradle / Ivy

There is a newer version: 1.1.7
Show newest version
package io.elderscrollslegends

class CardCache {
    companion object {
        private val cache = mutableMapOf()

        @JvmStatic
        fun load() {
            cache.clear()
            Card.all().forEach { card ->
                cache[card.id] = card
            }
        }

        @JvmStatic
        fun findById(id: String): Card? {
            return if (!hasCard(id)) {
                val card = Card.find(id)
                if (card != null) {
                    cache[id] = card
                }
                card
            } else {
                cache[id]
            }
        }

        @JvmStatic
        fun findByCode(code: String): Card? {
            val id = Decoder.codeToIdMap[code] ?: return null
            return findById(id)
        }

        fun hasCard(id: String): Boolean = cache.containsKey(id)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy