update 14
This commit is contained in:
1 parent
e0ddd32744
commit
da592f9860
15 files changed
+261
-286
No files matched your search
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Timers;
|
||||
using Dalamud.Plugin.Ipc;
|
||||
|
||||
namespace Waypoints
|
||||
{
|
||||
public class WotsitIpc
|
||||
{
|
||||
private ICallGateSubscriber<string, string, string, uint, string> _registerWithSearch;
|
||||
private ICallGateSubscriber<string, bool> _invoke;
|
||||
private ICallGateSubscriber<string, bool> _unregisterAll;
|
||||
private Timer _timer;
|
||||
|
||||
private Dictionary<string, (uint, uint, Vector3)> _map = new();
|
||||
|
||||
public WotsitIpc()
|
||||
{
|
||||
_registerWithSearch = Plugin.PluginInterface.GetIpcSubscriber<string, string, string, uint, string>("FA.RegisterWithSearch");
|
||||
_unregisterAll = Plugin.PluginInterface.GetIpcSubscriber<string, bool>("FA.UnregisterAll");
|
||||
|
||||
_invoke = Plugin.PluginInterface.GetIpcSubscriber<string, bool>("FA.Invoke");
|
||||
_invoke.Subscribe(Invoke);
|
||||
_timer = new Timer(5000);
|
||||
_timer.Elapsed += (sender, e) => RetryInit();
|
||||
if (!Update())
|
||||
{
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void RetryInit()
|
||||
{
|
||||
_registerWithSearch = Plugin.PluginInterface.GetIpcSubscriber<string, string, string, uint, string>("FA.RegisterWithSearch");
|
||||
_unregisterAll = Plugin.PluginInterface.GetIpcSubscriber<string, bool>("FA.UnregisterAll");
|
||||
|
||||
_invoke = Plugin.PluginInterface.GetIpcSubscriber<string, bool>("FA.Invoke");
|
||||
_invoke.Subscribe(Invoke);
|
||||
if (Update())
|
||||
{
|
||||
_timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
UnregisterAll();
|
||||
}
|
||||
|
||||
public bool Update()
|
||||
{
|
||||
_map.Clear();
|
||||
if (!UnregisterAll())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var kvp in Plugin.Configuration.Waypoints)
|
||||
{
|
||||
string guid = _registerWithSearch.InvokeFunc(
|
||||
Plugin.PluginInterface.InternalName,
|
||||
$"Waypoint: {kvp.Key}",
|
||||
$"Waypoint: {kvp.Key}",
|
||||
66472
|
||||
);
|
||||
|
||||
_map.Add(guid, (kvp.Value.Item1, kvp.Value.Item2, kvp.Value.Item3));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Invoke(string guid)
|
||||
{
|
||||
if (!_map.TryGetValue(guid, out var value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Utils.OpenMapAt(value.Item1, value.Item2, value.Item3);
|
||||
}
|
||||
|
||||
public bool UnregisterAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
_unregisterAll.InvokeFunc(Plugin.PluginInterface.InternalName);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user