public void PostParse(Parsed.Fiction parsedFiction)
 {
     foreach (var plugin in _plugins)
     {
         plugin.PostParse(parsedFiction);
     }
 }
 public void PostExport(Parsed.Fiction parsedFiction, Runtime.Story runtimeStory)
 {
     foreach (var plugin in _plugins)
     {
         plugin.PostExport(parsedFiction, runtimeStory);
     }
 }
Пример #3
0
        private Runtime.Story CreateStory(Parsed.Fiction parsedFiction)
        {
            Runtime.Story runtimeStory = null;

            if (_pluginManager != null)
            {
                _pluginManager.PostParse(parsedFiction);
            }

            if (parsedFiction != null && !_hadParseError)
            {
                parsedFiction.countAllVisits = _options.countAllVisits;

                runtimeStory = parsedFiction.ExportRuntime();

                if (_pluginManager != null)
                {
                    _pluginManager.PostExport(parsedFiction, runtimeStory);
                }
            }
            else
            {
                runtimeStory = null;
            }
            return(runtimeStory);
        }
Пример #4
0
        public Runtime.Story Compile(out Parsed.Fiction parsedFiction)
        {
            parsedFiction = Parse();


            _runtimeStory = CreateStory(parsedFiction);

            return(_runtimeStory);
        }
        protected object IncludeStatement()
        {
            Whitespace();

            if (ParseString("INCLUDE") == null)
            {
                return(null);
            }

            Whitespace();

            var filename = (string)Expect(() => ParseUntilCharactersFromString("\n\r"), "filename for include statement");

            filename = filename.TrimEnd(' ', '\t');

            // Working directory should already have been set up relative to the root ink file.
            var fullFilename = _rootParser._fileHandler.ResolveInkFilename(filename);

            if (FilenameIsAlreadyOpen(fullFilename))
            {
                Error("Recursive INCLUDE detected: '" + fullFilename + "' is already open.");
                ParseUntilCharactersFromString("\r\n");
                return(new IncludedFile(null));
            }
            else
            {
                AddOpenFilename(fullFilename);
            }

            Parsed.Fiction includedFiction = null;
            string         includedString  = null;

            try {
                includedString = _rootParser._fileHandler.LoadInkFileContents(fullFilename);
            }
            catch {
                Error("Failed to load: '" + filename + "'");
            }


            if (includedString != null)
            {
                InkParser parser = new InkParser(includedString, filename, _rootParser);
                includedFiction = parser.Parse();
            }

            RemoveOpenFilename(fullFilename);

            // Return valid IncludedFile object even if there were errors when parsing.
            // We don't want to attempt to re-parse the include line as something else,
            // and we want to include the bits that *are* valid, so we don't generate
            // more errors than necessary.
            return(new IncludedFile(includedFiction));
        }
Пример #6
0
        /// <summary>Writes the compiled story to a Fountain file.</summary>
        /// <param name="story">The story.</param>
        /// <param name="options">The options.</param>
        public void WriteStoryToFountainFile(Parsed.Fiction parsedFiction, CommandLineToolOptions options)
        {
            string fountainContent = FountainExponentialAdapter.ConvertToFountainExponential(parsedFiction, options.InputFileName);

            try
            {
                FileSystemInteractor.WriteAllTextToFile(options.RootedOutputFountainFilePath, fountainContent, System.Text.Encoding.UTF8);

                OutputManager.ShowExportComplete(options);
            }
            catch
            {
                ConsoleInteractor.WriteErrorMessage("Could not write to output file '{0}'", options.RootedOutputFilePath);
                ConsoleInteractor.EnvironmentExitWithCodeError1();
            }
        }
Пример #7
0
        /// <summary>Plays the story.</summary>
        /// <param name="story">The story.</param>
        /// <param name="compiler">The compiler.</param>
        /// <param name="options">The options.</param>
        /// <exception cref="Exception"></exception>
        public void PlayStory(Runtime.IStory story, Parsed.Fiction parsedFiction, CommandLineToolOptions options)
        {
            // Always allow ink external fall-backs
            story.allowExternalFunctionFallbacks = true;

            //Capture a CTRL+C key combo so we can restore the console's foreground color back to normal when exiting
            ConsoleInteractor.ResetColorOnCancelKeyPress();

            try
            {
                ConsoleUserInterfaceOptions uiOptions = new ConsoleUserInterfaceOptions()
                {
                    IsAutoPlayActive = false,
                    IsKeepRunningAfterStoryFinishedNeeded = options.IsKeepRunningAfterStoryFinishedNeeded,
                    IsJsonOutputNeeded = options.IsJsonOutputNeeded
                };
                UserInterface.Begin(story, parsedFiction, uiOptions);
            }
            catch (Runtime.StoryException e)
            {
                if (e.Message.Contains("Missing function binding"))
                {
                    Errors.Add(e.Message);

                    // If you get an error while playing, just print immediately
                    PrintAllMessages();
                }
                else
                {
                    throw e;
                }
            }
            catch (Exception e)
            {
                string storyPath = "<END>";
                var    path      = story.state.currentPathString;
                if (path != null)
                {
                    storyPath = path.ToString();
                }
                throw new Exception(e.Message + " (Internal story path: " + storyPath + ")", e);
            }
        }
Пример #8
0
        /// <summary>Creates the story from the file contents.</summary>
        /// <param name="fileContent">Content of the file.</param>
        /// <param name="options">The options.</param>
        /// <param name="compiler">The compiler.</param>
        /// <param name="compileSuccess">if set to <c>true</c> [compile success].</param>
        /// <param name="finished">if set to <c>true</c> [finished].</param>
        /// <returns></returns>
        public Runtime.IStory CreateStory(string fileContent, CommandLineToolOptions options, out Parsed.Fiction parsedFiction)
        {
            Runtime.IStory story = null;

            if (!options.IsInputFileJson)
            {
                // Loading a normal ink file (as opposed to an already compiled JSON file)
                var compiler = CreateCompiler(fileContent, options);

                if (options.IsOnlyShowJsonStatsActive)
                {
                    ShowStats(compiler, options);
                    parsedFiction = null;
                }
                else
                {
                    //Parsed.Fiction parsedFiction = null;
                    // Full compile
                    story = compiler.Compile(out parsedFiction);
                }
            }
            else
            {
                story         = CreateStoryFromJson(fileContent, options);
                parsedFiction = null;
            }

            return(story);
        }
 public IncludedFile(Parsed.Fiction includedFiction)
 {
     this.includedStory = includedFiction;
 }