mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Apply Char(Int) and Char.code patch to Maya Calendar (#6435)
This commit is contained in:
parent
c93f0339a3
commit
2c2ffd02d1
@ -64,11 +64,11 @@ data class KeyCharAndCode(val char: Char, val code: Int) {
|
|||||||
val UNKNOWN = KeyCharAndCode(Input.Keys.UNKNOWN)
|
val UNKNOWN = KeyCharAndCode(Input.Keys.UNKNOWN)
|
||||||
|
|
||||||
// Kludges because we got crashes: java.lang.NoSuchMethodError: 'int kotlin.CharCodeKt.access$getCode$p(char)'
|
// Kludges because we got crashes: java.lang.NoSuchMethodError: 'int kotlin.CharCodeKt.access$getCode$p(char)'
|
||||||
private fun Char.toCode() =
|
fun Char.toCode() =
|
||||||
try { code } catch (ex: Throwable) { null }
|
try { code } catch (ex: Throwable) { null }
|
||||||
?: try { @Suppress("DEPRECATION") toInt() } catch (ex: Throwable) { null }
|
?: try { @Suppress("DEPRECATION") toInt() } catch (ex: Throwable) { null }
|
||||||
?: 0
|
?: 0
|
||||||
private fun Int.makeChar() =
|
fun Int.makeChar() =
|
||||||
try { Char(this) } catch (ex: Throwable) { null }
|
try { Char(this) } catch (ex: Throwable) { null }
|
||||||
?: try { toChar() } catch (ex: Throwable) { null }
|
?: try { toChar() } catch (ex: Throwable) { null }
|
||||||
?: Char.MIN_VALUE
|
?: Char.MIN_VALUE
|
||||||
|
@ -6,6 +6,8 @@ import com.unciv.logic.civilization.CivilizationInfo
|
|||||||
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
import com.unciv.models.ruleset.unique.UniqueTriggerActivation
|
||||||
import com.unciv.models.ruleset.unique.UniqueType
|
import com.unciv.models.ruleset.unique.UniqueType
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
|
import com.unciv.ui.utils.KeyCharAndCode.Companion.makeChar
|
||||||
|
import com.unciv.ui.utils.KeyCharAndCode.Companion.toCode
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
object MayaCalendar {
|
object MayaCalendar {
|
||||||
@ -23,7 +25,7 @@ object MayaCalendar {
|
|||||||
const val zero = 'ⅰ' // U+2170
|
const val zero = 'ⅰ' // U+2170
|
||||||
const val nineteen = 'Ↄ' // U+2183
|
const val nineteen = 'Ↄ' // U+2183
|
||||||
val digits = zero..nineteen
|
val digits = zero..nineteen
|
||||||
fun digitIcon(ch: Char) = iconFolder + (ch.code - zero.code).toString()
|
fun digitIcon(ch: Char) = iconFolder + (ch.toCode() - zero.toCode()).toString()
|
||||||
|
|
||||||
// Calculation
|
// Calculation
|
||||||
private const val daysOn30000101BCE = 36000 + 5040 + 240 + 11
|
private const val daysOn30000101BCE = 36000 + 5040 + 240 + 11
|
||||||
@ -43,9 +45,9 @@ object MayaCalendar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
val baktunDigit = Char(zero.code + baktuns)
|
val baktunDigit = (zero.toCode() + baktuns).makeChar()
|
||||||
val katunDigit = Char(zero.code + katuns)
|
val katunDigit = (zero.toCode() + katuns).makeChar()
|
||||||
val tunDigit = Char(zero.code + tuns)
|
val tunDigit = (zero.toCode() + tuns).makeChar()
|
||||||
return "$baktunDigit$baktun$katunDigit$katun$tunDigit$tun"
|
return "$baktunDigit$baktun$katunDigit$katun$tunDigit$tun"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user