leadercraft/Leadercraft/LeadercraftPlugin.cs

81 lines
2.4 KiB
C#
Raw Normal View History

using System.Reflection;
using IllusionPlugin;
2020-05-14 23:09:39 -04:00
using GamecraftModdingAPI.Utility;
using Leadercraft.Scoring;
2020-05-14 23:09:39 -04:00
using Leadercraft.Server;
namespace Leadercraft
{
2020-08-23 11:49:30 -04:00
public class LeadercraftPlugin : IEnhancedPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin'
{
2020-05-14 23:09:39 -04:00
public static float LoopDelay = 0.1f;
2020-08-23 11:49:30 -04:00
public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; // mod name
2020-08-23 11:49:30 -04:00
public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); // mod & assembly version
2020-05-14 23:09:39 -04:00
internal static LeadercraftApi Api = null;
private static string tokenUrl =
#if DEBUG
"http://192.168.122.229:1337/token";
#else
"https://leadercraft.exmods.org/s/token";
2020-05-14 23:09:39 -04:00
#endif
private static string criteriaUrl =
#if DEBUG
"http://192.168.122.229:7048/criteria";
2020-05-14 23:09:39 -04:00
#else
"https://leadercraft.exmods.org/c/criteria";
2020-05-14 23:09:39 -04:00
#endif
public static void BuildApi()
{
if (Api == null)
{
if (!Tools.IsSteamAvailable)
{
Logging.MetaLog("Steam is unavailable :(");
2020-05-14 23:09:39 -04:00
return;
}
Api = new LeadercraftApi(Tools.UserId, tokenUrl, criteriaUrl);
GamecraftModdingAPI.Utility.Logging.MetaLog("Leadercraft API initialized");
2020-05-14 23:09:39 -04:00
}
}
// called when Gamecraft shuts down
2020-08-23 11:49:30 -04:00
public override void OnApplicationQuit()
{
// Shutdown this mod
GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has shutdown");
// Shutdown the Gamecraft modding API last
GamecraftModdingAPI.Main.Shutdown();
}
// called when Gamecraft starts up
2020-08-23 11:49:30 -04:00
public override void OnApplicationStart()
{
// Initialize the Gamecraft modding API first
GamecraftModdingAPI.Main.Init();
// check out the modding API docs here: https://mod.exmods.org/
// Initialize this mod
GamecraftModdingAPI.App.Game.Simulate += (_, __) => State.StartPlayingGame();
GamecraftModdingAPI.App.Game.Edit += (_, __) => State.StopPlayingGame();
GamecraftModdingAPI.App.Game.Enter += (_, __) => State.EnterGame();
GamecraftModdingAPI.App.Game.Exit += (_, __) => State.ExitGame();
GamecraftModdingAPI.Utility.Logging.MetaLog($"{Name} has started up");
2020-05-14 23:09:39 -04:00
// Debug mode
//Debug();
}
2020-08-23 11:49:30 -04:00
public static void Debug()
2020-05-14 23:09:39 -04:00
{
tokenUrl = "http://192.168.122.229:1337/token";
criteriaUrl = "http://192.168.122.229:7048/criteria";
}
}
}