EFFECTPLAY2.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. namespace OpenVIII.Fields.Scripts.Instructions
  3. {
  4. internal sealed class EFFECTPLAY2 : JsmInstruction
  5. {
  6. private readonly Int32 _fieldSoundIndex;
  7. private IJsmExpression _pan;
  8. private IJsmExpression _volume;
  9. private IJsmExpression _channel;
  10. public EFFECTPLAY2(Int32 fieldSoundIndex, IJsmExpression pan, IJsmExpression volume, IJsmExpression channel)
  11. {
  12. _fieldSoundIndex = fieldSoundIndex;
  13. _pan = pan;
  14. _volume = volume;
  15. _channel = channel;
  16. }
  17. public EFFECTPLAY2(Int32 parameter, IStack<IJsmExpression> stack)
  18. : this(parameter,
  19. channel: stack.Pop(),
  20. volume: stack.Pop(),
  21. pan: stack.Pop())
  22. {
  23. }
  24. public override String ToString()
  25. {
  26. return $"{nameof(EFFECTPLAY2)}({nameof(_fieldSoundIndex)}: {_fieldSoundIndex}, {nameof(_pan)}: {_pan}, {nameof(_volume)}: {_volume}, {nameof(_channel)}: {_channel})";
  27. }
  28. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  29. {
  30. var formatter = sw.Format(formatterContext, services);
  31. formatter
  32. .StaticType(nameof(ISoundService))
  33. .Method(nameof(ISoundService.PlaySound))
  34. .Argument("fieldSoundIndex", _fieldSoundIndex)
  35. .Argument("pan", _pan)
  36. .Argument("volume", _volume)
  37. .Argument("channel", _channel)
  38. .Comment(nameof(MUSICLOAD));
  39. }
  40. public override IAwaitable TestExecute(IServices services)
  41. {
  42. ServiceId.Sound[services].PlaySound(_fieldSoundIndex,
  43. _pan.Int32(services),
  44. _volume.Int32(services),
  45. _channel.Int32(services));
  46. return DummyAwaitable.Instance;
  47. }
  48. }
  49. }