mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 02:45:13 -04:00
fix some key bugs
This commit is contained in:
parent
1c6f1b4b9a
commit
3babe28375
@ -86,15 +86,25 @@ class BindingManagerTest {
|
||||
assertEquals(b, 1)
|
||||
}
|
||||
|
||||
fun `check binding`() {
|
||||
fun `check press binding`() {
|
||||
val input = create()
|
||||
|
||||
input.bindings.registerCheck(dummy to KeyBinding(mapOf(KeyActions.PRESS to setOf(KeyCodes.KEY_1))))
|
||||
assertFalse(input.bindings.isDown(dummy))
|
||||
input.simulate(KeyCodes.KEY_1, KeyChangeTypes.PRESS)
|
||||
assertFalse(input.bindings.isDown(dummy))
|
||||
}
|
||||
|
||||
fun `check change binding`() {
|
||||
val input = create()
|
||||
|
||||
input.bindings.registerCheck(dummy to KeyBinding(mapOf(KeyActions.CHANGE to setOf(KeyCodes.KEY_1))))
|
||||
assertFalse(input.bindings.isDown(dummy))
|
||||
input.simulate(KeyCodes.KEY_1, KeyChangeTypes.PRESS)
|
||||
assertTrue(input.bindings.isDown(dummy))
|
||||
}
|
||||
|
||||
|
||||
fun `ignore if consumer is set`() {
|
||||
val input = create()
|
||||
|
||||
|
@ -173,7 +173,6 @@ class Change {
|
||||
)
|
||||
|
||||
assertTrue(state.satisfied)
|
||||
assertTrue(state.forceNotify)
|
||||
}
|
||||
|
||||
fun `simple release`() {
|
||||
@ -187,7 +186,6 @@ class Change {
|
||||
)
|
||||
|
||||
assertTrue(state.satisfied)
|
||||
assertTrue(state.forceNotify)
|
||||
}
|
||||
|
||||
fun `wrong key`() {
|
||||
@ -201,7 +199,6 @@ class Change {
|
||||
)
|
||||
|
||||
assertFalse(state.satisfied)
|
||||
assertFalse(state.forceNotify)
|
||||
}
|
||||
|
||||
fun `multiple keys`() {
|
||||
@ -215,7 +212,6 @@ class Change {
|
||||
)
|
||||
|
||||
assertTrue(state.satisfied)
|
||||
assertTrue(state.forceNotify)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,13 +31,13 @@ class InteractionManagerKeys(
|
||||
|
||||
private fun registerAttack() {
|
||||
input.bindings.register(ATTACK, KeyBinding(
|
||||
KeyActions.CHANGE to setOf(KeyCodes.MOUSE_BUTTON_LEFT),
|
||||
KeyActions.PRESS to setOf(KeyCodes.MOUSE_BUTTON_LEFT),
|
||||
)) { interactions.tryAttack(it) }
|
||||
}
|
||||
|
||||
private fun registerInteraction() {
|
||||
input.bindings.register(USE_ITEM, KeyBinding(
|
||||
KeyActions.CHANGE to setOf(KeyCodes.MOUSE_BUTTON_RIGHT),
|
||||
KeyActions.PRESS to setOf(KeyCodes.MOUSE_BUTTON_RIGHT),
|
||||
)) { interactions.use.change(it) }
|
||||
}
|
||||
|
||||
|
@ -83,21 +83,21 @@ class BindingsManager(
|
||||
if (!filterState.satisfied) return
|
||||
|
||||
val previous = name in this
|
||||
if (previous == filterState.result && !filterState.forceNotify) return
|
||||
if (previous == filterState.result) return
|
||||
|
||||
for (callback in state.callback) {
|
||||
callback(filterState.result)
|
||||
}
|
||||
if (previous == filterState.result) return
|
||||
|
||||
state.lastChange = millis
|
||||
|
||||
if (!filterState.store) return
|
||||
|
||||
if (filterState.result) {
|
||||
this.pressed += name
|
||||
} else {
|
||||
this.pressed -= name
|
||||
}
|
||||
// skipCharPress = true
|
||||
}
|
||||
|
||||
fun onKey(code: KeyCodes, pressed: Boolean, millis: Long) {
|
||||
|
@ -16,5 +16,5 @@ package de.bixilon.minosoft.gui.rendering.input.key.manager.binding
|
||||
data class KeyBindingFilterState(
|
||||
var result: Boolean,
|
||||
var satisfied: Boolean = true,
|
||||
var forceNotify: Boolean = false,
|
||||
var store: Boolean = true,
|
||||
)
|
||||
|
@ -29,30 +29,34 @@ interface KeyActionFilter {
|
||||
object Press : KeyActionFilter {
|
||||
|
||||
override fun check(filter: KeyBindingFilterState, codes: Set<KeyCodes>, input: InputManager, name: ResourceLocation, state: KeyBindingState, code: KeyCodes, pressed: Boolean, millis: Long) {
|
||||
if (code in codes) return
|
||||
if (!pressed || code !in codes) {
|
||||
filter.satisfied = false
|
||||
return
|
||||
}
|
||||
|
||||
filter.satisfied = false
|
||||
filter.store = false
|
||||
}
|
||||
}
|
||||
|
||||
object Release : KeyActionFilter {
|
||||
|
||||
override fun check(filter: KeyBindingFilterState, codes: Set<KeyCodes>, input: InputManager, name: ResourceLocation, state: KeyBindingState, code: KeyCodes, pressed: Boolean, millis: Long) {
|
||||
if (code in codes) return
|
||||
if (pressed || code !in codes) {
|
||||
filter.satisfied = false
|
||||
return
|
||||
}
|
||||
|
||||
filter.satisfied = false
|
||||
filter.result = true
|
||||
filter.store = false
|
||||
}
|
||||
}
|
||||
|
||||
object Change : KeyActionFilter {
|
||||
|
||||
override fun check(filter: KeyBindingFilterState, codes: Set<KeyCodes>, input: InputManager, name: ResourceLocation, state: KeyBindingState, code: KeyCodes, pressed: Boolean, millis: Long) {
|
||||
if (code !in codes) {
|
||||
filter.satisfied = false
|
||||
return
|
||||
}
|
||||
if (code in codes) return
|
||||
|
||||
filter.forceNotify = true
|
||||
filter.satisfied = false
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user