Started keeping track of masks for #2

This commit is contained in:
2026-06-04 03:40:05 +01:00
parent 7fd622b331
commit 33fee44e63

View File

@ -12,6 +12,15 @@ from watchdog.observers import Observer
from pythonosc import udp_client
import watchdog.events
_ADDR_TO_MASK = {
'/usercamera/ShowUIInCamera': 'UI',
'/usercamera/LocalPlayer': 'LOCAL_PLAYER',
'/usercamera/RemotePlayer': 'REMOTE_PLAYER',
'/usercamera/Environment': 'ENVIRONMENT',
}
_MASK_TO_ADDR = {value: key for key, value in _ADDR_TO_MASK.items()}
class NewPictureHandler(watchdog.events.FileSystemEventHandler):
"""
Watches for new pictures in the VRChat camera folder.
@ -88,8 +97,15 @@ class Camera:
self._newPictureObserver = createNewPictureObserver(self._newPicture)
self._multiPictureOngoing = False
self._onEnabledCallback = onCameraEnabled
self._masks = {'UI': False}
dispatcher.map('/usercamera/Mode', self._onModeChange)
# Map all mask addresses to self._onMaskChange
# and populate any missing mask IDs in self._masks with True.
for address, maskID in _ADDR_TO_MASK.items():
dispatcher.map(address, self._onMaskChange)
if maskID not in self._masks:
self._masks.update({maskID: True})
def close(self):
"""
@ -133,7 +149,20 @@ class Camera:
if enabledFlag:
self._onCameraEnabled()
def _onMaskChange(self, address: str, value: bool):
"""
Gets called when any mask is changed.
"""
mask = _ADDR_TO_MASK[address]
self._masks[mask] = value
def _onCameraEnabled(self):
# Ensure the VRChat camera's masks match our own
for maskID, value in self._masks.items():
address = _MASK_TO_ADDR[maskID]
self.oscClient.send_message(address, value)
if self._onEnabledCallback is not None:
self._onEnabledCallback(self)