2020-03-27 20:19:28 -04:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
using IllusionPlugin;
|
2020-05-14 23:09:39 -04:00
|
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
|
|
|
|
|
|
using Leadercraft.Server;
|
2020-03-27 20:19:28 -04:00
|
|
|
|
|
|
|
|
|
namespace Leadercraft
|
|
|
|
|
{
|
|
|
|
|
public class LeadercraftPlugin : IPlugin // 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-03-27 20:19:28 -04:00
|
|
|
|
public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; // mod name
|
|
|
|
|
|
|
|
|
|
public 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/token";
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
private static string criteriaUrl =
|
|
|
|
|
#if DEBUG
|
|
|
|
|
"http://192.168.122.229:7048/criteria";
|
|
|
|
|
#else
|
|
|
|
|
"https://board.exmods.org/criteria";
|
|
|
|
|
#endif
|
|
|
|
|
public static void BuildApi()
|
|
|
|
|
{
|
|
|
|
|
if (Api == null)
|
|
|
|
|
{
|
|
|
|
|
if (!Tools.IsSteamAvailable)
|
|
|
|
|
{
|
|
|
|
|
Logging.MetaDebugLog("Steam is unavailable :(");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Api = new LeadercraftApi(Tools.UserId, tokenUrl, criteriaUrl);
|
|
|
|
|
GamecraftModdingAPI.Utility.Logging.MetaDebugLog("Leadercraft API initialized");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// called when Gamecraft shuts down
|
2020-03-27 20:19:28 -04:00
|
|
|
|
public 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
|
|
|
|
|
public 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
|
2020-05-14 23:09:39 -04:00
|
|
|
|
GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(new Scoring.LeadercraftSimEventHandler());
|
|
|
|
|
GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(new Scoring.LeadercraftGameEventHandler());
|
|
|
|
|
GamecraftModdingAPI.Events.EventManager.AddEventHandler(new Scoring.GameLoop());
|
2020-03-27 20:19:28 -04:00
|
|
|
|
GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has started up");
|
2020-05-14 23:09:39 -04:00
|
|
|
|
|
|
|
|
|
// Debug mode
|
|
|
|
|
Debug();
|
2020-03-27 20:19:28 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unused methods
|
|
|
|
|
|
|
|
|
|
public void OnFixedUpdate() { } // called once per physics update
|
|
|
|
|
|
2020-05-14 23:09:39 -04:00
|
|
|
|
public void OnLevelWasInitialized(int level) { }// called after a level is initialized
|
2020-03-27 20:19:28 -04:00
|
|
|
|
|
|
|
|
|
public void OnLevelWasLoaded(int level) { } // called after a level is loaded
|
|
|
|
|
|
|
|
|
|
public void OnUpdate() { } // called once per rendered frame (frame update)
|
2020-05-14 23:09:39 -04:00
|
|
|
|
|
|
|
|
|
public static void Debug()
|
|
|
|
|
{
|
|
|
|
|
tokenUrl = "http://192.168.122.229:1337/token";
|
|
|
|
|
criteriaUrl = "http://192.168.122.229:7048/criteria";
|
|
|
|
|
}
|
2020-03-27 20:19:28 -04:00
|
|
|
|
}
|
|
|
|
|
}
|