/// <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); } }
/// <inheritdoc /> public override void Write(SceneWriter output, ElementContext context) { if (this.active || context.OutputAttribute.FalseKeyword != Keyword.Undefined) { base.Write(output, context); } }
/// <inheritdoc /> public override void Write(SceneWriter output, ElementContext context) { if (this.active) { base.Write(output, context); } }
/// <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); }); } }
/// <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); }
/// <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; }
/// <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); } }
/// <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; } } }
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()); }
/// <inheritdoc /> protected override void WriteContent(SceneWriter output, ElementContext context) { // There is no inner content for this type of element }