private void setInputMode(InputModes value) { visualScopes.Clear(); lastVisualScopeMarker = null; switch (value) { case InputModes.RegexManipulation: if (lastTextBeforeInputModeChange != Text) { ResetRootScope(); lastTextBeforeInputModeChange = Text; } CanDrawScopes = true; ReadOnly = true; BackColor = regexModeBackColor; CacheSpecialMarks = true; raiseInputModeChangedEvent(); break; case InputModes.StandardEdit: ShowSPaces = false; ShowTabs = false; ShowNewLines = false; CacheSpecialMarks = false; CanDrawScopes = false; ReadOnly = false; BackColor = editModeBackColor; raiseInputModeChangedEvent(); break; default: break; } }
public void ParseCommandlineParameters(IConfiguration configuration) { if (!string.IsNullOrWhiteSpace(configuration["InputPath"])) { InputPath = configuration["InputPath"]; if (File.Exists(InputPath)) { ImeFilePath = InputPath; InputMode = InputModes.InputFile; } else if (Directory.Exists(InputPath)) { InputDirectoryPath = InputPath; InputMode = InputModes.InputDirectory; } } else { Ensure.ThatNotNull(InputPath, nameof(InputPath)); } if (!string.IsNullOrWhiteSpace(configuration["OutputFolderPath"])) { OutputFolderPath = configuration["OutputFolderPath"]; } else { Ensure.ThatNotNull(OutputFolderPath, nameof(OutputFolderPath)); } }
public override void HandleArgsOnConsoleChange(List <string> arguments) { if (arguments?.Count == 0) { return; } for (int i = 0; i < arguments.Count; i++) { //Check for enum mode if (Enum.TryParse(arguments[i], true, out InputModes mode) == true) { InputMode = mode; BotProgram.QueueMessage($"Changed Wii input mode to {mode}!"); } //Kimimaru: I'm debating including the ability to set it by number, so we'll keep it commented until a decision is made //if (int.TryParse(arguments[i], out int inputMode) == true) //{ // InputModes newInputMode = (InputModes)inputMode; // InputMode = (InputModes)inputMode; // Console.WriteLine($"Changed Wii input mode to {newInputMode}"); //} } }
public void RequestMode(InputModes newMode, bool value) { if (value) { requestedMode |= newMode; } else { requestedMode &= ~newMode; } }
void CloseInventory() { for (int i = 0; i < playerUnit.GetEquipped().Count; i++) { baseItems.Add(playerUnit.GetEquipped()[i]); } playerUnit.SetEquipped(baseItems); inventoryPanel.transform.position = new Vector3(-1000, -1000, -1000); storageView.Reset(playerUnit.GetStorage()); inputMode = InputModes.movement; gameController.ClearBoxes(playerUnit.posX, playerUnit.posY); }
public async Task <bool> SetCombinedInputMode(byte modeCombinationIndex, uint delta = 1, bool notify = true) { if (Capabilities.HasFlag(PortCapabilities.Input) && Capabilities.HasFlag(PortCapabilities.Combinable)) { var modeCombination = ModeCombinations.ElementAtOrDefault(modeCombinationIndex); if (modeCombination != default) { // combined input SendMessage(new PortInputFormatSetupCombinedMessage(Port, PortInputFormatSetupSubCommands.Lock_LPF2_Device_For_Setup)); IsLocked = true; await Task.Delay(1000); InputModes.Clear(); var modeAndDatasetCombinations = new List <byte>(); foreach (var mode in modeCombination.ToModes()) { SendMessage(new PortInputFormatSetupSingleMessage(Port, mode, delta, notify)); for (int i = 1; i <= ModeInformation[mode].ValueFormat[0]; i++) { var modeAndDatasetInfo = mode << 4; modeAndDatasetInfo |= (i - 1); modeAndDatasetCombinations.Add((byte)modeAndDatasetInfo); } do { await Task.Delay(500); }while (!InputModes.ContainsKey(mode)); } SendMessage(new PortInputFormatSetupCombinedSetModeDatasetMessage(Port, modeCombinationIndex, modeAndDatasetCombinations)); do { await Task.Delay(500); }while (IsLocked); InputMode = modeCombination; return(true); } } return(false); }
void OpenInventory() { invRightText.text = "Sack"; invLeftText.text = "Equipped"; baseItems = new List <Item>(); for (int i = 0; i < 4; i++) { baseItems.Add(playerUnit.GetEquipped()[0]); playerUnit.GetEquipped().RemoveAt(0); } inputMode = InputModes.inventory; inventoryPanel.transform.position = centerUIMarker.transform.position; storageView.Reset(playerUnit.GetStorage()); }
protected override void Awake() { base.Awake(); Install(false); ControllerLayer = Devices .Union(newDevices) .Select(d => (int?)d.Layer) .FirstOrDefault() ?? LayerMask.NameToLayer("Ignore Raycast"); requestedMode = SavedInputMode; }
void ScanForSearchInput() { if (Input.GetAxisRaw("Wait") != 0) { OpenInventory(); SetSecondaryList(playerUnit.Search(playerUnit.posX, playerUnit.posY)); //searchMode = false; inputMode = InputModes.inventory; } if (Input.GetAxisRaw("MoveNorth") != 0) { } if (Input.GetAxisRaw("MoveSouth") != 0) { } if (Input.GetAxisRaw("MoveEast") != 0) { } if (Input.GetAxisRaw("MoveWest") != 0) { } if (Input.GetAxisRaw("MoveNorthWest") != 0) { } if (Input.GetAxisRaw("MoveSouthWest") != 0) { } if (Input.GetAxisRaw("MoveNorthEast") != 0) { } if (Input.GetAxisRaw("MoveSouthEast") != 0) { } if (Input.GetAxisRaw("MoveSouthEast") != 0) { } if (Input.GetAxisRaw("Search") != 0 && canSearch) { //searchMode = false; } else if (Input.GetAxisRaw("Search") == 0) { canSearch = true; } }
public override void Initialize() { base.Initialize(); //Show all input modes InputModes[] inputModeArr = EnumUtility.GetValues <InputModes> .EnumValues; for (int i = 0; i < inputModeArr.Length; i++) { InputModes inputMode = inputModeArr[i]; CachedInputModesStr += inputMode.ToString(); if (i < (inputModeArr.Length - 1)) { CachedInputModesStr += ", "; } } }
private void Calculate() { bool up = this.Up(); bool down = this.Down(); bool hold = this.Hold(); if (up && !hold) { this.mode = InputModes.RELEASE; } else if (down && this.mode != InputModes.HOLD) { this.mode = InputModes.PRESS; this.CheckDoubleTap(); if (this.mode == InputModes.PRESS) { this.doubleTapCheckValue = this.value; this.doubleTapCheckTime = Time.time; } } else if (hold) { this.mode = InputModes.HOLD; } else { this.mode = InputModes.NONE; } }
public void OnGUI() { var inputModes = new[] { "Add water", "Remove water", "Add Terrain", "Remove terrain" }; GUILayout.BeginArea(new Rect(10, 10, 400, 400)); InputMode = (InputModes)GUILayout.Toolbar((int)InputMode, inputModes); GUILayout.BeginHorizontal(); GUILayout.Label("Brush strength"); BrushAmount = GUILayout.HorizontalSlider(BrushAmount, 1f, 100f); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Brush size"); _brushRadius = GUILayout.HorizontalSlider(_brushRadius, 0.01f, 0.2f); GUILayout.EndHorizontal(); GUILayout.Label("[W][A][S][D] - Fly, hold [Shift] - fly faster"); GUILayout.Label("hold [RMB] - rotate camera"); GUILayout.Label("[LMB] - draw"); GUILayout.EndArea(); }
private void CheckDoubleTap() { if (this.CanDoubleTap() && this.IsDoubleTap()) { this.mode = InputModes.DOUBLE_TAP; } }
/// <summary> /// Find all the pointers and fire raycaster events for them. /// </summary> public override void Process() { if (requestedMode != currentMode) { if (requestedMode == InputModes.Auto) { requestedMode = SavedInputMode; } // Validate the InputModes that has been set var voice = VoiceRequestApproved; var controllers = ControllersRequestApproved; var hands = HandsRequestApproved; var mouse = MouseRequestApproved; var gaze = GazeRequestApproved; var touch = TouchRequestApproved; // Enable a default device if no devices are enabled if (!controllers && !hands && !mouse && !touch && !gaze) { if (ControllersAvailable) { controllers = true; } else if (HandsAvailable) { hands = true; } else if (MouseAvailable) { mouse = true; } else if (TouchAvailable) { touch = true; } else if (GazeAvailable) { gaze = true; } } if (Voice != null) { Voice.enabled = voice; } Gaze.SetActive(gaze); Mouse.SetActive(mouse); foreach (var touchPoint in Touches) { touchPoint.SetActive(touch); } foreach (var handTracker in Hands) { handTracker.SetActive(hands); } foreach (var motionController in Controllers) { motionController.SetActive(controllers); } // record the actual input mode VoiceRequested = voice; ControllersRequested = controllers; MouseRequested = mouse; TouchRequested = touch; HandsRequested = hands; GazeRequested = gaze; SavedInputMode = currentMode = requestedMode; } if (newDevices.Count > 0) { foreach (var device in newDevices) { device.LaserPointerNormalMaterial = laserPointerNormalMaterial; device.LaserPointerEnabledMaterial = laserPointerEnabledMaterial; device.LaserPointerDisabledMaterial = laserPointerDisabledMaterial; } Devices.AddRange(newDevices); newDevices.Clear(); } if (newKeyboardShortcuts.Count > 0) { keyboardShortcuts.AddRange(newKeyboardShortcuts); newKeyboardShortcuts.Clear(); } keyPresses.Clear(); toActivate.Clear(); toRemove.Clear(); foreach (var pointer in Devices) { if (pointer.ProcessInUpdate) { ProcessPointer(pointer); } } foreach (var shortcut in keyboardShortcuts) { if (shortcut == null || !shortcut.gameObject.scene.isLoaded) { toRemove.MaybeAdd(shortcut); } else if (shortcut.IsInteractable() && (UnityInput.GetKeyUp(shortcut.KeyCode) || keyPresses.Contains(shortcut.KeyCode))) { toActivate.MaybeAdd(shortcut); } } foreach (var shortcut in toRemove) { keyboardShortcuts.Remove(shortcut); } if (!paused) { foreach (var shortcut in toActivate) { shortcut.ActivateEvent(); } } }
public virtual void Uninstall() { requestedMode = InputModes.Auto; }
/// <summary> /// Removes all input modes currently associated with the node editor /// </summary> public void ClearInputModes() { InputModes.Clear(); }
void Start() { inputMode = InputModes.movement; }
void ScanForMenuInputs() { if (Input.GetAxisRaw("MoveNorth") != 0 && canMoveNorth) { canMoveNorth = false; if (onRightPanel) { storageView.PrevOption(); } else { secondaryStorageView.PrevOption(); } } else if (Input.GetAxisRaw("MoveNorth") == 0) { canMoveNorth = true; } if (Input.GetAxisRaw("MoveSouth") != 0 && canMoveSouth) { canMoveSouth = false; if (onRightPanel) { storageView.NextOption(); } else { secondaryStorageView.NextOption(); } } else if (Input.GetAxisRaw("MoveSouth") == 0) { canMoveSouth = true; } if (Input.GetAxisRaw("MoveWest") != 0 && canMoveWest) { canMoveWest = false; SwitchInventoryFocus(); } else if (Input.GetAxisRaw("MoveWest") == 0) { canMoveWest = true; } if (Input.GetAxisRaw("MoveEast") != 0 && canMoveEast) { canMoveEast = false; SwitchInventoryFocus(); } else if (Input.GetAxisRaw("MoveEast") == 0) { canMoveEast = true; } if (Input.GetAxisRaw("OpenInventory") != 0 && canOpenInventory) { CloseInventory(); canOpenInventory = false; } else if (Input.GetAxisRaw("OpenInventory") == 0) { canOpenInventory = true; } if (Input.GetAxisRaw("Drop") != 0 && canDrop) { if (onRightPanel) { DropItem(storageView.GetCurrentIndex()); } else { DropItem(secondaryStorageView.GetCurrentIndex()); } canDrop = false; } else if (Input.GetAxisRaw("Drop") == 0) { canDrop = true; } if (Input.GetAxisRaw("Search") != 0 && canSearch) { //searchMode = true; CloseInventory(); inputMode = InputModes.search; canSearch = false; } else if (Input.GetAxisRaw("Search") == 0) { canSearch = true; } if (Input.GetAxisRaw("Swap") != 0 && canSwap) { canSwap = false; if (onRightPanel) { secondaryStorageView.AddItem(storageView.GetItem()); storageView.SoftReset(); secondaryStorageView.SoftReset(); } else { storageView.AddItem(secondaryStorageView.GetItem()); storageView.SoftReset(); secondaryStorageView.SoftReset(); } } else if (Input.GetAxisRaw("Swap") == 0) { canSwap = true; } }
/// <summary> /// Add an input mode /// </summary> /// <param name="inputMode">The input mode to add</param> public void EnableInputMode(InputMode inputMode) { InputModes.Add(inputMode); SortInputModes(); }
/// <summary> /// Sort the input modes /// </summary> private void SortInputModes() { InputModes.Sort((x, y) => x.Priority.CompareTo(y.Priority)); }
/// <summary> /// Get the input mode of the specified type /// </summary> /// <param name="modeType">The type of input mode to retrieve</param> /// <returns>The found input mode that matches the type, or null if not found</returns> public InputMode GetInputMode(Type modeType) { return(InputModes.Find((x) => x.GetType().IsOrIsSubclassOf(modeType))); }
/// <summary> /// Gets the full name (including input-mode) of the command defined by this <see cref="MicrocodeDoc"/>. /// </summary> public string GetFullName() { return($"{CommandName}{InputModes.GetInputModes()}"); }
private void setInputMode(InputModes value) { visualScopes.Clear(); lastVisualScopeMarker = null; switch (value) { case InputModes.RegexManipulation: if (lastTextBeforeInputModeChange!=Text) { ResetRootScope(); lastTextBeforeInputModeChange = Text; } CanDrawScopes = true; ReadOnly = true; BackColor = regexModeBackColor; CacheSpecialMarks = true; raiseInputModeChangedEvent(); break; case InputModes.StandardEdit: ShowSPaces = false; ShowTabs = false; ShowNewLines = false; CacheSpecialMarks = false; CanDrawScopes = false; ReadOnly = false; BackColor = editModeBackColor; raiseInputModeChangedEvent(); break; default: break; } }
private void ProcessMsgAsInput(EvtUserMessageArgs e) { //Ignore commands as inputs if (e.UsrMessage.Message.StartsWith(DataConstants.COMMAND_IDENTIFIER) == true) { return; } GameConsole usedConsole = null; int lastConsoleID = 1; using (BotDBContext context = DatabaseManager.OpenContext()) { lastConsoleID = (int)DataHelper.GetSettingIntNoOpen(SettingsConstants.LAST_CONSOLE, context, 1L); GameConsole lastConsole = context.Consoles.FirstOrDefault(c => c.ID == lastConsoleID); if (lastConsole != null) { //Create a new console using data from the database usedConsole = new GameConsole(lastConsole.Name, lastConsole.InputList, lastConsole.InvalidCombos); } } //If there are no valid inputs, don't attempt to parse if (usedConsole == null) { MsgHandler.QueueMessage($"The current console does not point to valid data. Please set a different console to use, or if none are available, add one."); return; } if (usedConsole.ConsoleInputs.Count == 0) { MsgHandler.QueueMessage($"The current console, \"{usedConsole.Name}\", does not have any available inputs."); } ParsedInputSequence inputSequence = default; string userName = e.UsrMessage.Username; int defaultDur = 200; int defaultPort = 0; try { int maxDur = 60000; string regexStr = usedConsole.InputRegex; string readyMessage = string.Empty; //Get default and max input durations //Use user overrides if they exist, otherwise use the global values User user = DataHelper.GetUser(userName); //Get default controller port defaultPort = (int)user.ControllerPort; defaultDur = (int)DataHelper.GetUserOrGlobalDefaultInputDur(userName); maxDur = (int)DataHelper.GetUserOrGlobalMaxInputDur(userName); //TRBotLogger.Logger.Information($"Default dur: {defaultDur} | Max dur: {maxDur}"); using (BotDBContext context = DatabaseManager.OpenContext()) { //Get input synonyms for this console IQueryable <InputSynonym> synonyms = context.InputSynonyms.Where(syn => syn.ConsoleID == lastConsoleID); //Prepare the message for parsing readyMessage = InputParser.PrepParse(e.UsrMessage.Message, context.Macros, synonyms); } //Parse inputs to get our parsed input sequence inputSequence = InputParser.ParseInputs(readyMessage, regexStr, new ParserOptions(defaultPort, defaultDur, true, maxDur)); TRBotLogger.Logger.Debug(inputSequence.ToString()); TRBotLogger.Logger.Debug("Reverse Parsed (on parse): " + ReverseParser.ReverseParse(inputSequence, usedConsole, new ReverseParser.ReverseParserOptions(ReverseParser.ShowPortTypes.ShowNonDefaultPorts, defaultPort, ReverseParser.ShowDurationTypes.ShowNonDefaultDurations, defaultDur))); } catch (Exception exception) { string excMsg = exception.Message; //Handle parsing exceptions MsgHandler.QueueMessage($"ERROR PARSING: {excMsg} | {exception.StackTrace}", Serilog.Events.LogEventLevel.Warning); inputSequence.ParsedInputResult = ParsedInputResults.Invalid; } //Check for non-valid messages if (inputSequence.ParsedInputResult != ParsedInputResults.Valid) { //Display error message for invalid inputs if (inputSequence.ParsedInputResult == ParsedInputResults.Invalid) { MsgHandler.QueueMessage(inputSequence.Error); } return; } #region Parser Post-Process Validation /* All this validation may be able to be performed faster. * Find a way to speed it up. */ long globalInputPermLevel = DataHelper.GetSettingInt(SettingsConstants.GLOBAL_INPUT_LEVEL, 0L); int userControllerPort = 0; long userLevel = 0; using (BotDBContext context = DatabaseManager.OpenContext()) { User user = DataHelper.GetUserNoOpen(e.UsrMessage.Username, context); //Check if the user is silenced and ignore the message if so if (user.HasEnabledAbility(PermissionConstants.SILENCED_ABILITY) == true) { return; } //Ignore based on user level and permissions if (user.Level < globalInputPermLevel) { MsgHandler.QueueMessage($"Inputs are restricted to levels {(PermissionLevels)globalInputPermLevel} and above."); return; } userControllerPort = (int)user.ControllerPort; userLevel = user.Level; } //First, add delays between inputs if we should //We do this first so we can validate the inserted inputs later //The blank inputs can have a different permission level if (DataHelper.GetUserOrGlobalMidInputDelay(e.UsrMessage.Username, out long midInputDelay) == true) { MidInputDelayData midInputDelayData = ParserPostProcess.InsertMidInputDelays(inputSequence, userControllerPort, (int)midInputDelay, usedConsole); //If it's successful, replace the input list and duration if (midInputDelayData.Success == true) { int oldDur = inputSequence.TotalDuration; inputSequence.Inputs = midInputDelayData.NewInputs; inputSequence.TotalDuration = midInputDelayData.NewTotalDuration; //TRBotLogger.Logger.Debug($"Mid input delay success. Message: {midInputDelayData.Message} | OldDur: {oldDur} | NewDur: {inputSequence.TotalDuration}\n{ReverseParser.ReverseParse(inputSequence, usedConsole, new ReverseParser.ReverseParserOptions(ReverseParser.ShowPortTypes.ShowAllPorts, 0))}"); } } InputValidation validation = default; using (BotDBContext context = DatabaseManager.OpenContext()) { User user = DataHelper.GetUserNoOpen(userName, context); //Check for restricted inputs on this user validation = ParserPostProcess.InputSequenceContainsRestrictedInputs(inputSequence, user.GetRestrictedInputs()); if (validation.InputValidationType != InputValidationTypes.Valid) { if (string.IsNullOrEmpty(validation.Message) == false) { MsgHandler.QueueMessage(validation.Message); } return; } //Check for invalid input combinations validation = ParserPostProcess.ValidateInputCombos(inputSequence, usedConsole.InvalidCombos, DataContainer.ControllerMngr, usedConsole); if (validation.InputValidationType != InputValidationTypes.Valid) { if (string.IsNullOrEmpty(validation.Message) == false) { MsgHandler.QueueMessage(validation.Message); } return; } } //Check for level permissions and ports validation = ParserPostProcess.ValidateInputLvlPermsAndPorts(userLevel, inputSequence, DataContainer.ControllerMngr, usedConsole.ConsoleInputs); if (validation.InputValidationType != InputValidationTypes.Valid) { if (string.IsNullOrEmpty(validation.Message) == false) { MsgHandler.QueueMessage(validation.Message, Serilog.Events.LogEventLevel.Warning); } return; } #endregion //Make sure inputs aren't stopped if (InputHandler.InputsHalted == true) { //We can't process inputs because they're currently stopped MsgHandler.QueueMessage("New inputs cannot be processed until all other inputs have stopped.", Serilog.Events.LogEventLevel.Warning); return; } //Fetch these values ahead of time to avoid passing the database context through so many methods long autoPromoteEnabled = DataHelper.GetSettingInt(SettingsConstants.AUTO_PROMOTE_ENABLED, 0L); long autoPromoteInputReq = DataHelper.GetSettingInt(SettingsConstants.AUTO_PROMOTE_INPUT_REQ, long.MaxValue); long autoPromoteLevel = DataHelper.GetSettingInt(SettingsConstants.AUTO_PROMOTE_LEVEL, -1L); string autoPromoteMsg = DataHelper.GetSettingString(SettingsConstants.AUTOPROMOTE_MESSAGE, string.Empty); bool addedInputCount = false; TRBotLogger.Logger.Debug($"Reverse Parsed (post-process): " + ReverseParser.ReverseParse(inputSequence, usedConsole, new ReverseParser.ReverseParserOptions(ReverseParser.ShowPortTypes.ShowNonDefaultPorts, defaultPort, ReverseParser.ShowDurationTypes.ShowNonDefaultDurations, defaultDur))); //Get the max recorded inputs per-user long maxUserRecInps = DataHelper.GetSettingInt(SettingsConstants.MAX_USER_RECENT_INPUTS, 0L); //It's a valid input - save it in the user's stats //Also record the input if we should using (BotDBContext context = DatabaseManager.OpenContext()) { User user = DataHelper.GetUserNoOpen(e.UsrMessage.Username, context); //Ignore if the user is opted out if (user.IsOptedOut == false) { user.Stats.ValidInputCount++; addedInputCount = true; context.SaveChanges(); //If we should store recent user inputs, do so if (maxUserRecInps > 0) { //Get the input sequence - we may have added mid input delays between //As a result, we'll need to reverse parse it string message = ReverseParser.ReverseParse(inputSequence, usedConsole, new ReverseParser.ReverseParserOptions(ReverseParser.ShowPortTypes.ShowNonDefaultPorts, (int)user.ControllerPort, ReverseParser.ShowDurationTypes.ShowNonDefaultDurations, defaultDur)); //Add the recorded input user.RecentInputs.Add(new RecentInput(message)); context.SaveChanges(); int diff = user.RecentInputs.Count - (int)maxUserRecInps; //If we're over the max after adding, remove if (diff > 0) { //Order by ascending ID and take the difference //Lower IDs = older entries IEnumerable <RecentInput> shouldRemove = user.RecentInputs.OrderBy(r => r.UserID).Take(diff); foreach (RecentInput rec in shouldRemove) { user.RecentInputs.Remove(rec); context.SaveChanges(); } } } } } bool autoPromoted = false; //Check if auto promote is enabled and auto promote the user if applicable if (addedInputCount == true) { using (BotDBContext context = DatabaseManager.OpenContext()) { User user = DataHelper.GetUserNoOpen(e.UsrMessage.Username, context); //Check if the user was already autopromoted, autopromote is enabled, //and if the user reached the autopromote input count requirement if (user.Stats.AutoPromoted == 0 && autoPromoteEnabled > 0 && user.Stats.ValidInputCount >= autoPromoteInputReq) { //Only autopromote if this is a valid permission level //We may not want to log or send a message for this, as it has potential to be very spammy, //and it's not something the users can control if (PermissionHelpers.IsValidPermissionValue(autoPromoteLevel) == true) { //Mark the user as autopromoted and save user.Stats.AutoPromoted = 1; autoPromoted = true; context.SaveChanges(); } } } } if (autoPromoted == true) { //If the user is already at or above this level, don't set them to it //Only set if the user is below if (userLevel < autoPromoteLevel) { //Adjust abilities and promote to the new level DataHelper.AdjustUserLvlAndAbilitiesOnLevel(userName, autoPromoteLevel); if (string.IsNullOrEmpty(autoPromoteMsg) == false) { PermissionLevels permLvl = (PermissionLevels)autoPromoteLevel; string finalMsg = autoPromoteMsg.Replace("{0}", userName).Replace("{1}", permLvl.ToString()); MsgHandler.QueueMessage(finalMsg); } } } InputModes inputMode = (InputModes)DataHelper.GetSettingInt(SettingsConstants.INPUT_MODE, 0L); //If the mode is Democracy, add it as a vote for this input if (inputMode == InputModes.Democracy) { //Set up the routine if it doesn't exist BaseRoutine foundRoutine = RoutineHandler.FindRoutine(RoutineConstants.DEMOCRACY_ROUTINE_ID, out int indexFound); DemocracyRoutine democracyRoutine = null; if (foundRoutine == null) { long voteTime = DataHelper.GetSettingInt(SettingsConstants.DEMOCRACY_VOTE_TIME, 10000L); democracyRoutine = new DemocracyRoutine(voteTime); RoutineHandler.AddRoutine(democracyRoutine); } else { democracyRoutine = (DemocracyRoutine)foundRoutine; } democracyRoutine.AddInputSequence(userName, inputSequence.Inputs); } //If it's Anarchy, carry out the input else { /************************************ * Finally carry out the inputs now! * ************************************/ InputHandler.CarryOutInput(inputSequence.Inputs, usedConsole, DataContainer.ControllerMngr); } }
public bool IsModeRequested(InputModes checkMode) { return(requestedMode.HasFlag(checkMode)); }
bool ScanForBaseInputs() { if (Input.GetAxisRaw("MoveNorth") != 0 && canMoveNorth) { canMoveNorth = false; return(playerUnit.MoveNorth()); } else if (Input.GetAxisRaw("MoveNorth") == 0) { canMoveNorth = true; } if (Input.GetAxisRaw("MoveSouth") != 0 && canMoveSouth) { canMoveSouth = false; return(playerUnit.MoveSouth()); } else if (Input.GetAxisRaw("MoveSouth") == 0) { canMoveSouth = true; } if (Input.GetAxisRaw("MoveEast") != 0 && canMoveEast) { canMoveEast = false; return(playerUnit.MoveEast()); } else if (Input.GetAxisRaw("MoveEast") == 0) { canMoveEast = true; } if (Input.GetAxisRaw("MoveWest") != 0 && canMoveWest) { canMoveWest = false; return(playerUnit.MoveWest()); } else if (Input.GetAxisRaw("MoveWest") == 0) { canMoveWest = true; } if (Input.GetAxisRaw("MoveNorthWest") != 0 && canMoveNorthWest) { canMoveNorthWest = false; return(playerUnit.MoveNorthWest()); } else if (Input.GetAxisRaw("MoveNorthWest") == 0) { canMoveNorthWest = true; } if (Input.GetAxisRaw("MoveSouthWest") != 0 && canMoveSouthWest) { canMoveSouthWest = false; return(playerUnit.MoveSouthWest()); } else if (Input.GetAxisRaw("MoveSouthWest") == 0) { canMoveSouthWest = true; } if (Input.GetAxisRaw("MoveNorthEast") != 0 && canMoveNorthEast) { canMoveNorthEast = false; return(playerUnit.MoveNorthEast()); } else if (Input.GetAxisRaw("MoveNorthEast") == 0) { canMoveNorthEast = true; } if (Input.GetAxisRaw("MoveSouthEast") != 0 && canMoveSouthEast) { canMoveSouthEast = false; return(playerUnit.MoveSouthEast()); } else if (Input.GetAxisRaw("MoveSouthEast") == 0) { canMoveSouthEast = true; } if (Input.GetAxisRaw("MoveSouthEast") != 0 && canMoveSouthEast) { canMoveSouthEast = false; return(playerUnit.MoveSouthEast()); } else if (Input.GetAxisRaw("MoveSouthEast") == 0) { canMoveSouthEast = true; } if (Input.GetAxisRaw("TickRight") != 0 && canTickRight) { canTickRight = false; playerUnit.TickRight(); FillUI(); } else if (Input.GetAxisRaw("TickRight") == 0) { canTickRight = true; } if (Input.GetAxisRaw("TickLeft") != 0 && canTickLeft) { canTickLeft = false; playerUnit.TickLeft(); FillUI(); } else if (Input.GetAxisRaw("TickLeft") == 0) { canTickLeft = true; } if (Input.GetAxisRaw("OpenInventory") != 0 && canOpenInventory) { OpenInventory(); SetSecondaryList(playerUnit.GetEquipped()); canOpenInventory = false; } else if (Input.GetAxisRaw("OpenInventory") == 0) { canOpenInventory = true; } if (Input.GetAxisRaw("Search") != 0 && canSearch) { inputMode = InputModes.search; canSearch = false; //EngageSearch(); } else if (Input.GetAxisRaw("Search") == 0) { canSearch = true; } return(false); }
public void ToggleModeRequested(InputModes newMode) { RequestMode(newMode, !IsModeRequested(newMode)); }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; long curInputMode = DataHelper.GetSettingInt(SettingsConstants.INPUT_MODE, 0L); InputModes inpMode = (InputModes)curInputMode; //See the input mode if (arguments.Count == 0) { QueueMessage($"The current input mode is {inpMode}. To set the input mode, add one as an argument: {CachedInputModesStr}"); return; } //Invalid number of arguments if (arguments.Count > 1) { QueueMessage(UsageMessage); return; } using (BotDBContext context = DatabaseManager.OpenContext()) { //Check if the user has the ability to set the mode User user = DataHelper.GetUserNoOpen(args.Command.ChatMessage.Username, context); if (user != null && user.HasEnabledAbility(PermissionConstants.SET_INPUT_MODE_ABILITY) == false) { QueueMessage("You don't have the ability to set the input mode!"); return; } } string inputModeStr = arguments[0]; //Parse if (EnumUtility.TryParseEnumValue(inputModeStr, out InputModes parsedInputMode) == false) { QueueMessage($"Please enter a valid input mode: {CachedInputModesStr}"); return; } //Same mode if (parsedInputMode == inpMode) { QueueMessage($"The current input mode is already {inpMode}!"); return; } using (BotDBContext context = DatabaseManager.OpenContext()) { //Set the value and save Settings inputModeSetting = DataHelper.GetSettingNoOpen(SettingsConstants.INPUT_MODE, context); inputModeSetting.ValueInt = (long)parsedInputMode; context.SaveChanges(); } QueueMessage($"Changed the input mode from {inpMode} to {parsedInputMode}!"); //If we set it to Anarchy, check if the Democracy routine is active and remove it if so if (parsedInputMode == InputModes.Anarchy) { BaseRoutine democracyRoutine = RoutineHandler.FindRoutine(RoutineConstants.DEMOCRACY_ROUTINE_ID, out int indexFound); if (democracyRoutine != null) { RoutineHandler.RemoveRoutine(indexFound); } } //If we set it to Democracy, add the routine if it's not already active else if (parsedInputMode == InputModes.Democracy) { DemocracyRoutine democracyRoutine = RoutineHandler.FindRoutine <DemocracyRoutine>(); if (democracyRoutine == null) { long votingTime = DataHelper.GetSettingInt(SettingsConstants.DEMOCRACY_VOTE_TIME, 10000L); democracyRoutine = new DemocracyRoutine(votingTime); RoutineHandler.AddRoutine(democracyRoutine); } } }
static void Main(string[] args) { bool configHiddenWindow = false; string varname = ""; string filter = ""; string subargs = "/C "; int argofs = 0; bool subdir = false; bool quiet = false; bool wait = false; //---------------------- InputModes imode = InputModes.DIRSCAN; // Pipe and file option bools are just flags for whether they've been encountered on the cmd line, // not whether the option is currently active, because it could be flipped with /-p or /-f. // In that case, these bools are used to determine which state to revert to when using the mode enum. // If one of these modes has been previously specified, and the other one's /- argument is read, // it will revert to the previously encountered mode, rather than the default directory scan. bool pipeOption = false; bool fileInOption = false; string fileInOptionFilename = ""; int userCommandArgOffset = 3; // This could vary if no file pattern needs to be specified, as in /p and /f //---------------------- int tCount = Environment.ProcessorCount; for (argofs = 0; argofs < args.Length; argofs++) { if (args[argofs][0] == '/') { string curArg = args[argofs].ToLower(); if (curArg == "/s") { subdir = true; } else if (curArg == "/-s") { subdir = false; } else if (curArg == "/+s") { subdir = true; } else if (curArg == "/h") { configHiddenWindow = true; } else if (curArg == "/-h") { configHiddenWindow = false; } else if (curArg == "/+h") { configHiddenWindow = true; } else if (curArg == "/q") { quiet = true; } else if (curArg == "/-q") { quiet = false; } else if (curArg == "/+q") { quiet = true; } else if (curArg == "/w") { wait = true; } else if (curArg == "/-w") { wait = false; } else if (curArg == "/+w") { wait = true; } else if (curArg == "/p") { imode = InputModes.PIPE; pipeOption = true; } else if (curArg == "/+p") { imode = InputModes.PIPE; pipeOption = true; } else if (curArg == "/-p") { if (imode == InputModes.PIPE) { if (fileInOption) { imode = InputModes.FILE; } else { imode = InputModes.DIRSCAN; } } } else if (curArg == "/f" || curArg == "/+f") { imode = InputModes.FILE; fileInOption = true; argofs++; if (argofs >= args.Length) { usage(); return; } fileInOptionFilename = args[argofs]; } else if (curArg == "/-f") { if (imode == InputModes.FILE) { if (pipeOption) { imode = InputModes.PIPE; } else { imode = InputModes.DIRSCAN; } } } else if (curArg == "/t") { argofs++; if (argofs >= args.Length) { break; } int tmp = int.Parse(args[argofs]); if (tmp > 0) { tCount = tmp; } } else { if (!quiet) { usage(); } return; } } else { break; } } if (imode == InputModes.DIRSCAN) { userCommandArgOffset = 3; } else if (imode == InputModes.FILE) { userCommandArgOffset = 1; } else if (imode == InputModes.PIPE) { userCommandArgOffset = 1; } if (argofs + userCommandArgOffset >= args.Length) { usage(); return; } varname = args[argofs + 0]; for (int i = argofs + userCommandArgOffset; i < args.Length; i++) { subargs += args[i] + " "; } // trim final space subargs = subargs.Substring(0, subargs.Length - 1); IEnumerable <string> matches = new List <string>(); // gotta initialize with something if ((imode == InputModes.DIRSCAN) && (args[argofs + 1].ToLower() == "in" && args.Length >= argofs + 4)) { filter = args[argofs + 2]; System.IO.SearchOption subdirEnum = (subdir ? System.IO.SearchOption.AllDirectories : System.IO.SearchOption.TopDirectoryOnly); string scanDir = "."; string postFilter = filter; string pp = Path.GetDirectoryName(filter); if (pp.Length > 0) { if (filter.Substring(0, pp.Length) == pp) { scanDir = pp; postFilter = filter.Substring(pp.Length, filter.Length - pp.Length); if (postFilter[0] == '\\' || postFilter[0] == '/') { postFilter = postFilter.Substring(1, postFilter.Length - 1); } } } bool bContinue = true; try { matches = System.IO.Directory.EnumerateFiles(scanDir, postFilter, subdirEnum); } catch (Exception e) { if (!quiet) { Console.WriteLine("Exception in directory scan: " + e.Message); } bContinue = false; } if (bContinue) { iterate(configHiddenWindow, varname, subargs, quiet, wait, tCount, matches); } } //else if (args[argofs + 1] == "=" // && args[argofs + 3].ToLower() == "to" // && args.Length >= argofs + 4) //{ // //} else if (imode == InputModes.FILE) { try { matches = new llfor.fileLineEnumerable(fileInOptionFilename); } catch (Exception e) { if (!quiet) { Console.WriteLine("Error trying to open input file: " + e.Message); } return; } iterate(configHiddenWindow, varname, subargs, quiet, wait, tCount, matches); } else if (imode == InputModes.PIPE) { try { matches = new llfor.stdinEnumerable(); } catch (Exception e) { if (!quiet) { Console.WriteLine("Error trying to open standard input/pipe: " + e.Message); } return; } iterate(configHiddenWindow, varname, subargs, quiet, wait, tCount, matches); } else { if (!quiet) { usage(); return; } } }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; long curInputMode = DataHelper.GetSettingInt(SettingsConstants.INPUT_MODE, 0L); InputModes inpMode = (InputModes)curInputMode; //Check the number of votes if (arguments.Count == 0) { InputModeVoteRoutine inpModeVoteRoutine = RoutineHandler.FindRoutine <InputModeVoteRoutine>(); if (inpModeVoteRoutine == null) { QueueMessage($"There is no voting in progress for a new input mode. To start one up, pass a mode as an argument: {CachedInputModesStr}"); } else { StringBuilder stringBuilder = new StringBuilder(128); //Show the number of votes for each mode Dictionary <InputModes, long> curVotes = inpModeVoteRoutine.GetVotesPerMode(); foreach (KeyValuePair <InputModes, long> kvPair in curVotes) { stringBuilder.Append(kvPair.Key.ToString()).Append(' ').Append('='); stringBuilder.Append(' ').Append(kvPair.Value).Append(' ').Append('|').Append(' '); } stringBuilder.Remove(stringBuilder.Length - 3, 3); stringBuilder.Append(". To vote for a new input mode, pass one as an argument: ").Append(CachedInputModesStr); int charLimit = (int)DataHelper.GetSettingInt(SettingsConstants.BOT_MSG_CHAR_LIMIT, 500L); QueueMessageSplit(stringBuilder.ToString(), charLimit, "| "); } return; } //Invalid number of arguments if (arguments.Count > 1) { QueueMessage(UsageMessage); return; } using (BotDBContext context = DatabaseManager.OpenContext()) { //Check if the user has the ability to vote User user = DataHelper.GetUserNoOpen(args.Command.ChatMessage.Username, context); if (user != null && user.HasEnabledAbility(PermissionConstants.VOTE_INPUT_MODE_ABILITY) == false) { QueueMessage("You don't have the ability to vote for a new input mode!"); return; } } //Check if the cooldown is up DateTime nowUTC = DateTime.UtcNow; //Check the last completed time string lastComplete = DataHelper.GetSettingString(SettingsConstants.INPUT_MODE_NEXT_VOTE_DATE, DataHelper.GetStrFromDateTime(DateTime.UnixEpoch)); if (DateTime.TryParse(lastComplete, out DateTime lastCompleteDate) == false) { lastCompleteDate = DateTime.UnixEpoch; TRBotLogger.Logger.Warning($"Failed to parse DateTime: {DataHelper.GetStrFromDateTime(lastCompleteDate)}"); } if (nowUTC < lastCompleteDate) { QueueMessage($"Input mode voting is on cooldown until {lastCompleteDate}"); return; } string inputModeStr = arguments[0]; //Parse if (EnumUtility.TryParseEnumValue(inputModeStr, out InputModes parsedInputMode) == false) { QueueMessage($"Please enter a valid input mode: {CachedInputModesStr}"); return; } bool commencedNewVote = false; //Get the routine InputModeVoteRoutine inputModeVoteRoutine = RoutineHandler.FindRoutine <InputModeVoteRoutine>(); //Add the routine if it doesn't exist if (inputModeVoteRoutine == null) { long voteDur = DataHelper.GetSettingInt(SettingsConstants.INPUT_MODE_VOTE_TIME, 60000L); inputModeVoteRoutine = new InputModeVoteRoutine(voteDur); RoutineHandler.AddRoutine(inputModeVoteRoutine); commencedNewVote = true; } //Check for tallying if (inputModeVoteRoutine.TallyingCommenced == true) { QueueMessage("Too late! Voting has ended and tallying has already begun!"); return; } string userName = args.Command.ChatMessage.Username.ToLowerInvariant(); //Add the vote inputModeVoteRoutine.AddModeVote(userName, parsedInputMode, out bool voteChanged); if (commencedNewVote == false) { if (voteChanged == true) { QueueMessage($"{userName} changed their vote to {parsedInputMode}!"); } else { QueueMessage($"{userName} voted for {parsedInputMode}!"); } } else { QueueMessage($"Voting for changing the input mode has begun! {userName} voted for {parsedInputMode}!"); } }