Beispiel #1
0
        protected void Wait(InputRequest req, Action <long> tickAction = null)
        {
            long target = req.EndTime + CurrentTime;

            lock (inputLock)
            {
                currentInputReq = req;
            }

            while (true)
            {
                Task.Delay(WAIT_TIMEOUT).Wait();

                if (!IsWaiting)
                {
                    break;
                }

                tickAction?.Invoke(target - CurrentTime);

                if (currentInputReq.HasTimeout && target <= CurrentTime)
                {
                    OnTextEntered(currentInputReq.DefaultValue);
                    break;
                }
            }

            Console.DeActiveButtons();
        }
Beispiel #2
0
        public void OnTextEntered(string value)
        {
            if (!IsWaiting)
            {
                return;
            }

            lock (inputLock)
            {
                if (currentInputReq.IsOneInput)
                {
                    value = value?[0].ToString();
                }

                switch (currentInputReq.InputType)
                {
                case InputType.ANYKEY:
                    LastInputValue = null;
                    break;

                case InputType.INT:
                    if (!int.TryParse(value, out var num))
                    {
                        return;
                    }
                    LastInputValue  = value;
                    LastInputNumber = num;
                    break;

                case InputType.STR:
                    if (value == null)
                    {
                        return;
                    }
                    LastInputValue = value;
                    break;

                default:
                    throw new ArgumentException("Invalid InputType");
                }

                currentInputReq = null;
            }
        }