mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-06 08:42:32 -08:00
Add ResetTrackerAssignments
This commit is contained in:
2 files changed
+32
-1
No files matched your search
@@ -1,11 +1,14 @@
|
||||
package dev.slimevr.solarxr
|
||||
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.skeleton.bodyPartMap
|
||||
import dev.slimevr.tracker.Tracker
|
||||
import dev.slimevr.tracker.TrackerActions
|
||||
import dev.slimevr.util.isActive
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.rpc.AssignTrackerRequest
|
||||
import solarxr_protocol.rpc.ResetTrackerAssignments
|
||||
|
||||
class AssignTrackerBehaviour(
|
||||
private val server: VRServer,
|
||||
@@ -46,5 +49,33 @@ class AssignTrackerBehaviour(
|
||||
)
|
||||
}
|
||||
}.launchIn(receiver.context.scope)
|
||||
|
||||
receiver.rpcDispatcher.on<ResetTrackerAssignments> {
|
||||
val trackers = server.context.state.value.trackers.values
|
||||
val intendedBodyParts = bodyPartMap<Tracker>()
|
||||
|
||||
// First unassign all trackers so that we don't have conflicts.
|
||||
trackers.forEach { tracker ->
|
||||
val intendedBodyPart = tracker.context.state.value.intendedBodyPart
|
||||
intendedBodyParts.putIfAbsent(intendedBodyPart, tracker)
|
||||
|
||||
tracker.context.dispatch(
|
||||
TrackerActions.Update {
|
||||
copy(bodyPart = null)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// Then re-assign trackers with intended body parts, using the map to ensure
|
||||
// we don't try to assign two trackers to the same body part if there were
|
||||
// multiple with the same intended body part.
|
||||
intendedBodyParts.forEach { (bodyPart, tracker) ->
|
||||
tracker.context.dispatch(
|
||||
TrackerActions.Update {
|
||||
copy(bodyPart = bodyPart)
|
||||
},
|
||||
)
|
||||
}
|
||||
}.launchIn(receiver.context.scope)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user