Skip to content

Commit d99d1e7

Browse files
committed
GLFW sucks
1 parent 242d78e commit d99d1e7

File tree

8 files changed

+21
-21
lines changed

8 files changed

+21
-21
lines changed

common/src/main/kotlin/com/lambda/config/serializer/KeyCodeSerializer.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.lambda.config.serializer
22

33
import com.google.gson.*
44
import com.lambda.util.KeyCode
5-
import com.lambda.util.primitives.extension.displayValue
65
import java.lang.reflect.Type
76

87
object KeyCodeSerializer : JsonSerializer<KeyCode>, JsonDeserializer<KeyCode> {
@@ -12,13 +11,13 @@ object KeyCodeSerializer : JsonSerializer<KeyCode>, JsonDeserializer<KeyCode> {
1211
context: JsonSerializationContext?,
1312
): JsonElement =
1413
src?.let {
15-
JsonPrimitive(it.displayValue)
14+
JsonPrimitive(it.name)
1615
} ?: JsonNull.INSTANCE
1716

1817
override fun deserialize(
1918
json: JsonElement?,
2019
typeOfT: Type?,
2120
context: JsonDeserializationContext?,
2221
): KeyCode =
23-
json?.asString?.let(KeyCode::byNameOrNull) ?: throw JsonParseException("Invalid key code format")
22+
json?.asString?.let(KeyCode::fromNameOrNull) ?: throw JsonParseException("Invalid key code format")
2423
}

common/src/main/kotlin/com/lambda/gui/api/LambdaGui.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ abstract class LambdaGui(
8080
}
8181

8282
final override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
83-
KeyCode.byIdOrNull(keyCode)?.let {
83+
KeyCode.fromKeyCodeOrNull(keyCode)?.let {
8484
onEvent(GuiEvent.KeyPress(it))
8585
}
8686

87-
if (keyCode == KeyCode.Escape.key) {
87+
if (keyCode == KeyCode.Escape.keyCode) {
8888
close()
8989
}
9090

common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/BIndButton.kt renamed to common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/setting/BindButton.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.lambda.gui.impl.clickgui.buttons.ModuleButton
99
import com.lambda.gui.impl.clickgui.buttons.SettingButton
1010
import com.lambda.util.KeyCode
1111
import com.lambda.util.math.ColorUtils.multAlpha
12-
import com.lambda.util.primitives.extension.displayValue
1312

1413
class BindButton(
1514
setting: KeyBindSetting,
@@ -23,7 +22,7 @@ class BindButton(
2322
override val showAnimation get() = this@BindButton.showAnimation
2423
override val isKeyBind = true
2524

26-
override fun getText() = value.displayValue
25+
override fun getText() = value.localizedName
2726
override fun setKeyValue(key: KeyCode) { value = key }
2827
}.apply(layer::addChild)
2928

common/src/main/kotlin/com/lambda/module/Module.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ abstract class Module(
109109
init {
110110
listener<KeyPressEvent>(alwaysListen = true) { event ->
111111
val screen = mc.currentScreen
112-
if (event.key == keybind.key
112+
if (event.key == keybind.keyCode
113113
&& !mc.options.commandKey.isPressed
114114
&& (screen == null
115115
|| screen is LambdaClickGui)

common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ object Replay : Module(
9999
if (mc.currentScreen != null && !mc.options.commandKey.isPressed) return@listener
100100

101101
when (it.key) {
102-
record.key -> handleRecord()
103-
play.key -> handlePlay()
104-
cycle.key -> handlePlayModeCycle()
105-
check.key -> handleCheckpoint()
102+
record.keyCode -> handleRecord()
103+
play.keyCode -> handlePlay()
104+
cycle.keyCode -> handlePlayModeCycle()
105+
check.keyCode -> handleCheckpoint()
106106
else -> {}
107107
}
108108
}

common/src/main/kotlin/com/lambda/module/modules/render/XRay.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ object XRay : Module(
2323
Blocks.ANCIENT_DEBRIS
2424
)
2525

26-
private val selection by setting("Block Selection", defaultBlocks, "Block selection that will be shown (whitelist) or hidden (blacklist)")
26+
// private val selection by setting("Block Selection", defaultBlocks, "Block selection that will be shown (whitelist) or hidden (blacklist)")
2727
private val mode by setting("Selection Mode", Selection.WHITELIST, "The mode of the block selection")
2828

2929
@JvmStatic fun isSelected(blockState: BlockState) = mode.select(blockState)
3030

3131
enum class Selection(val select: (BlockState) -> Boolean) {
32-
WHITELIST({ it.block in selection }),
33-
BLACKLIST({ it.block !in selection })
32+
WHITELIST({ it.block in defaultBlocks }),
33+
BLACKLIST({ it.block !in defaultBlocks })
3434
}
3535

3636
init {

common/src/main/kotlin/com/lambda/util/Communication.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ object Communication {
127127
literal("\n")
128128
literal("Keybind: ")
129129
color(GuiSettings.primaryColor) {
130-
literal(module.keybind.key.toString())
130+
literal(module.keybind.keyCode.toString())
131131
}
132132
literal("\n")
133133
literal("Default tags: ")

common/src/main/kotlin/com/lambda/util/KeyCode.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.lambda.util
33
import com.lambda.util.primitives.extension.displayValue
44
import org.lwjgl.glfw.GLFW
55

6-
enum class KeyCode(val key: Int) {
6+
enum class KeyCode(val keyCode: Int) {
77
Unbound(GLFW.GLFW_KEY_UNKNOWN),
88
Space(GLFW.GLFW_KEY_SPACE),
99
Apostrophe(GLFW.GLFW_KEY_APOSTROPHE),
@@ -127,11 +127,13 @@ enum class KeyCode(val key: Int) {
127127
MENU(GLFW.GLFW_KEY_MENU),
128128
LAST(GLFW.GLFW_KEY_LAST);
129129

130+
val localizedName by lazy { GLFW.glfwGetKeyName(keyCode, 0)?.uppercase() ?: displayValue }
131+
130132
companion object {
131-
fun byIdOrNull(key: Int) = entries.firstOrNull { it.key == key }
132-
fun byId(key: Int) = byIdOrNull(key) ?: Unbound
133+
fun fromKeyCodeOrNull(keyCode: Int) = entries.firstOrNull { it.keyCode == keyCode }
134+
fun fromKeyCode(keyCode: Int) = fromKeyCodeOrNull(keyCode) ?: Unbound
133135

134-
fun byNameOrNull(name: String) = entries.firstOrNull { it.displayValue.equals(name, true) }
135-
fun byName(name: String) = byNameOrNull(name) ?: Unbound
136+
fun fromNameOrNull(name: String) = entries.firstOrNull { it.name.equals(name, true) }
137+
fun fromName(name: String) = fromNameOrNull(name) ?: Unbound
136138
}
137139
}

0 commit comments

Comments
 (0)