internal static void AddOptionIfGoingToChange(List<string> optionsToCheck, VTStateOptions desiredEnabledStates, VTStateOptions desiredDisabledStates, VTStateOptions checkState, string optionValueToAdd) { if ((desiredEnabledStates & checkState) != 0 || (desiredDisabledStates & checkState) != 0) { optionsToCheck.Add(optionValueToAdd); } }
public VTStateScope(VTStateOptions desiredEnabledStates, VTStateOptions desiredDisabledStates) { List<string> optionsToCheck = new List<string>(); // Only check the options that will get changed. That way we don't even mess with options // the scope doesn't care about. AddOptionIfGoingToChange(optionsToCheck, desiredEnabledStates, desiredDisabledStates, VTStateOptions.Combat, VTOptionNames.EnableCombat); AddOptionIfGoingToChange(optionsToCheck, desiredEnabledStates, desiredDisabledStates, VTStateOptions.Nav, VTOptionNames.EnableNav); AddOptionIfGoingToChange(optionsToCheck, desiredEnabledStates, desiredDisabledStates, VTStateOptions.Looting, VTOptionNames.EnableLooting); AddOptionIfGoingToChange(optionsToCheck, desiredEnabledStates, desiredDisabledStates, VTStateOptions.Buffing, VTOptionNames.EnableBuffing); AddOptionIfGoingToChange(optionsToCheck, desiredEnabledStates, desiredDisabledStates, VTStateOptions.Meta, VTOptionNames.EnableMeta); this._previousStateOptions = VTUtilities.GetVTOptions(optionsToCheck); REPlugin.Instance.Debug.WriteObject(this._previousStateOptions, "VTStateScope-CurrentBackup"); // Apply enables first if (desiredEnabledStates != VTStateOptions.DontChange) { CheckAndSetState(desiredEnabledStates, VTStateOptions.Combat, VTActions.EnableCombat); CheckAndSetState(desiredEnabledStates, VTStateOptions.Nav, VTActions.EnableNav); CheckAndSetState(desiredEnabledStates, VTStateOptions.Looting, VTActions.EnableLooting); CheckAndSetState(desiredEnabledStates, VTStateOptions.Buffing, VTActions.EnableBuffing); CheckAndSetState(desiredEnabledStates, VTStateOptions.Meta, VTActions.EnableMeta); } // Then apply disables. Yes, they could overwrite, consider that programmer error if (desiredDisabledStates != VTStateOptions.DontChange) { CheckAndSetState(desiredDisabledStates, VTStateOptions.Combat, VTActions.DisableCombat); CheckAndSetState(desiredDisabledStates, VTStateOptions.Nav, VTActions.DisableNav); CheckAndSetState(desiredDisabledStates, VTStateOptions.Looting, VTActions.DisableLooting); CheckAndSetState(desiredDisabledStates, VTStateOptions.Buffing, VTActions.DisableBuffing); CheckAndSetState(desiredDisabledStates, VTStateOptions.Meta, VTActions.DisableMeta); } }
private static void CheckAndSetState(VTStateOptions desiredState, VTStateOptions checkState, SafeAction matchAction) { if ((desiredState & checkState) != 0) { matchAction(); } }
public static VTStateScope Enter(VTStateOptions enabledStates, VTStateOptions disabledStates) { return new VTStateScope(enabledStates, disabledStates); }