Jsm.Control.If.ElseIfSegment.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using OpenVIII.Fields.Scripts.Instructions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace OpenVIII.Fields.Scripts
  7. {
  8. public static partial class Jsm
  9. {
  10. public static partial class Control
  11. {
  12. public sealed partial class If
  13. {
  14. private sealed class ElseIfSegment : Segment
  15. {
  16. public ElseIfSegment(Int32 from, Int32 to)
  17. : base(from, to)
  18. {
  19. }
  20. public override void ToString(StringBuilder sb)
  21. {
  22. sb.Append("else if(");
  23. sb.Append(Jpf);
  24. sb.AppendLine(")");
  25. FormatBranch(sb, GetBodyInstructions());
  26. }
  27. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  28. {
  29. sw.Append("else if(");
  30. ((JPF)_list[0]).Format(sw, formatterContext, services);
  31. sw.AppendLine(")");
  32. FormatBranch(sw, formatterContext, services, GetBodyInstructions());
  33. }
  34. public JPF Jpf => ((JPF)_list[0]);
  35. public IEnumerable<IJsmInstruction> GetBodyInstructions()
  36. {
  37. return _list.Skip(1);
  38. }
  39. }
  40. }
  41. }
  42. }
  43. }