Esempio n. 1
0
        private bool Write(DialogGroupElement dialog)
        {
            if (dialog == null)
            {
                return(false);
            }

            string[] charLine      = BreakIntoLines(dialog.Character, _settings.CharacterWidth);
            string[] parenthetical = string.IsNullOrEmpty(dialog.Parenthetical) ? new string[0] : BreakIntoLines(dialog.Parenthetical, _settings.ParentheticalWidth);
            string[] dialogtext    = BreakIntoLines(dialog.Dialog.ToString(), _settings.DialogWidth);

            int totalLines = charLine.Length + parenthetical.Length + 3;

            if (!HaveRoomFor(totalLines) && dialogtext.Length <= 2)
            {
                NewPage();
            }

            IndentInches(_settings.CharacterIndent);
            foreach (string line in charLine)
            {
                WriteLine(line);
            }
            if (parenthetical.Length > 0)
            {
                IndentInches(-_settings.CharacterIndent + _settings.ParentheticalIndent);
                for (int x = 0, m = parenthetical.Length; x < m; x++)
                {
                    WriteLine((x == 0 ? "(" : "")
                              + parenthetical[x]
                              + (x == m - 1 ? ")" : "")
                              );
                }
                IndentInches(-_settings.ParentheticalIndent);
            }
            else
            {
                IndentInches(-_settings.CharacterIndent);
            }

            WriteContentNode(dialog.Dialog, PageSettings.InPoints(_settings.DialogWidth), (x) => PageSettings.InPoints(_settings.DialogIndent), l => {
                if (l > 0)
                {
                    MoveDown(1);
                    WriteRightAlignedLine("(CONTINUED)");
                    NewPage();
                    IndentInches(_settings.CharacterIndent);
                    foreach (string line in charLine)
                    {
                        WriteLine(line);
                    }
                    IndentInches(-_settings.CharacterIndent + _settings.ParentheticalIndent);
                    WriteLine("(CONT'D)");
                    IndentInches(-_settings.ParentheticalIndent);
                }
            });

            /*
             * foreach (string line in dialogtext) {
             *      WriteLine(line);
             * }
             * IndentInches(-_settings.DialogIndent);
             */

            EmptyLine();

            return(true);
        }
