Jsm.Control.If.ElseIfSegment.cs 1.9 KB

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