Beispiel #1
0
 /// <summary>Write this element to the scene file.</summary>
 /// <param name="output"></param>
 public void Write(SceneWriter output)
 {
     if (this.Active)
     {
         this.Element.Write(output, this);
     }
 }
Beispiel #2
0
 /// <inheritdoc />
 public override void Write(SceneWriter output, ElementContext context)
 {
     if (this.active || context.OutputAttribute.FalseKeyword != Keyword.Undefined)
     {
         base.Write(output, context);
     }
 }
Beispiel #3
0
 /// <inheritdoc />
 public override void Write(SceneWriter output, ElementContext context)
 {
     if (this.active)
     {
         base.Write(output, context);
     }
 }
Beispiel #4
0
        /// <summary>
        /// Write the inner content of this element.
        /// </summary>
        /// <param name="output"></param>
        /// <param name="context"></param>
        protected virtual void WriteContent(SceneWriter output, ElementContext context)
        {
            bool?space = context.OutputAttribute.IsString ? (bool?)false : null;

            if (context.OutputAttribute.OutputString)
            {
                output.Append(this.ToString(), space);
            }
            else
            {
                context.Children.ForEach(child =>
                {
                    child.Write(child.OutputAttribute.Outside ? this.outsideWriter : output);
                });
            }
        }
Beispiel #5
0
        /// <inheritdoc />
        protected override void WriteContent(SceneWriter output, ElementContext context)
        {
            if (context.OutputAttribute.IsCollection && this.RealValue.GetType().IsArray)
            {
                IEnumerable <string> e = ((IEnumerable)this.RealValue)
                                         .Cast <object>()
                                         .Where(o => o != null)
                                         .Select(o => o.ToString());

                this.Value = string.Join(context.OutputAttribute.CollectionJoin ?? " ", e);
            }

            if (context.OutputAttribute.Direction)
            {
                if (this.RealValue is Vector v)
                {
                    this.Value = v.ToString(true);
                }
            }

            if (context.OutputAttribute.Float)
            {
                switch (this.RealValue)
                {
                case Vector v:
                    if (v.x == v.y && v.x == v.z)
                    {
                        this.Value = v.x.ToString();
                    }

                    break;

                case Color c:
                    if (c.Identifier == null && c.Red == c.Green && c.Red == c.Blue)
                    {
                        this.Value = c.Red.ToString();
                    }

                    break;
                }
            }

            output.Append(this.Value);
        }
Beispiel #6
0
        /// <summary>Write the end of this element.</summary>
        /// <param name="output"></param>
        /// <param name="context"></param>
        protected virtual void WriteEnd(SceneWriter output, ElementContext context)
        {
            if (context.OutputAttribute.Indent)
            {
                output.Unindent(context.OutputAttribute.IndentNewLine);
            }

            bool?space = context.OutputAttribute.IsString ? (bool?)false : null;

            output.Append(context.OutputAttribute.GetContentEnd(context), space);

            if (!context.OutputAttribute.GroupNext)
            {
                output.AppendLine();
            }

            output.Append(this.outsideWriter.ToString());
            this.outsideWriter = null;
        }
Beispiel #7
0
        /// <summary>Write the start of this element, which is usually the keyword.</summary>
        /// <param name="output"></param>
        /// <param name="context"></param>
        protected virtual void WriteStart(SceneWriter output, ElementContext context)
        {
            this.outsideWriter = new SceneWriter {
                IndentLevel = output.IndentLevel
            };

            string keyword = this.GetKeyword(context);

            if (!string.IsNullOrEmpty(keyword))
            {
                output.Append(keyword);
            }

            output.Append(context.OutputAttribute.GetContentStart(context));
            if (context.OutputAttribute.Indent)
            {
                output.Indent(context.OutputAttribute.IndentNewLine);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Write this element to the output.
        /// </summary>
        /// <param name="output">The output.</param>
        /// <param name="context">The element context.</param>
        public virtual void Write(SceneWriter output, ElementContext context)
        {
            int startPos    = output.Length;
            int startIndent = output.IndentLevel;

            this.WriteStart(output, context);
            int contentPos = output.Length;

            this.WriteContent(output, context);

            if (context.OutputAttribute.OnlyWithContent && output.Length == contentPos)
            {
                output.Length      = startPos;
                output.IndentLevel = startIndent;
            }
            else
            {
                bool newLine = false;
                if (context.OutputAttribute.Indent)
                {
                    string content = output.SubString(contentPos).Trim();
                    if (content.IndexOf('\n') == -1)
                    {
                        output.Length = contentPos;
                        output.Unspace();
                        output.Append(content);
                        if (context.OutputAttribute.IndentNewLine)
                        {
                            context.OutputAttribute.IndentNewLine = false;
                            newLine = true;
                        }
                    }
                }

                this.WriteEnd(output, context);

                if (newLine)
                {
                    context.OutputAttribute.IndentNewLine = true;
                }
            }
        }
Beispiel #9
0
        public string Write()
        {
            this.IncludeDirectives = new DirectiveCollection();

            SceneWriter    output       = new SceneWriter();
            ElementContext sceneContext = new ElementContext(null, this);

            sceneContext.LoadChildren(true);

            ElementContext context = sceneContext.Children.FirstOrDefault(c => c.Element == this.IncludeDirectives);

            foreach (string includeFile in this.Include.Files)
            {
                this.IncludeDirectives.Directives.Add(Directive.Include(includeFile));
            }
            context?.LoadChildren();

            this.GenerateDependentScenes();

            sceneContext.Write(output);
            return(output.ToString());
        }
Beispiel #10
0
 /// <inheritdoc />
 protected override void WriteContent(SceneWriter output, ElementContext context)
 {
     // There is no inner content for this type of element
 }