コード例 #1
0
        /// <summary>Processes the command line input result.</summary>
        /// <param name="uiResult">The UI result.</param>
        /// <param name="result">The result.</param>
        /// <param name="choiceCount">The choices counted.</param>
        public virtual void ProcessCommandLineInputResult(UserInteractionResult uiResult, InputInterpretationResult result, Runtime.IStory runtimeStory)
        {
            if (uiResult == null || result == null)
            {
                return;
            }

            uiResult.IsExitRequested = result.requestsExit;
            uiResult.ChosenIndex     = result.choiceIdx;
            uiResult.DivertedPath    = result.divertedPath;
            uiResult.Output          = result.output;

            int choiceCount = 0;

            if (runtimeStory != null && runtimeStory.currentChoices != null)
            {
                choiceCount = runtimeStory.currentChoices.Count;
            }

            if (result.choiceIdx >= 0 && result.choiceIdx < choiceCount)
            {
                // The choice is only valid if it's a valid index.
                uiResult.IsValidChoice = true;
            }
        }
コード例 #2
0
        /// <summary>Gets the user interaction result.</summary>
        /// <param name="runtimeStory"></param>
        /// <param name="parsedFiction"></param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public virtual UserInteractionResult GetUserInteractionResult(Runtime.IStory runtimeStory, Parsed.IFiction parsedFiction, ConsoleUserInterfaceOptions options)
        {
            var uiResult = new UserInteractionResult();

            OutputManager.RequestInput(options);

            var userInput = OutputManager.GetUserInput();

            // If we have null user input, it means that we're
            // "at the end of the stream", or in other words, the input
            // stream has closed, so there's nothing more we can do.
            // We return immediately, since otherwise we get into a busy
            // loop waiting for user input.
            if (userInput == null)
            {
                OutputManager.ShowStreamError(options);
                uiResult.IsInputStreamClosed = true;
            }
            else
            {
                var result = Interpreter.InterpretCommandLineInput(userInput, parsedFiction, runtimeStory);
                if (result == null)
                {
                    return(null);
                }


                ProcessCommandLineInputResult(uiResult, result, runtimeStory);

                if (uiResult.Output != null)
                {
                    OutputManager.ShowOutputResult(result, options);
                }

                if (!uiResult.IsValidChoice)
                {
                    // The choice is only valid if it's a valid index.
                    OutputManager.ShowChoiceOutOffRange(options);
                }
            }

            return(uiResult);
        }