MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / Buttons

Class Buttons

src/main/java/field/graphics/vr/Buttons.kt:7–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5import java.util.ArrayList
6import java.util.function.Supplier
7
8class Buttons(init: (Buttons) -> Unit) : Runnable {
9
10 // a button is just an axis
11 val axesMap: MutableMap<String, Number> = mutableMapOf();
12
13 // callbacks
14 val down: MutableMap<String, IdempotencyMap<Supplier<Boolean>>> = mutableMapOf()
15 val up: MutableMap<String, IdempotencyMap<Supplier<Boolean>>> = mutableMapOf()
16
17 private val lastDown: MutableSet<String> = mutableSetOf()
18
19 var slop = 0.01f
20
21 init {
22 init(this)
23 }
24
25 override fun run() {
26
27 val currentDown = axesMap.entries.filter { abs(it.value.toDouble()) > slop }.map { it.key }.toSet()
28
29 if (currentDown.size>0)
30 println("current : "+currentDown)
31
32 val downEvents = LinkedHashSet<String>(currentDown)
33 downEvents.removeAll(lastDown)
34 downEvents.map { down[it] }.filter { it != null }.map { it!!.values }.forEach {
35
36 println(" running callbacks for $it")
37
38 it.removeIf { v ->
39 println(" running callback $v")
40 !v.get()
41 }
42 }
43
44 if (downEvents.size>0)
45 println("down :"+downEvents)
46
47 val upEvents = LinkedHashSet<String>(lastDown)
48 upEvents.removeAll(currentDown)
49 upEvents.map { up[it] }.filter { it != null }.map { it!!.values }.forEach {
50 it.removeIf { v -> !v.get() }
51 }
52
53 if (upEvents.size>0)
54 println("up :"+upEvents)
55
56 lastDown.clear()
57 lastDown.addAll(currentDown);
58
59 }
60
61 fun setAxis(name: String, value: Number) {
62 axesMap[name] = value
63 }
64

Callers 1

OpenVRDrawTargetClass · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected