mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 19:35:00 -04:00
fix double press key combination, tests
Now we can fly again!
This commit is contained in:
parent
b5bb290727
commit
8ccb362ef6
@ -26,20 +26,27 @@ import de.bixilon.minosoft.gui.rendering.input.key.manager.binding.KeyBindingFil
|
|||||||
import de.bixilon.minosoft.gui.rendering.input.key.manager.binding.KeyBindingState
|
import de.bixilon.minosoft.gui.rendering.input.key.manager.binding.KeyBindingState
|
||||||
import de.bixilon.minosoft.test.IT.OBJENESIS
|
import de.bixilon.minosoft.test.IT.OBJENESIS
|
||||||
import de.bixilon.minosoft.util.KUtil.set
|
import de.bixilon.minosoft.util.KUtil.set
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2LongMap
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap
|
||||||
import org.testng.Assert.assertFalse
|
import org.testng.Assert.assertFalse
|
||||||
import org.testng.Assert.assertTrue
|
import org.testng.Assert.assertTrue
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
|
|
||||||
|
val times = InputManager::class.java.getDeclaredField("times").apply { isAccessible = true }
|
||||||
val keysPressed = InputManager::class.java.getDeclaredField("pressed").apply { isAccessible = true }
|
val keysPressed = InputManager::class.java.getDeclaredField("pressed").apply { isAccessible = true }
|
||||||
val bindingsPressed = BindingsManager::class.java.getDeclaredField("pressed").apply { isAccessible = true }
|
val bindingsPressed = BindingsManager::class.java.getDeclaredField("pressed").apply { isAccessible = true }
|
||||||
val name = minosoft("dummy")
|
val name = minosoft("dummy")
|
||||||
|
|
||||||
|
val InputManager.times: Object2LongMap<KeyCodes> get() = de.bixilon.minosoft.gui.rendering.input.key.manager.binding.actions.times.get(this).unsafeCast()
|
||||||
|
|
||||||
|
|
||||||
fun input(): InputManager {
|
fun input(): InputManager {
|
||||||
val manager = OBJENESIS.newInstance(InputManager::class.java)
|
val manager = OBJENESIS.newInstance(InputManager::class.java)
|
||||||
val bindings = OBJENESIS.newInstance(BindingsManager::class.java)
|
val bindings = OBJENESIS.newInstance(BindingsManager::class.java)
|
||||||
bindingsPressed[bindings] = mutableSetOf<ResourceLocation>()
|
bindingsPressed[bindings] = mutableSetOf<ResourceLocation>()
|
||||||
manager::bindings.forceSet(bindings)
|
manager::bindings.forceSet(bindings)
|
||||||
|
times[manager] = Object2LongOpenHashMap<KeyCodes>()
|
||||||
|
|
||||||
keysPressed[manager] = KeyCodes.set()
|
keysPressed[manager] = KeyCodes.set()
|
||||||
|
|
||||||
@ -353,3 +360,93 @@ class Sticky {
|
|||||||
assertTrue(state.satisfied)
|
assertTrue(state.satisfied)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test(groups = ["input"])
|
||||||
|
class DoublePress {
|
||||||
|
|
||||||
|
fun `press single`() {
|
||||||
|
val state = KeyBindingFilterState(false)
|
||||||
|
KeyActionFilter.DoublePress.check(
|
||||||
|
state, setOf(KeyCodes.KEY_0), input(), name,
|
||||||
|
KeyBindingState(KeyBinding(mapOf(KeyActions.DOUBLE_PRESS to setOf(KeyCodes.KEY_0)))),
|
||||||
|
KeyCodes.KEY_0,
|
||||||
|
pressed = true,
|
||||||
|
0L,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertFalse(state.satisfied)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `double press`() {
|
||||||
|
val state = KeyBindingFilterState(false)
|
||||||
|
val input = input()
|
||||||
|
input.times.put(KeyCodes.KEY_0, 1000L)
|
||||||
|
|
||||||
|
KeyActionFilter.DoublePress.check(
|
||||||
|
state, setOf(KeyCodes.KEY_0), input, name,
|
||||||
|
KeyBindingState(KeyBinding(mapOf(KeyActions.DOUBLE_PRESS to setOf(KeyCodes.KEY_0)))),
|
||||||
|
KeyCodes.KEY_0,
|
||||||
|
pressed = true,
|
||||||
|
1100L,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(state.satisfied)
|
||||||
|
assertTrue(state.result)
|
||||||
|
assertTrue(state.store)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `double press second time`() {
|
||||||
|
val state = KeyBindingFilterState(false)
|
||||||
|
val input = input()
|
||||||
|
|
||||||
|
val pressed = bindingsPressed[input.bindings].unsafeCast<MutableSet<ResourceLocation>>()
|
||||||
|
pressed += name
|
||||||
|
|
||||||
|
input.times.put(KeyCodes.KEY_0, 1000L)
|
||||||
|
|
||||||
|
KeyActionFilter.DoublePress.check(
|
||||||
|
state, setOf(KeyCodes.KEY_0), input, name,
|
||||||
|
KeyBindingState(KeyBinding(mapOf(KeyActions.DOUBLE_PRESS to setOf(KeyCodes.KEY_0)))),
|
||||||
|
KeyCodes.KEY_0,
|
||||||
|
pressed = true,
|
||||||
|
1100L,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(state.satisfied)
|
||||||
|
assertFalse(state.result)
|
||||||
|
assertTrue(state.store)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `too long ago press`() {
|
||||||
|
val state = KeyBindingFilterState(false)
|
||||||
|
val input = input()
|
||||||
|
input.times.put(KeyCodes.KEY_0, 1000L)
|
||||||
|
|
||||||
|
KeyActionFilter.DoublePress.check(
|
||||||
|
state, setOf(KeyCodes.KEY_0), input, name,
|
||||||
|
KeyBindingState(KeyBinding(mapOf(KeyActions.DOUBLE_PRESS to setOf(KeyCodes.KEY_0)))),
|
||||||
|
KeyCodes.KEY_0,
|
||||||
|
pressed = true,
|
||||||
|
10000L,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertFalse(state.satisfied)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `delay between`() {
|
||||||
|
val state = KeyBindingFilterState(false)
|
||||||
|
val input = input()
|
||||||
|
input.times.put(KeyCodes.KEY_0, 10L)
|
||||||
|
|
||||||
|
KeyActionFilter.DoublePress.check(
|
||||||
|
state, setOf(KeyCodes.KEY_0), input, name,
|
||||||
|
KeyBindingState(KeyBinding(mapOf(KeyActions.DOUBLE_PRESS to setOf(KeyCodes.KEY_0)))),
|
||||||
|
KeyCodes.KEY_0,
|
||||||
|
pressed = true,
|
||||||
|
100L,
|
||||||
|
)
|
||||||
|
|
||||||
|
assertFalse(state.satisfied)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -118,7 +118,7 @@ interface KeyActionFilter {
|
|||||||
filter.satisfied = false
|
filter.satisfied = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
filter.result = input.bindings.isDown(name)
|
filter.result = !input.bindings.isDown(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user