CTURNL.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. namespace OpenVIII.Fields.Scripts.Instructions
  3. {
  4. /// <summary>
  5. /// Turns this entity.
  6. /// </summary>
  7. internal sealed class CTURNL : JsmInstruction
  8. {
  9. private IJsmExpression _angle;
  10. private IJsmExpression _frameDuration;
  11. public CTURNL(IJsmExpression angle, IJsmExpression frameDuration)
  12. {
  13. _angle = angle;
  14. _frameDuration = frameDuration;
  15. }
  16. public CTURNL(Int32 parameter, IStack<IJsmExpression> stack)
  17. : this(
  18. frameDuration: stack.Pop(),
  19. angle: stack.Pop())
  20. {
  21. }
  22. public override String ToString()
  23. {
  24. return $"{nameof(CTURNL)}({nameof(_angle)}: {_angle}, {nameof(_frameDuration)}: {_frameDuration})";
  25. }
  26. public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
  27. {
  28. sw.Format(formatterContext, services)
  29. .Await()
  30. .Property(nameof(FieldObject.Model))
  31. .Method(nameof(FieldObjectModel.Rotate))
  32. .Argument("angle", _angle)
  33. .Argument("frameDuration", _frameDuration)
  34. .Comment(nameof(CTURNL));
  35. }
  36. public override IAwaitable TestExecute(IServices services)
  37. {
  38. FieldObject currentObject = ServiceId.Field[services].Engine.CurrentObject;
  39. Degrees degrees = Degrees.FromAngle256(_angle.Int32(services));
  40. Int32 frameDuration = _frameDuration.Int32(services);
  41. currentObject.Model.Rotate(-degrees, frameDuration);
  42. return DummyAwaitable.Instance;
  43. }
  44. }
  45. }