/// <summary> /// Move the config rules into lists for warp, time and keypress /// and register events as needed /// /// Use with caution, locks on this /// </summary> private void CheckRulesAndUpdateEventReg() { lock (this) { WarpRules.Clear(); TimeRules.Clear(); KeyRules.Clear(); foreach (ModRule rule in m_config.SnapshotRules) { if (rule.Trigger.IsWaitingOnWarp()) { WarpRules.Add(rule); } else if (rule.Trigger.IsWaitingOnTime()) { TimeRules.Add(rule); } else if (rule.Trigger.IsWaitingOnKeypress()) { KeyRules.Add(rule); } } EventAction warpAction = ShouldAlterEventReg(WarpEventRegistered, WarpRules.Count); EventAction timeAction = ShouldAlterEventReg(TimeEventRegistered, TimeRules.Count); EventAction keyAction = ShouldAlterEventReg(KeyEventRegistered, KeyRules.Count); MTrace($"Warp = {WarpRules.Count} {warpAction}, Time = {TimeRules.Count} {timeAction}, Key = {KeyRules.Count} {keyAction}"); // Events cannot be passed, so this code must be duplicated if (EventAction.Add == warpAction) { Helper.Events.Player.Warped += OnWarped; } else if (EventAction.Remove == warpAction) { Helper.Events.Player.Warped -= OnWarped; } WarpEventRegistered = 0 < WarpRules.Count; if (EventAction.Add == timeAction) { Helper.Events.GameLoop.TimeChanged += OnTimeChanged; } else if (EventAction.Remove == timeAction) { Helper.Events.GameLoop.TimeChanged -= OnTimeChanged; } TimeEventRegistered = 0 < TimeRules.Count; if (EventAction.Add == keyAction) { Helper.Events.Input.ButtonPressed += OnButtonPressed; } else if (EventAction.Remove == keyAction) { Helper.Events.Input.ButtonPressed -= OnButtonPressed; } KeyEventRegistered = 0 < KeyRules.Count; } }