1
Fork 0
mirror of https://github.com/redstrate/Auracite.git synced 2025-04-24 05:37:44 +00:00
auracite/dalamud/Auracite/Plugin.cs
Joshua Goins 66f641b7ca Switch around the server/client for Dalamud communication
This is to facilitate support for this feature on the Web, where the
plugin needs to start a server instead of Auracite itself. Otherwise,
the functionality is identical to before.
2024-10-31 21:46:50 -04:00

97 lines
No EOL
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Dalamud.Game.Command;
using Dalamud.Interface.Windowing;
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using EmbedIO;
using EmbedIO.Routing;
using EmbedIO.WebApi;
using Newtonsoft.Json;
namespace Auracite;
public sealed class Plugin : IDalamudPlugin
{
public static IStep? CurrentStep;
private readonly WindowSystem WindowSystem = new("Auracite");
private readonly List<Type> _steps =
[typeof(AppearanceStep), typeof(CurrencyStep), typeof(MiscStep), typeof(PlaytimeStep), typeof(EndStep)];
private int _stepIndex;
private readonly StepWindow StepWindow;
public class Package
{
public string playtime;
public int height;
public int bust_size;
public uint gil;
public bool is_battle_mentor;
public bool is_trade_mentor;
public bool is_novice;
public bool is_returner;
public short player_commendations;
}
public static Package? package;
public Plugin()
{
CommandManager.AddHandler("/auracite", new CommandInfo(OnAuraciteCommand)
{
HelpMessage = "Start the server."
});
StepWindow = new StepWindow();
WindowSystem.AddWindow(StepWindow);
PluginInterface.UiBuilder.Draw += WindowSystem.Draw;
}
[PluginService] internal static IClientState ClientState { get; private set; } = null!;
[PluginService] internal static IDalamudPluginInterface PluginInterface { get; private set; } = null!;
[PluginService] internal static IChatGui ChatGui { get; private set; } = null!;
[PluginService] internal static ICommandManager CommandManager { get; private set; } = null!;
public void Dispose()
{
CurrentStep?.Dispose();
WindowSystem.RemoveAllWindows();
}
private void OnAuraciteCommand(string command, string arguments)
{
if (arguments == "begin" && CurrentStep == null)
{
_stepIndex = -1;
package = new Package();
NextStep();
StepWindow.IsOpen = true;
}
}
private void NextStep()
{
_stepIndex++;
if (_stepIndex >= _steps.Count)
{
CurrentStep?.Dispose();
CurrentStep = null;
StepWindow.IsOpen = false;
return;
}
CurrentStep = (IStep)Activator.CreateInstance(_steps[_stepIndex])!;
CurrentStep.Completed += NextStep;
CurrentStep.Run();
}
}