Moar Gamecraft commands!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.6KB

  1. using System;
  2. using RobocraftX.GUI.CommandLine;
  3. using RobocraftX.Multiplayer;
  4. using RobocraftX.StateSync;
  5. using RobocraftX.Character;
  6. using Svelto.ECS;
  7. using Unity.Entities;
  8. using UnityEngine;
  9. using uREPL;
  10. using Svelto.Context;
  11. using RobocraftX;
  12. using Svelto.ECS.EntityStructs;
  13. using Unity.Mathematics;
  14. using RobocraftX.Character.Camera;
  15. using RobocraftX.Character.Factories;
  16. namespace ExtraCommands.Basics
  17. {
  18. [CustomCommand("RotateTo")]
  19. class RotatePlayerCommandEngine : CustomCommandEngine
  20. {
  21. public RotatePlayerCommandEngine(UnityContext<FullGameCompositionRoot> ctxHolder, EnginesRoot enginesRoot, World physW, Action reloadGame, MultiplayerInitParameters mpParams) : base(ctxHolder, enginesRoot, physW, reloadGame, mpParams)
  22. {
  23. }
  24. public override void Ready()
  25. {
  26. CustomCommandUtility.Register<float, float>("RotateAbsolute", RotateAbsoluteCommand, "Rotate the player camera to the entered rotation");
  27. CustomCommandUtility.Register<float, float>("RotateRelative", RotateRelativeCommand, "Rotate the player camera by the entered rotation");
  28. }
  29. private void RotateAbsoluteCommand(float vertical, float horizontal)
  30. {
  31. uint count;
  32. CharacterCameraEntityStruct[] cameras = entitiesDB.QueryEntities<CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup, out count);
  33. int num2 = 0;
  34. while ((long)num2 < (long)((ulong)count))
  35. {
  36. cameras[num2].eulerRotation.x = vertical;
  37. cameras[num2].eulerRotation.y = horizontal;
  38. // TODO: Multiplayer compatibility
  39. /*
  40. uint num3;
  41. InputEntityStruct[] array;
  42. if (this.entitiesDB.TryQueryEntitiesAndIndex<InputEntityStruct>(item2[num2].ID.entityID, PlayersExclusiveGroups.LocalPlayers, out num3, out array))
  43. {
  44. desiredDistance = math.clamp(desiredDistance, 0f, item[num2].maxDistance);
  45. array[(int)num3].cameraZoomFactor = math.unlerp(item[num2].minDistance, item[num2].maxDistance, desiredDistance);
  46. }
  47. */
  48. num2++;
  49. }
  50. }
  51. private void RotateRelativeCommand(float vertical, float horizontal)
  52. {
  53. float2 angleDelta = new float2(vertical, horizontal);
  54. uint count;
  55. ValueTuple<CharacterCameraSettingsEntityStruct[], CharacterCameraEntityStruct[]> tuple = this.entitiesDB.QueryEntities<CharacterCameraSettingsEntityStruct, CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup, out count);
  56. CharacterCameraSettingsEntityStruct[] settings = tuple.Item1;
  57. CharacterCameraEntityStruct[] cameras = tuple.Item2;
  58. int num2 = 0;
  59. while ((long)num2 < (long)((ulong)count))
  60. {
  61. CharacterCameraMovementUtility.UpdateCameraRotationFromDelta(ref cameras[num2], in settings[num2], angleDelta);
  62. // TODO: Multiplayer compatibility
  63. /*
  64. uint num3;
  65. InputEntityStruct[] array;
  66. if (this.entitiesDB.TryQueryEntitiesAndIndex<InputEntityStruct>(item2[num2].ID.entityID, PlayersExclusiveGroups.LocalPlayers, out num3, out array))
  67. {
  68. desiredDistance = math.clamp(desiredDistance, 0f, item[num2].maxDistance);
  69. array[(int)num3].cameraZoomFactor = math.unlerp(item[num2].minDistance, item[num2].maxDistance, desiredDistance);
  70. }
  71. */
  72. num2++;
  73. }
  74. }
  75. public override void Dispose()
  76. {
  77. CustomCommandUtility.Unregister("RotateAbsolute");
  78. CustomCommandUtility.Unregister("RotateRelative");
  79. }
  80. }
  81. }