A stable modding interface between Techblox and mods https://mod.exmods.org/
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.

74 lines
2.8KB

  1. using System.Collections.Generic;
  2. using Svelto.Tasks;
  3. using Svelto.Tasks.Enumerators;
  4. using Unity.Mathematics;
  5. using TechbloxModdingAPI.App;
  6. using TechbloxModdingAPI.Blocks;
  7. using TechbloxModdingAPI.Tests;
  8. namespace TechbloxModdingAPI.Players
  9. {
  10. #if TEST
  11. /// <summary>
  12. /// Player test cases. Not accessible in release versions.
  13. /// </summary>
  14. [APITestClass]
  15. public static class PlayerTests
  16. {
  17. [APITestCase(TestType.EditMode)]
  18. public static void ExistsTest()
  19. {
  20. if (!Assert.Equal(Player.Exists(PlayerType.Local), true, "Local player does not exist.", "Local player detected.")) return;
  21. Assert.Equal(Player.Count(), 1u, "Player.Count() is not one, possibly because it failed silently.", "Player count is one for single player game.");
  22. }
  23. [APITestCase(TestType.EditMode)]
  24. public static void PositionTest()
  25. {
  26. Player p = new Player(PlayerType.Local);
  27. if (!Assert.Errorless(() => { p.Teleport(0, 0, 0, relative: false); }, "Player.Teleport(origin) errored: ", "Player teleported to origin successfully.")) return;
  28. if (!Assert.CloseTo(p.Position, float3.zero, "Player is not close to origin despite being teleported there.", "Player.Position is at origin.")) return;
  29. if (!Assert.Errorless(() => { p.Position = float3.zero + 1; }, "Player.Position = origin+1 errored: ", "Player moved to origin+1.")) return;
  30. Assert.CloseTo(p.Position, float3.zero + 1, "Player is not close to origin+1 despite being teleported there.", "Player.Position is at origin+1.");
  31. }
  32. [APITestCase(TestType.Game)]
  33. public static void SeatEventTestBuild()
  34. {
  35. Player.LocalPlayer.SeatEntered += Assert.CallsBack<PlayerSeatEventArgs>("SeatEntered");
  36. Player.LocalPlayer.SeatExited += Assert.CallsBack<PlayerSeatEventArgs>("SeatExited");
  37. Block.PlaceNew(BlockIDs.DriverSeat, -1f);
  38. }
  39. [APITestCase(TestType.SimulationMode)]
  40. public static IEnumerator<TaskContract> SeatEventTestSim()
  41. {
  42. var seats = Game.CurrentGame().GetBlocksInGame(BlockIDs.DriverSeat);
  43. if (seats.Length == 0)
  44. {
  45. Assert.Fail("No driver seat found!");
  46. yield break;
  47. }
  48. if (seats[0] is Seat seat)
  49. Assert.Errorless(() => Player.LocalPlayer.EnterSeat(seat), "Failed to enter seat.",
  50. "Entered seat successfully.");
  51. else
  52. Assert.Fail("Found a seat that is not a seat!");
  53. yield return new WaitForSecondsEnumerator(1).Continue();
  54. Assert.Errorless(() => Player.LocalPlayer.ExitSeat(), "Failed to exit seat.",
  55. "Exited seat successfully.");
  56. }
  57. [APITestCase(TestType.Menu)]
  58. public static void InvalidStateTest()
  59. {
  60. if (!Assert.Errorless(() => { Player.Count(); }, "Player.Count() errored in menu.", "Player.Count() succeeded in menu.")) return;
  61. Assert.Equal(Player.Count(), 0u, "Player.Count() is not zero in menu.", "Player count is zero in menu as expected.");
  62. }
  63. }
  64. #endif
  65. }