mirror of
https://github.com/baketnk/frame-yap.git
synced 2026-10-06 01:00:04 +02:00
67 lines
3.4 KiB
Python
67 lines
3.4 KiB
Python
"""Offline contract for the default Frame controller shortcut (no OpenVR)."""
|
|
import json
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class ActionBindingTests(unittest.TestCase):
|
|
def test_review_controls_match_config_defaults(self):
|
|
manifest = json.loads((ROOT / "assets/actions.json").read_text())
|
|
binding = json.loads((ROOT / "assets/bindings_frame_controller.json").read_text())
|
|
config = json.loads((ROOT / "assets/config.example.json").read_text())
|
|
sources = binding["bindings"]["/actions/frameyap"]["sources"]
|
|
self.assertEqual(len({s["path"] for s in sources}), len(sources))
|
|
for action, button in {"ptt": "x", "cancel": "b", "insert": "a", "quick_chat": "y"}.items():
|
|
name = f"/actions/frameyap/in/{action}"
|
|
path = f"/user/hand/right/input/{button}"
|
|
self.assertIn({"name": name, "type": "boolean"}, manifest["actions"])
|
|
self.assertEqual(config["buttons"][action], path)
|
|
self.assertEqual([s["path"] for s in sources if s["inputs"].get("click", {}).get("output") == name], [path])
|
|
self.assertEqual(config["buttons"]["enter"], "")
|
|
self.assertFalse(any(s["inputs"].get("click", {}).get("output") == "/actions/frameyap/in/enter" for s in sources))
|
|
self.assertEqual(config["quick_inputs"], ["/new", "/questions", "/help"])
|
|
|
|
def test_right_x_is_hold_to_talk(self):
|
|
manifest = json.loads((ROOT / "assets/actions.json").read_text())
|
|
binding = json.loads((ROOT / "assets/bindings_frame_controller.json").read_text())
|
|
self.assertIn(
|
|
{"controller_type": "frame_controller", "binding_url": "bindings_frame_controller.json"},
|
|
manifest["default_bindings"],
|
|
)
|
|
self.assertIn(
|
|
{"name": "/actions/frameyap/in/ptt", "type": "boolean"},
|
|
manifest["actions"],
|
|
)
|
|
sources = binding["bindings"]["/actions/frameyap"]["sources"]
|
|
right_x = [source for source in sources if source["path"] == "/user/hand/right/input/x"]
|
|
self.assertEqual(right_x, [{
|
|
"path": "/user/hand/right/input/x",
|
|
"mode": "button",
|
|
"inputs": {"click": {"output": "/actions/frameyap/in/ptt"}},
|
|
}])
|
|
# Do not map a second PTT source or replace the dashboard's pointer trigger.
|
|
self.assertEqual(sum(
|
|
source["inputs"].get("click", {}).get("output") == "/actions/frameyap/in/ptt"
|
|
for source in sources
|
|
), 1)
|
|
self.assertFalse(any(source["path"].endswith("/input/trigger") for source in sources))
|
|
|
|
def test_grab_depth_axes_are_hand_specific(self):
|
|
manifest = json.loads((ROOT / "assets/actions.json").read_text())
|
|
for binding_file in ("bindings_frame_controller.json", "bindings_knuckles.json"):
|
|
sources = json.loads((ROOT / "assets" / binding_file).read_text())["bindings"]["/actions/grab"]["sources"]
|
|
for hand in ("left", "right"):
|
|
name = f"/actions/grab/in/{hand}_depth"
|
|
path = f"/user/hand/{hand}/input/thumbstick"
|
|
self.assertIn({"name": name, "type": "vector2"}, manifest["actions"])
|
|
self.assertEqual([s for s in sources if s["path"] == path], [{
|
|
"path": path, "mode": "joystick", "inputs": {"position": {"output": name}},
|
|
}])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|