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.

81 lines
2.4KB

  1. using System.Reflection;
  2. using IllusionPlugin;
  3. using GamecraftModdingAPI.Utility;
  4. using Leadercraft.Scoring;
  5. using Leadercraft.Server;
  6. namespace Leadercraft
  7. {
  8. public class LeadercraftPlugin : IEnhancedPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin'
  9. {
  10. public static float LoopDelay = 0.1f;
  11. public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; // mod name
  12. public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); // mod & assembly version
  13. internal static LeadercraftApi Api = null;
  14. private static string tokenUrl =
  15. #if DEBUG
  16. "http://192.168.122.229:1337/token";
  17. #else
  18. "https://leadercraft.exmods.org/s/token";
  19. #endif
  20. private static string criteriaUrl =
  21. #if DEBUG
  22. "http://192.168.122.229:7048/criteria";
  23. #else
  24. "https://leadercraft.exmods.org/c/criteria";
  25. #endif
  26. public static void BuildApi()
  27. {
  28. if (Api == null)
  29. {
  30. if (!Tools.IsSteamAvailable)
  31. {
  32. Logging.MetaLog("Steam is unavailable :(");
  33. return;
  34. }
  35. Api = new LeadercraftApi(Tools.UserId, tokenUrl, criteriaUrl);
  36. GamecraftModdingAPI.Utility.Logging.MetaLog("Leadercraft API initialized");
  37. }
  38. }
  39. // called when Gamecraft shuts down
  40. public override void OnApplicationQuit()
  41. {
  42. // Shutdown this mod
  43. GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has shutdown");
  44. // Shutdown the Gamecraft modding API last
  45. GamecraftModdingAPI.Main.Shutdown();
  46. }
  47. // called when Gamecraft starts up
  48. public override void OnApplicationStart()
  49. {
  50. // Initialize the Gamecraft modding API first
  51. GamecraftModdingAPI.Main.Init();
  52. // check out the modding API docs here: https://mod.exmods.org/
  53. // Initialize this mod
  54. GamecraftModdingAPI.App.Game.Simulate += (_, __) => State.StartPlayingGame();
  55. GamecraftModdingAPI.App.Game.Edit += (_, __) => State.StopPlayingGame();
  56. GamecraftModdingAPI.App.Game.Enter += (_, __) => State.EnterGame();
  57. GamecraftModdingAPI.App.Game.Exit += (_, __) => State.ExitGame();
  58. GamecraftModdingAPI.Utility.Logging.MetaLog($"{Name} has started up");
  59. // Debug mode
  60. //Debug();
  61. }
  62. public static void Debug()
  63. {
  64. tokenUrl = "http://192.168.122.229:1337/token";
  65. criteriaUrl = "http://192.168.122.229:7048/criteria";
  66. }
  67. }
  68. }