using UnityEngine; using Yarn.Unity; namespace NightclubArcadia.Skills { /// /// Composition root and singleton that static Yarn commands route through. /// public sealed class SkillRuntime : MonoBehaviour { public static SkillRuntime Instance { get; private set; } [SerializeField] SkillDatabase database; [SerializeField] DialogueRunner dialogueRunner; [SerializeField] SkillCheckResultView resultView; [SerializeField] CommentarySystem commentary; [SerializeField] int rollSeed; [SerializeField] string debugContextId = "Entrance_Queue"; public SkillDatabase Database => database; public DialogueRunner DialogueRunner => dialogueRunner; public SkillCheckResultView ResultView => resultView; public CommentarySystem Commentary => commentary; public PlayerSkills Skills { get; private set; } public SkillStateModifiers States { get; private set; } public SkillCheckSystem Checks { get; private set; } public IRollSource Rolls { get; private set; } void Awake() { if (Instance != null && Instance != this) { Debug.LogError($"[{nameof(SkillRuntime)}] Duplicate instance on '{name}'. Destroying this component.", this); Destroy(this); return; } Instance = this; if (database == null) { Debug.LogError($"[{nameof(SkillRuntime)}] SkillDatabase is not assigned.", this); } Skills = database != null ? new PlayerSkills(database) : null; States = new SkillStateModifiers(); Rolls = rollSeed != 0 ? (IRollSource)new SeededRollSource(rollSeed) : new UnityRollSource(); if (Skills != null) { Checks = new SkillCheckSystem(database, Skills, States, Rolls); } } void OnDestroy() { if (Instance == this) { Instance = null; } } [ContextMenu("Fire Commentary (debug)")] void FireCommentaryDebug() { if (commentary == null) { Debug.LogWarning($"[{nameof(SkillRuntime)}] No CommentarySystem assigned.", this); return; } commentary.RequestCommentary(debugContextId); } } }