Add VRC OSC tooling

This commit is contained in:
messypy
2026-06-03 21:39:55 +09:00
committed by every_holiday
parent 072e819b0b
commit 54854969b9
24 changed files with 2982 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
from pathlib import Path
import tomllib
from common.project_paths import ROOT_DIR
CONFIG_DIR = ROOT_DIR / "config"
CONFIG_FILE = CONFIG_DIR / "config.toml"
DEFAULT_EVENT_FILE = CONFIG_DIR / "event.toml"
def loadTomlFile(path):
if not path.exists():
return {}
return tomllib.loads(path.read_text(encoding="utf-8"))
def resolveConfigPath(value, default_path):
if not value:
return default_path
candidate = Path(value)
if candidate.is_absolute():
return candidate
return (ROOT_DIR / candidate).resolve()
def loadVrcLogConfig():
config = loadTomlFile(CONFIG_FILE)
vrc_log = config.get("vrc_log", {})
self_section = config.get("self", {})
event_file_value = (
vrc_log.get("event_toml")
or vrc_log.get("event_file")
or config.get("event_toml")
or config.get("event_file")
)
event_file = resolveConfigPath(event_file_value, DEFAULT_EVENT_FILE)
event_config = loadTomlFile(event_file)
if not event_config:
event_config = vrc_log or config
guest_names = event_config.get("guest", {}).get("names", [])
staff_names = event_config.get("staff", {}).get("names", [])
if not guest_names and isinstance(event_config.get("guest_names"), list):
guest_names = event_config.get("guest_names", [])
if not staff_names and isinstance(event_config.get("staff_names"), list):
staff_names = event_config.get("staff_names", [])
notice_section = event_config.get("notice", {})
missing_count = notice_section.get("missing_count", 0)
if not missing_count:
missing_count = event_config.get("missing_count", 0)
self_name = (
self_section.get("name")
or config.get("self_name")
or vrc_log.get("self_name")
or event_config.get("self", {}).get("name")
or ""
)
return {
"config_file": CONFIG_FILE,
"event_file": event_file,
"guest_names": [str(name).strip() for name in guest_names if str(name).strip()],
"staff_names": [str(name).strip() for name in staff_names if str(name).strip()],
"missing_count": int(missing_count),
"self_name": str(self_name).strip(),
}