WINCLOSE.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. namespace OpenVIII.Fields.Scripts.Instructions
  3. {
  4. /// <summary>
  5. /// Close the last window created by AMES.
  6. /// I haven't tried this for other types of windows...
  7. /// </summary>
  8. internal sealed class WINCLOSE : JsmInstruction
  9. {
  10. private Int32 _channel;
  11. public WINCLOSE(Int32 channel)
  12. {
  13. _channel = channel;
  14. }
  15. public WINCLOSE(Int32 parameter, IStack<IJsmExpression> stack)
  16. : this(
  17. channel: ((Jsm.Expression.PSHN_L)stack.Pop()).Int32())
  18. {
  19. }
  20. public override String ToString()
  21. {
  22. return $"{nameof(WINCLOSE)}({nameof(_channel)}: {_channel})";
  23. }
  24. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  25. {
  26. sw.Format(formatterContext, services)
  27. .StaticType(nameof(IMessageService))
  28. .Method(nameof(IMessageService.Close))
  29. .Argument("channel", _channel)
  30. .Comment(nameof(WINCLOSE));
  31. }
  32. public override IAwaitable TestExecute(IServices services)
  33. {
  34. ServiceId.Message[services].Close(_channel);
  35. return DummyAwaitable.Instance;
  36. }
  37. }
  38. }