Follow the leader
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

90 lines
2.7KB

  1. using System.Reflection;
  2. using IllusionPlugin;
  3. using GamecraftModdingAPI.Utility;
  4. using Leadercraft.Server;
  5. namespace Leadercraft
  6. {
  7. public class LeadercraftPlugin : IPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin'
  8. {
  9. public static float LoopDelay = 0.1f;
  10. public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; // mod name
  11. public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); // mod & assembly version
  12. internal static LeadercraftApi Api = null;
  13. private static string tokenUrl =
  14. #if DEBUG
  15. "http://192.168.122.229:1337/token";
  16. #else
  17. "https://leadercraft.exmods.org/token";
  18. #endif
  19. private static string criteriaUrl =
  20. #if DEBUG
  21. "http://192.168.122.229:7048/criteria";
  22. #else
  23. "https://board.exmods.org/criteria";
  24. #endif
  25. public static void BuildApi()
  26. {
  27. if (Api == null)
  28. {
  29. if (!Tools.IsSteamAvailable)
  30. {
  31. Logging.MetaDebugLog("Steam is unavailable :(");
  32. return;
  33. }
  34. Api = new LeadercraftApi(Tools.UserId, tokenUrl, criteriaUrl);
  35. GamecraftModdingAPI.Utility.Logging.MetaDebugLog("Leadercraft API initialized");
  36. }
  37. }
  38. // called when Gamecraft shuts down
  39. public void OnApplicationQuit()
  40. {
  41. // Shutdown this mod
  42. GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has shutdown");
  43. // Shutdown the Gamecraft modding API last
  44. GamecraftModdingAPI.Main.Shutdown();
  45. }
  46. // called when Gamecraft starts up
  47. public void OnApplicationStart()
  48. {
  49. // Initialize the Gamecraft modding API first
  50. GamecraftModdingAPI.Main.Init();
  51. // check out the modding API docs here: https://mod.exmods.org/
  52. // Initialize this mod
  53. GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(new Scoring.LeadercraftSimEventHandler());
  54. GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(new Scoring.LeadercraftGameEventHandler());
  55. GamecraftModdingAPI.Events.EventManager.AddEventHandler(new Scoring.GameLoop());
  56. GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has started up");
  57. // Debug mode
  58. Debug();
  59. }
  60. // unused methods
  61. public void OnFixedUpdate() { } // called once per physics update
  62. public void OnLevelWasInitialized(int level) { }// called after a level is initialized
  63. public void OnLevelWasLoaded(int level) { } // called after a level is loaded
  64. public void OnUpdate() { } // called once per rendered frame (frame update)
  65. public static void Debug()
  66. {
  67. tokenUrl = "http://192.168.122.229:1337/token";
  68. criteriaUrl = "http://192.168.122.229:7048/criteria";
  69. }
  70. }
  71. }