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.

GamecraftModdingAPIPluginTest.cs 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using System;
  2. using System.Reflection;
  3. using Harmony;
  4. // test
  5. using Svelto.ECS;
  6. using RobocraftX.Blocks;
  7. using RobocraftX.Common;
  8. using RobocraftX.SimulationModeState;
  9. using GamecraftModdingAPI.Commands;
  10. using GamecraftModdingAPI.Events;
  11. using GamecraftModdingAPI.Utility;
  12. namespace GamecraftModdingAPI.Tests
  13. {
  14. // unused by design
  15. /// <summary>
  16. /// Modding API implemented as a standalone IPA Plugin.
  17. /// Ideally, GamecraftModdingAPI should be loaded by another mod; not itself
  18. /// </summary>
  19. public class GamecraftModdingAPIPluginTest
  20. #if DEBUG
  21. : IllusionPlugin.IEnhancedPlugin
  22. #endif
  23. {
  24. private static HarmonyInstance harmony { get; set; }
  25. public string[] Filter { get; } = new string[] { "Gamecraft", "GamecraftPreview" };
  26. public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name;
  27. public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
  28. public string HarmonyID { get; } = "org.git.exmods.modtainers.gamecraftmoddingapi";
  29. public void OnApplicationQuit()
  30. {
  31. GamecraftModdingAPI.Main.Shutdown();
  32. }
  33. public void OnApplicationStart()
  34. {
  35. GamecraftModdingAPI.Main.Init();
  36. // in case Steam is not installed/running
  37. // this will crash the game slightly later during startup
  38. //SteamInitPatch.ForcePassSteamCheck = true;
  39. // in case running in a VM
  40. //MinimumSpecsCheckPatch.ForcePassMinimumSpecCheck = true;
  41. // disable some Gamecraft analytics
  42. //AnalyticsDisablerPatch.DisableAnalytics = true;
  43. // disable background music
  44. Logging.MetaDebugLog("Audio Mixers: "+string.Join(",", AudioTools.GetMixers()));
  45. //AudioTools.SetVolume(0.0f, "Music"); // The game now sets this from settings again after this is called :(
  46. // debug/test handlers
  47. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("App Inited event!"); }, () => { },
  48. EventType.ApplicationInitialized, "appinit API debug"));
  49. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Menu Activated event!"); },
  50. () => { Logging.Log("Menu Destroyed event!"); },
  51. EventType.Menu, "menuact API debug"));
  52. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Menu Switched To event!"); }, () => { },
  53. EventType.MenuSwitchedTo, "menuswitch API debug"));
  54. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Activated event!"); },
  55. () => { Logging.Log("Game Destroyed event!"); },
  56. EventType.Game, "gameact API debug"));
  57. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Reloaded event!"); }, () => { },
  58. EventType.GameReloaded, "gamerel API debug"));
  59. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Switched To event!"); }, () => { },
  60. EventType.GameSwitchedTo, "gameswitch API debug"));
  61. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Mode Simulation Switched To event!"); }, () => { },
  62. EventType.SimulationSwitchedTo, "simulationswitch API debug"));
  63. EventManager.AddEventHandler(new SimpleEventHandlerEngine(() => { Logging.Log("Game Mode Build Switched To event!"); }, () => { },
  64. EventType.BuildSwitchedTo, "buildswitch API debug"));
  65. // debug/test commands
  66. if (Dependency.Hell("ExtraCommands"))
  67. {
  68. CommandManager.AddCommand(new SimpleCustomCommandEngine(() => { UnityEngine.Application.Quit(); },
  69. "Exit", "Close Gamecraft without any prompts"));
  70. CommandManager.AddCommand(new SimpleCustomCommandEngine<float>((float d) => { UnityEngine.Camera.main.fieldOfView = d; },
  71. "SetFOV", "Set the player camera's field of view"));
  72. CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
  73. (x, y, z) => {
  74. bool success = GamecraftModdingAPI.Blocks.Movement.MoveConnectedBlocks(
  75. GamecraftModdingAPI.Blocks.BlockIdentifiers.LatestBlockID,
  76. new Unity.Mathematics.float3(x, y, z));
  77. if (!success)
  78. {
  79. GamecraftModdingAPI.Utility.Logging.CommandLogError("Blocks can only be moved in Build mode!");
  80. }
  81. }, "MoveLastBlock", "Move the most-recently-placed block, and any connected blocks by the given offset"));
  82. CommandManager.AddCommand(new SimpleCustomCommandEngine<float, float, float>(
  83. (x, y, z) => { Blocks.Placement.PlaceBlock(Blocks.BlockIDs.AluminiumCube, new Unity.Mathematics.float3(x, y, z)); },
  84. "PlaceAluminium", "Place a block of aluminium at the given coordinates"));
  85. Analytics.DeltaDNAHelper.PlayerLifetimeParameters plp = new Analytics.DeltaDNAHelper.PlayerLifetimeParameters();
  86. CommandManager.AddCommand(new SimpleCustomCommandEngine<string>(
  87. (s) => { Analytics.DeltaDNAHelper.SendActionCompletedEvent(in plp, s.Replace(", ", " ")); },
  88. "SendAnalyticsAction", "Send an analytics action"));
  89. System.Random random = new System.Random(); // for command below
  90. CommandManager.AddCommand(new SimpleCustomCommandEngine(
  91. () => {
  92. if (!GameState.IsSimulationMode())
  93. {
  94. Logging.CommandLogError("You must be in simulation mode for this to work!");
  95. return;
  96. }
  97. Tasks.Repeatable task = new Tasks.Repeatable(() => {
  98. uint count = 0;
  99. EGID[] eBlocks = Blocks.Signals.GetElectricBlocks();
  100. for (uint i = 0u; i < eBlocks.Length; i++)
  101. {
  102. uint[] ids = Blocks.Signals.GetSignalIDs(eBlocks[i]);
  103. for (uint j = 0u; j < ids.Length; j++)
  104. {
  105. Blocks.Signals.SetSignalByID(ids[j], (float)random.NextDouble());
  106. count++;
  107. }
  108. }
  109. Logging.MetaDebugLog($"Did the thing on {count} inputs");
  110. },
  111. () => { return GameState.IsSimulationMode(); });
  112. Tasks.Scheduler.Schedule(task);
  113. }, "RandomizeSignalsInputs", "Do the thing"));
  114. }
  115. // dependency test
  116. if (Dependency.Hell("GamecraftScripting", new Version("0.0.1.0")))
  117. {
  118. Logging.LogWarning("You're in GamecraftScripting dependency hell");
  119. }
  120. else
  121. {
  122. Logging.Log("Compatible GamecraftScripting detected");
  123. }
  124. }
  125. public void OnFixedUpdate() { }
  126. public void OnLateUpdate() { }
  127. public void OnLevelWasInitialized(int level) { }
  128. public void OnLevelWasLoaded(int level) { }
  129. public void OnUpdate() { }
  130. }
  131. }