MUSICVOL.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. namespace OpenVIII.Fields.Scripts.Instructions
  3. {
  4. /// <summary>
  5. /// Set the volume of the music.
  6. /// All the music functions have a parameter that's either 0 or 1.
  7. /// </summary>
  8. internal sealed class MUSICVOL : JsmInstruction
  9. {
  10. private IJsmExpression _flag;
  11. private IJsmExpression _volume;
  12. public MUSICVOL(IJsmExpression flag, IJsmExpression volume)
  13. {
  14. _flag = flag;
  15. _volume = volume;
  16. }
  17. public MUSICVOL(Int32 parameter, IStack<IJsmExpression> stack)
  18. : this(
  19. volume: stack.Pop(),
  20. flag: stack.Pop())
  21. {
  22. }
  23. public override String ToString()
  24. {
  25. return $"{nameof(MUSICVOL)}({nameof(_flag)}: {_flag}, {nameof(_volume)}: {_volume})";
  26. }
  27. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  28. {
  29. sw.Format(formatterContext, services)
  30. .StaticType(nameof(IMusicService))
  31. .Method(nameof(IMusicService.ChangeMusicVolume))
  32. .Argument("volume", _volume)
  33. .Argument("flag", _flag)
  34. .Comment(nameof(MUSICVOL));
  35. }
  36. public override IAwaitable TestExecute(IServices services)
  37. {
  38. ServiceId.Music[services].ChangeMusicVolume(
  39. _volume.Int32(services),
  40. _flag.Boolean(services));
  41. return DummyAwaitable.Instance;
  42. }
  43. }
  44. }