mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
More thorough workaround for Char.code and Char(Int) crashing (#6419)
This commit is contained in:
parent
0b50715fb3
commit
f9b34fd40d
@ -42,7 +42,7 @@ data class KeyCharAndCode(val char: Char, val code: Int) {
|
|||||||
return when {
|
return when {
|
||||||
char == Char.MIN_VALUE -> fixedKeysToString(code)
|
char == Char.MIN_VALUE -> fixedKeysToString(code)
|
||||||
this == ESC -> "ESC"
|
this == ESC -> "ESC"
|
||||||
char < ' ' -> "Ctrl-" + Char(char.code+64)
|
char < ' ' -> "Ctrl-" + (char.toCode() + 64).makeChar()
|
||||||
else -> "\"$char\""
|
else -> "\"$char\""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,16 +63,18 @@ data class KeyCharAndCode(val char: Char, val code: Int) {
|
|||||||
/** Guaranteed to be ignored by [KeyPressDispatcher.set] and never to be generated for an actual event, used as fallback to ensure no action is taken */
|
/** Guaranteed to be ignored by [KeyPressDispatcher.set] and never to be generated for an actual event, used as fallback to ensure no action is taken */
|
||||||
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)'
|
||||||
|
private fun Char.toCode() =
|
||||||
|
try { code } catch (ex: Throwable) { null }
|
||||||
|
?: try { @Suppress("DEPRECATION") toInt() } catch (ex: Throwable) { null }
|
||||||
|
?: 0
|
||||||
|
private fun Int.makeChar() =
|
||||||
|
try { Char(this) } catch (ex: Throwable) { null }
|
||||||
|
?: try { toChar() } catch (ex: Throwable) { null }
|
||||||
|
?: Char.MIN_VALUE
|
||||||
|
|
||||||
/** mini-factory for control codes - case insensitive */
|
/** mini-factory for control codes - case insensitive */
|
||||||
fun ctrl(letter: Char) = KeyCharAndCode(Char(
|
fun ctrl(letter: Char) = KeyCharAndCode((letter.toCode() and 31).makeChar(),0)
|
||||||
try {
|
|
||||||
letter.code and 31
|
|
||||||
} catch (ex: NoSuchMethodError) {
|
|
||||||
// Seems to happen on some Ubuntu systems
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
letter.toInt() and 31
|
|
||||||
}
|
|
||||||
), 0)
|
|
||||||
|
|
||||||
/** mini-factory for control codes from keyCodes */
|
/** mini-factory for control codes from keyCodes */
|
||||||
fun ctrlFromCode(keyCode: Int): KeyCharAndCode {
|
fun ctrlFromCode(keyCode: Int): KeyCharAndCode {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user