diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-11-17 19:55:02 +0100 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-11-17 19:55:02 +0100 |
| commit | c93a04a001b0f66b2724d46b04b6d1ed49a08d07 (patch) | |
| tree | 5869ca70acc482ef0362f27785c3d3f1cbb9ffae /src/main/kotlin/keybindings | |
| parent | af9893b59407c69d31ebd2ed513f0396ab4d2dc9 (diff) | |
| download | Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.gz Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.bz2 Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.zip | |
refactor: port to mojmaps
Diffstat (limited to 'src/main/kotlin/keybindings')
4 files changed, 51 insertions, 51 deletions
diff --git a/src/main/kotlin/keybindings/FirmamentKeyBindings.kt b/src/main/kotlin/keybindings/FirmamentKeyBindings.kt index fe87eff..c0fe995 100644 --- a/src/main/kotlin/keybindings/FirmamentKeyBindings.kt +++ b/src/main/kotlin/keybindings/FirmamentKeyBindings.kt @@ -1,18 +1,18 @@ package moe.nea.firmament.keybindings import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper -import net.minecraft.client.option.KeyBinding -import net.minecraft.client.util.InputUtil +import net.minecraft.client.KeyMapping +import com.mojang.blaze3d.platform.InputConstants import moe.nea.firmament.Firmament import moe.nea.firmament.gui.config.ManagedOption import moe.nea.firmament.util.TestUtil object FirmamentKeyBindings { - val cat = KeyBinding.Category(Firmament.identifier("category")) + val cat = KeyMapping.Category(Firmament.identifier("category")) fun registerKeyBinding(name: String, config: ManagedOption<SavedKeyBinding>) { - val vanillaKeyBinding = KeyBinding( + val vanillaKeyBinding = KeyMapping( name, - InputUtil.Type.KEYSYM, + InputConstants.Type.KEYSYM, -1, cat ) @@ -22,6 +22,6 @@ object FirmamentKeyBindings { keyBindings[vanillaKeyBinding] = config } - val keyBindings = mutableMapOf<KeyBinding, ManagedOption<SavedKeyBinding>>() + val keyBindings = mutableMapOf<KeyMapping, ManagedOption<SavedKeyBinding>>() } diff --git a/src/main/kotlin/keybindings/FirmamentKeyboardState.kt b/src/main/kotlin/keybindings/FirmamentKeyboardState.kt index dc20630..da94a44 100644 --- a/src/main/kotlin/keybindings/FirmamentKeyboardState.kt +++ b/src/main/kotlin/keybindings/FirmamentKeyboardState.kt @@ -2,7 +2,7 @@ package moe.nea.firmament.keybindings import java.util.BitSet import org.lwjgl.glfw.GLFW -import net.minecraft.client.input.KeyInput +import net.minecraft.client.input.KeyEvent object FirmamentKeyboardState { @@ -15,7 +15,7 @@ object FirmamentKeyboardState { } @Synchronized - fun maintainState(keyInput: KeyInput, action: Int) { + fun maintainState(keyInput: KeyEvent, action: Int) { when (action) { GLFW.GLFW_PRESS -> pressedScancodes.set(keyInput.scancode) GLFW.GLFW_RELEASE -> pressedScancodes.clear(keyInput.scancode) diff --git a/src/main/kotlin/keybindings/GenericInputButton.kt b/src/main/kotlin/keybindings/GenericInputButton.kt index 3876573..4a4aaba 100644 --- a/src/main/kotlin/keybindings/GenericInputButton.kt +++ b/src/main/kotlin/keybindings/GenericInputButton.kt @@ -13,14 +13,14 @@ import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.int import kotlinx.serialization.json.put -import net.minecraft.client.MinecraftClient -import net.minecraft.client.gui.Click -import net.minecraft.client.input.AbstractInput -import net.minecraft.client.input.KeyInput -import net.minecraft.client.input.MouseInput -import net.minecraft.client.util.InputUtil -import net.minecraft.client.util.MacWindowUtil -import net.minecraft.text.Text +import net.minecraft.client.Minecraft +import net.minecraft.client.input.MouseButtonEvent +import net.minecraft.client.input.InputWithModifiers +import net.minecraft.client.input.KeyEvent +import net.minecraft.client.input.MouseButtonInfo +import com.mojang.blaze3d.platform.InputConstants +import com.mojang.blaze3d.platform.MacosUtil +import net.minecraft.network.chat.Component import moe.nea.firmament.util.MC import moe.nea.firmament.util.mc.InitLevel @@ -65,7 +65,7 @@ sealed interface GenericInputButton { companion object { - fun of(event: KeyInput) = ofKeyAndScan(event.keycode, event.scancode) + fun of(event: KeyEvent) = ofKeyAndScan(event.input(), event.scancode) fun escape() = ofKeyCode(GLFW.GLFW_KEY_ESCAPE) fun ofKeyCode(keyCode: Int): GenericInputButton = KeyCodeButton(keyCode) fun ofScanCode(scanCode: Int): GenericInputButton = ScanCodeButton(scanCode) @@ -80,8 +80,8 @@ sealed interface GenericInputButton { } data object Unbound : GenericInputButton { - override fun toInputKey(): InputUtil.Key { - return InputUtil.UNKNOWN_KEY + override fun toInputKey(): InputConstants.Key { + return InputConstants.UNKNOWN } override fun isBound(): Boolean { @@ -96,24 +96,24 @@ sealed interface GenericInputButton { data class MouseButton( val mouseButton: Int ) : GenericInputButton { - override fun toInputKey(): InputUtil.Key { - return InputUtil.Type.MOUSE.createFromCode(mouseButton) + override fun toInputKey(): InputConstants.Key { + return InputConstants.Type.MOUSE.getOrCreate(mouseButton) } override fun isPressed(): Boolean { - return GLFW.glfwGetMouseButton(MC.window.handle, mouseButton) == GLFW.GLFW_PRESS + return GLFW.glfwGetMouseButton(MC.window.handle(), mouseButton) == GLFW.GLFW_PRESS } } data class KeyCodeButton( val keyCode: Int ) : GenericInputButton { - override fun toInputKey(): InputUtil.Key { - return InputUtil.Type.KEYSYM.createFromCode(keyCode) + override fun toInputKey(): InputConstants.Key { + return InputConstants.Type.KEYSYM.getOrCreate(keyCode) } override fun isPressed(): Boolean { - return InputUtil.isKeyPressed(MC.window, keyCode) + return InputConstants.isKeyDown(MC.window, keyCode) } override fun isCtrl(): Boolean { @@ -136,8 +136,8 @@ sealed interface GenericInputButton { data class ScanCodeButton( val scanCode: Int ) : GenericInputButton { - override fun toInputKey(): InputUtil.Key { - return InputUtil.Type.SCANCODE.createFromCode(scanCode) + override fun toInputKey(): InputConstants.Key { + return InputConstants.Type.SCANCODE.getOrCreate(scanCode) } override fun isPressed(): Boolean { @@ -153,12 +153,12 @@ sealed interface GenericInputButton { fun isSuper() = false fun isShift() = false - fun toInputKey(): InputUtil.Key - fun format(): Text = + fun toInputKey(): InputConstants.Key + fun format(): Component = if (InitLevel.isAtLeast(InitLevel.RENDER_INIT)) { - toInputKey().localizedText + toInputKey().displayName } else { - Text.of(toString()) + Component.nullToEmpty(toString()) } fun matches(inputAction: GenericInputAction) = inputAction.matches(this) @@ -194,12 +194,12 @@ sealed interface GenericInputAction { fun mouse(mouseButton: Int): GenericInputAction = MouseInput(mouseButton) @JvmStatic - fun mouse(click: Click): GenericInputAction = mouse(click.button()) + fun mouse(click: MouseButtonEvent): GenericInputAction = mouse(click.button()) @JvmStatic - fun of(input: net.minecraft.client.input.MouseInput): GenericInputAction = mouse(input.button) + fun of(input: net.minecraft.client.input.MouseButtonInfo): GenericInputAction = mouse(input.button) @JvmStatic - fun of(input: KeyInput): GenericInputAction = key(input.keycode, input.scancode) + fun of(input: KeyEvent): GenericInputAction = key(input.input(), input.scancode) @JvmStatic fun key(keyCode: Int, scanCode: Int): GenericInputAction = KeyboardInput(keyCode, scanCode) @@ -214,19 +214,19 @@ data class InputModifiers( @JvmStatic fun current(): InputModifiers { val h = MC.window - val ctrl = if (MacWindowUtil.IS_MAC) { - InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SUPER) - || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SUPER) - } else InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_CONTROL) - || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_CONTROL) - val shift = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SHIFT) || InputUtil.isKeyPressed( + val ctrl = if (MacosUtil.IS_MACOS) { + InputConstants.isKeyDown(h, GLFW.GLFW_KEY_LEFT_SUPER) + || InputConstants.isKeyDown(h, GLFW.GLFW_KEY_RIGHT_SUPER) + } else InputConstants.isKeyDown(h, GLFW.GLFW_KEY_LEFT_CONTROL) + || InputConstants.isKeyDown(h, GLFW.GLFW_KEY_RIGHT_CONTROL) + val shift = InputConstants.isKeyDown(h, GLFW.GLFW_KEY_LEFT_SHIFT) || InputConstants.isKeyDown( h, GLFW.GLFW_KEY_RIGHT_SHIFT ) - val alt = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_ALT) - || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_ALT) - val `super` = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SUPER) - || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SUPER) + val alt = InputConstants.isKeyDown(h, GLFW.GLFW_KEY_LEFT_ALT) + || InputConstants.isKeyDown(h, GLFW.GLFW_KEY_RIGHT_ALT) + val `super` = InputConstants.isKeyDown(h, GLFW.GLFW_KEY_LEFT_SUPER) + || InputConstants.isKeyDown(h, GLFW.GLFW_KEY_RIGHT_SUPER) return of( ctrl = ctrl, shift = shift, @@ -237,7 +237,7 @@ data class InputModifiers( val superKeys = listOf(GLFW.GLFW_KEY_LEFT_SUPER, GLFW.GLFW_KEY_RIGHT_SUPER) - val controlKeys = if (MacWindowUtil.IS_MAC) { + val controlKeys = if (MacosUtil.IS_MACOS) { listOf(GLFW.GLFW_KEY_LEFT_SUPER, GLFW.GLFW_KEY_RIGHT_SUPER) } else { listOf(GLFW.GLFW_KEY_LEFT_CONTROL, GLFW.GLFW_KEY_RIGHT_CONTROL) @@ -280,7 +280,7 @@ data class InputModifiers( fun of(modifiers: Int) = InputModifiers(modifiers) @JvmStatic - fun of(input: AbstractInput) = InputModifiers(input.modifiers()) + fun of(input: InputWithModifiers) = InputModifiers(input.modifiers()) fun none(): InputModifiers { return InputModifiers(0) @@ -325,8 +325,8 @@ data class InputModifiers( return this == other } - fun format(): Text { // TODO: translation for mods - return Text.of(toString()) + fun format(): Component { // TODO: translation for mods + return Component.nullToEmpty(toString()) } } diff --git a/src/main/kotlin/keybindings/SavedKeyBinding.kt b/src/main/kotlin/keybindings/SavedKeyBinding.kt index 8f08e5f..91d88ca 100644 --- a/src/main/kotlin/keybindings/SavedKeyBinding.kt +++ b/src/main/kotlin/keybindings/SavedKeyBinding.kt @@ -1,7 +1,7 @@ package moe.nea.firmament.keybindings import kotlinx.serialization.Serializable -import net.minecraft.text.Text +import net.minecraft.network.chat.Component @Serializable data class SavedKeyBinding( @@ -30,8 +30,8 @@ data class SavedKeyBinding( return format().string } - fun format(): Text { - val stroke = Text.empty() + fun format(): Component { + val stroke = Component.empty() if (!modifiers.isEmpty()) { stroke.append(modifiers.format()) stroke.append(" + ") |
