From 2c2ffd02d12edf24807f29f1318bc7675a54ea4e Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Sat, 26 Mar 2022 19:33:45 +0100 Subject: [PATCH] Apply Char(Int) and Char.code patch to Maya Calendar (#6435) --- core/src/com/unciv/ui/utils/KeyPressDispatcher.kt | 4 ++-- core/src/com/unciv/ui/utils/MayaCalendar.kt | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/ui/utils/KeyPressDispatcher.kt b/core/src/com/unciv/ui/utils/KeyPressDispatcher.kt index 03e1d5c35c..184922f03a 100644 --- a/core/src/com/unciv/ui/utils/KeyPressDispatcher.kt +++ b/core/src/com/unciv/ui/utils/KeyPressDispatcher.kt @@ -64,11 +64,11 @@ data class KeyCharAndCode(val char: Char, val code: Int) { val UNKNOWN = KeyCharAndCode(Input.Keys.UNKNOWN) // 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 { @Suppress("DEPRECATION") toInt() } catch (ex: Throwable) { null } ?: 0 - private fun Int.makeChar() = + fun Int.makeChar() = try { Char(this) } catch (ex: Throwable) { null } ?: try { toChar() } catch (ex: Throwable) { null } ?: Char.MIN_VALUE diff --git a/core/src/com/unciv/ui/utils/MayaCalendar.kt b/core/src/com/unciv/ui/utils/MayaCalendar.kt index e66edc6846..018e311ded 100644 --- a/core/src/com/unciv/ui/utils/MayaCalendar.kt +++ b/core/src/com/unciv/ui/utils/MayaCalendar.kt @@ -6,6 +6,8 @@ import com.unciv.logic.civilization.CivilizationInfo import com.unciv.models.ruleset.unique.UniqueTriggerActivation import com.unciv.models.ruleset.unique.UniqueType 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 object MayaCalendar { @@ -23,7 +25,7 @@ object MayaCalendar { const val zero = 'ⅰ' // U+2170 const val nineteen = 'Ↄ' // U+2183 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 private const val daysOn30000101BCE = 36000 + 5040 + 240 + 11 @@ -43,9 +45,9 @@ object MayaCalendar { } override fun toString(): String { - val baktunDigit = Char(zero.code + baktuns) - val katunDigit = Char(zero.code + katuns) - val tunDigit = Char(zero.code + tuns) + val baktunDigit = (zero.toCode() + baktuns).makeChar() + val katunDigit = (zero.toCode() + katuns).makeChar() + val tunDigit = (zero.toCode() + tuns).makeChar() return "$baktunDigit$baktun$katunDigit$katun$tunDigit$tun" } }