Exemplo n.º 1
0
        public JsonResult ContinueStory(Guid sessionGuid, string playId, int?choiceIndex)
        {
            //if we have a playId, this is a permaplay story, and we load it from permaplays insetad of inkJsons.
            string inkJsonPath = string.IsNullOrEmpty(playId)
                ? _rootPath + _inkJsonsDirectory + sessionGuid + ".json"
                : _rootPath + _permaplaysDirectory + playId + ".json";
            string gameStatePath = _rootPath + _gameStatesDirectory + sessionGuid + ".json";

            //if no choices at all, this means we're starting a new story.
            if (!choiceIndex.HasValue)
            {
                return(StartNewStory(inkJsonPath, gameStatePath));
            }

            //there was a choiceIndex selected, which means we're continuing a saved story.
            var story = InkMethods.RestoreStory(inkJsonPath, gameStatePath);

            //much happens in the Ink runtime here.
            story.ChooseChoiceIndex(choiceIndex.Value);

            List <InkOutputMessage> outputs = InkMethods.GetStoryOutputMessages(story);

            InkMethods.SaveStory(gameStatePath, story);

            return(Json(outputs));
        }
Exemplo n.º 2
0
        private JsonResult StartNewStory(string inkJsonPath, string gameStatePath)
        {
            var story = Models.InkMethods.LoadEmptyStory(inkJsonPath);

            List <InkOutputMessage> outputs = InkMethods.GetStoryOutputMessages(story);

            InkMethods.SaveStory(gameStatePath, story);

            return(Json(outputs));
        }
Exemplo n.º 3
0
        /*
         * public JsonResult methods
         *
         */

        public JsonResult ContinueStory(Guid sessionGuid, string playId, int?choiceIndex)
        {
            // if we have a playId, this is a permaplay story, and we load it from permaplays instead of inkJsons.
            string inkJsonPath = string.IsNullOrEmpty(playId)
                ? _rootPath + _inkJsonsDirectory + sessionGuid + ".json"
                : _rootPath + _permaplaysDirectory + playId + ".json";
            string gameStatePath = _rootPath + _gameStatesDirectory + sessionGuid + ".json";

            try
            {
                // if no choices at all, this means we're starting a new story.
                if (!choiceIndex.HasValue)
                {
                    return(StartNewStory(inkJsonPath, gameStatePath));
                }

                // there was a choiceIndex selected, which means we're continuing a saved story.
                var story = InkMethods.RestoreStory(inkJsonPath, gameStatePath);

                // much happens in the Ink runtime here.
                story.ChooseChoiceIndex(choiceIndex.Value);

                List <InkOutputMessage> outputs = InkMethods.GetStoryOutputMessages(story);

                InkMethods.SaveStory(gameStatePath, story);

                return(base.Json(outputs));
            }
            catch (Exception x)
            {
                string message;

                if (x is StoryException)
                {
                    // we don't need to log story exceptions. we do want to parse the exception message a little.
                    message = GetStoryExceptionMessage((StoryException)x);
                }
                else
                {
                    _logger.LogError(Environment.NewLine + "HANDLED EXCEPTION IN Home/ContinueStory" + Environment.NewLine + x.ToString(), null);

                    message = "Some especially weird error occurred. If you get this message repeatedly, please file an issue at https://github.com/MattConrad/Quill/issues "
                              + $"with a copy of this error text (/Home/ContinueStory {DateTime.Now})";
                }

                CateError[] errors = new CateError[] { new CateError {
                                                           Message = message, LineNumber = -1
                                                       } };
                return(base.Json(new { errors }));
            }
        }