Jsm.Control.If.IfSegment.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace FF8
  6. {
  7. public static partial class Jsm
  8. {
  9. public static partial class Control
  10. {
  11. public sealed partial class If
  12. {
  13. private sealed class IfSegment : ExecutableSegment
  14. {
  15. private readonly If _aggregator;
  16. public IfSegment(Int32 from, Int32 to, If aggregator)
  17. : base(from, to)
  18. {
  19. _aggregator = aggregator;
  20. }
  21. public override void ToString(StringBuilder sb)
  22. {
  23. sb.Append("if(");
  24. sb.Append((JPF)_list[0]);
  25. sb.AppendLine(")");
  26. FormatBranch(sb, _list.Skip(1));
  27. }
  28. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  29. {
  30. sw.Append("if(");
  31. Jpf.Format(sw, formatterContext, services);
  32. sw.AppendLine(")");
  33. FormatBranch(sw, formatterContext, services, GetBodyInstructions());
  34. foreach (var item in _aggregator.EnumerateElseBlocks())
  35. item.Format(sw, formatterContext, services);
  36. }
  37. public override IScriptExecuter GetExecuter()
  38. {
  39. return new Executer(_aggregator);
  40. }
  41. public JPF Jpf => ((JPF)_list[0]);
  42. public IEnumerable<IJsmInstruction> GetBodyInstructions()
  43. {
  44. return _list.Skip(1);
  45. }
  46. }
  47. }
  48. }
  49. }
  50. }