Exemplo n.º 1
0
        public JsonResult PlayInk(string inktext, Guid sessionGuid)
        {
            string newInkPath  = _rootPath + _rawInksDirectory + sessionGuid + ".ink";
            string newJsonPath = _rootPath + _inkJsonsDirectory + sessionGuid + ".json";

            // we don't NEED to write the ink to the ink path any more. does cost some resources, could come in handy with troubleshooting.
            System.IO.File.WriteAllText(newInkPath, inktext);

            var compiler = new Ink.Compiler(inktext, new Ink.Compiler.Options {
                errorHandler = InkErrorHandler
            });

            var story = compiler.Compile();

            // we should either have errors/warnings, or a working story. (probably can have warnings + story, but we treat warnings as errors in Quill.)
            // in a better world, we would send back story, errors, and warnings as separate object properties, and handle whatever we got, but that would
            //   take some rethink and rework and i am out of steam on that. for now, anyway.
            if (_errorsAndWarnings.Any())
            {
                return(base.Json(new { errors = ParseCateErrorsFromErrorStrings(_errorsAndWarnings) }));
            }
            else if (story != null)
            {
                System.IO.File.WriteAllText(newJsonPath, story.ToJson());

                return(base.Json(new { }));
            }
            else
            {
                throw new InvalidOperationException("Story compilation produced no usable story, and also no errors/warnings. This should never happen. If you get this error more than once, please file an issue at https://github.com/MattConrad/Quill/issues .");
            }
        }
Exemplo n.º 2
0
        private void LoadFile(string fileName)
        {
            var story = new Ink.Compiler(File.ReadAllText(fileName));

            inkStory = story.Compile();
        }