Esempio n. 2
0
        public void Transform(IEnumerable <Element> elements, Stream output)
        {
            string headerTemplate = ReadEmbeddedResource("PageOfBob.NFountain.Plugins.Templates.Script-Header.html");
            string footer         = ReadEmbeddedResource("PageOfBob.NFountain.Plugins.Templates.Script-Footer.html");

            string title = "NFountain Script";

            Element first = elements.FirstOrDefault();

            if (first == null)
            {
                return;
            }

            if (first.Type == ElementType.Title)
            {
                TitleElement element  = (TitleElement)first;
                var          titleKVP = element.Parts.FirstOrDefault(x => x.Key.ToLowerInvariant() == "title");
                if (!string.IsNullOrWhiteSpace(titleKVP.Value))
                {
                    title = titleKVP.Value.Trim();
                }
            }


            TextWriter w = new StreamWriter(output);

            w.Write(headerTemplate.Replace("{{Script Name}}", title));


            foreach (Element item in elements)
            {
                switch (item.Type)
                {
                case ElementType.None:

                    break;

                case ElementType.Heading:
                    w.Write("<div class\"heading\">");
                    w.Write(HtmlEncode(((HeadingElement)item).Value));
                    w.WriteLine("</div>");
                    break;

                case ElementType.DialogGroup:
                    w.WriteLine("<div class=\"dialog-group\">");
                    DialogGroupElement grp = (DialogGroupElement)item;

                    w.Write("<div class=\"dialog-character\">");
                    w.Write(HtmlEncode(grp.Character));
                    w.WriteLine("</div>");

                    if (!string.IsNullOrWhiteSpace(grp.Parenthetical))
                    {
                        w.Write("<div class=\"dialog-character\">");
                        w.Write(HtmlEncode(grp.Character));
                        w.WriteLine("</div>");
                    }

                    w.Write("<div class=\"dialog-text\">");
                    w.Write(HtmlEncode(grp.Dialog));
                    w.WriteLine("</div>");

                    w.WriteLine("</div>");
                    break;

                case ElementType.Action:
                    w.Write("<div class\"action\">");
                    w.Write(HtmlEncode(((ActionElement)item).Content));
                    w.WriteLine("</div>");
                    break;

                case ElementType.Boneyard:
                    w.Write("<!--");
                    w.Write(HtmlEncode(((BoneyardElement)item).Value));
                    w.WriteLine("-->");
                    break;

                case ElementType.Transition:
                    w.Write("<div class\"transition\">");
                    w.Write(HtmlEncode(((TransitionElement)item).Value));
                    w.WriteLine("</div>");
                    break;

                case ElementType.CenteredText:
                    w.Write("<div class\"centered\">");
                    w.Write(HtmlEncode(((CenteredTextElement)item).Content));
                    w.WriteLine("</div>");
                    break;

                case ElementType.LineBreak:
                    w.WriteLine("<br class=\"line-break\" />");
                    break;

                case ElementType.NoteBlock:
                    w.Write("<div class\"note\" style=\"display: none\">");
                    w.Write(HtmlEncode(((NoteBlockElement)item).Value));
                    w.WriteLine("</div>");
                    break;

                case ElementType.Section:
                    w.Write("<div class\"section\">");
                    w.Write(HtmlEncode(((SectionElement)item).Value));
                    w.WriteLine("</div>");
                    break;

                case ElementType.Synopsis:
                    w.Write("<div class\"synopsis\" style=\"display: none\">");
                    w.Write(HtmlEncode(((SynopsisElement)item).Value));
                    w.WriteLine("</div>");
                    break;

                case ElementType.Title:
                    w.WriteLine("<div class=\"title-group\">");
                    foreach (var kvp in ((TitleElement)item).Parts)
                    {
                        w.Write("<div class=\"title-part\">");
                        w.Write(HtmlEncode(kvp.Value));
                        w.WriteLine("</div>");
                    }
                    w.WriteLine("</div>");
                    break;

                default:
                    throw new Exception("Invalid value for ElementType");
                }
            }


            w.Write(footer);
            w.Flush();
        }
Esempio n. 3
0
        private bool Write(DialogGroupElement dialog)
        {
            if (dialog == null)
                return false;

            string[] charLine = BreakIntoLines(dialog.Character, _settings.CharacterWidth);
            string[] parenthetical = string.IsNullOrEmpty(dialog.Parenthetical) ? new string[0] : BreakIntoLines(dialog.Parenthetical, _settings.ParentheticalWidth);
            string[] dialogtext = BreakIntoLines(dialog.Dialog.ToString(), _settings.DialogWidth);

            int totalLines = charLine.Length + parenthetical.Length + 3;

            if (!HaveRoomFor(totalLines) && dialogtext.Length <= 2) {
                NewPage();
            }

            IndentInches(_settings.CharacterIndent);
            foreach (string line in charLine) {
                WriteLine(line);
            }
            if (parenthetical.Length > 0) {
                IndentInches(-_settings.CharacterIndent + _settings.ParentheticalIndent);
                for(int x=0, m = parenthetical.Length; x<m; x++) {
                    WriteLine( (x == 0 ? "(" : "")
                        + parenthetical[x]
                        + (x == m - 1 ? ")" : "")
                    );
                }
                IndentInches(-_settings.ParentheticalIndent);
            } else {
                IndentInches(-_settings.CharacterIndent);
            }

            WriteContentNode(dialog.Dialog, PageSettings.InPoints(_settings.DialogWidth), (x) => PageSettings.InPoints(_settings.DialogIndent), l => {
             	if (l > 0) {
             		MoveDown(1);
             		WriteRightAlignedLine("(CONTINUED)");
             		NewPage();
             		IndentInches(_settings.CharacterIndent);
                    foreach (string line in charLine) {
                        WriteLine(line);
                    }
             		IndentInches(-_settings.CharacterIndent + _settings.ParentheticalIndent);
             		WriteLine("(CONT'D)");
             		IndentInches(-_settings.ParentheticalIndent);
             	}
            });

            /*
            foreach (string line in dialogtext) {
                WriteLine(line);
            }
            IndentInches(-_settings.DialogIndent);
            */

            EmptyLine();

            return true;
        }