Add Vibration and MaxDuration in Plugin setting, randomize shock/vibrate
This commit is contained in:
parent
55efc96a1a
commit
910e9d1473
|
@ -7,10 +7,12 @@ namespace DalamudShock
|
||||||
public class Configuration : IPluginConfiguration
|
public class Configuration : IPluginConfiguration
|
||||||
{
|
{
|
||||||
public int Version { get; set; }
|
public int Version { get; set; }
|
||||||
|
|
||||||
public string openshockApiKey { get; set; } = string.Empty;
|
public string openshockApiKey { get; set; } = string.Empty;
|
||||||
public string OpenshockShockerID { get; set; } = string.Empty;
|
public string OpenshockShockerID { get; set; } = string.Empty;
|
||||||
public int MaxValue { get; set; } = 100;
|
public int MaxValue { get; set; } = 100;
|
||||||
|
public int MaxDuration { get; set; } = 30;
|
||||||
|
public bool IsVibrationAllowed { get; set; } = false;
|
||||||
|
|
||||||
public bool IsConfigWindowMovable { get; set; } = true;
|
public bool IsConfigWindowMovable { get; set; } = true;
|
||||||
|
|
||||||
|
@ -18,5 +20,6 @@ namespace DalamudShock
|
||||||
{
|
{
|
||||||
Plugin.PluginInterface.SavePluginConfig(this);
|
Plugin.PluginInterface.SavePluginConfig(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,27 +101,33 @@ namespace DalamudShock
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isVibrationAllowed = Configuration.IsVibrationAllowed;
|
||||||
|
|
||||||
var random = new Random();
|
var random = new Random();
|
||||||
int intensity = random.Next(0, Configuration.MaxValue);
|
var intensity = random.Next(0, Configuration.MaxValue);
|
||||||
int duration = random.Next(1000, 25000);
|
var duration = random.Next(1000, Configuration.MaxDuration);
|
||||||
|
|
||||||
|
var type = isVibrationAllowed && random.Next(2) == 0 ? "shock" : "vibrate";
|
||||||
|
|
||||||
var requestData = new[]
|
var requestData = new[]
|
||||||
{
|
{
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
id = Configuration.OpenshockShockerID,
|
id = Configuration.OpenshockShockerID,
|
||||||
type = "shock",
|
type = type,
|
||||||
intensity = intensity,
|
intensity = intensity,
|
||||||
duration = duration
|
duration = duration
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var jsonContent = JsonConvert.SerializeObject(requestData);
|
var jsonContent = JsonConvert.SerializeObject(requestData);
|
||||||
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
|
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
using var client = new HttpClient();
|
using var client = new HttpClient();
|
||||||
client.DefaultRequestHeaders.Add("OpenShockToken", Configuration.openshockApiKey);
|
client.DefaultRequestHeaders.Add("OpenShockToken", Configuration.openshockApiKey);
|
||||||
client.DefaultRequestHeaders.Add("User-Agent", "FFXIV:DalamudShock/0.2");
|
client.DefaultRequestHeaders.Add("User-Agent",
|
||||||
|
"Dalamud/0.2 (Windows; U; Windows NT 10.4; x64) AppleWebKit/602.39 (KHTML, like Gecko)");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -129,7 +135,7 @@ namespace DalamudShock
|
||||||
|
|
||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
PluginLog.Information("Shock sent successfully with intensity {0} and duration {1} ms.", intensity, duration);
|
PluginLog.Information("{0} sent successfully with intensity {1} and duration {2} ms.", type, intensity, duration);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace DalamudShock.Windows
|
||||||
{
|
{
|
||||||
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
|
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
|
||||||
ImGuiWindowFlags.NoScrollWithMouse;
|
ImGuiWindowFlags.NoScrollWithMouse;
|
||||||
Size = new Vector2(400, 200);
|
Size = new Vector2(600, 400);
|
||||||
SizeCondition = ImGuiCond.Always;
|
SizeCondition = ImGuiCond.Always;
|
||||||
Configuration = plugin.Configuration;
|
Configuration = plugin.Configuration;
|
||||||
}
|
}
|
||||||
|
@ -37,19 +37,36 @@ namespace DalamudShock.Windows
|
||||||
if (ImGui.InputText("OpenShock API Key", ref apiKey, 100))
|
if (ImGui.InputText("OpenShock API Key", ref apiKey, 100))
|
||||||
{
|
{
|
||||||
Configuration.openshockApiKey = apiKey;
|
Configuration.openshockApiKey = apiKey;
|
||||||
Configuration.Save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var shockerID = Configuration.OpenshockShockerID;
|
var shockerID = Configuration.OpenshockShockerID;
|
||||||
if (ImGui.InputText("OpenShock Shocker ID", ref shockerID, 100))
|
if (ImGui.InputText("OpenShock Shocker ID", ref shockerID, 100))
|
||||||
{
|
{
|
||||||
Configuration.OpenshockShockerID = shockerID;
|
Configuration.OpenshockShockerID = shockerID;
|
||||||
Configuration.Save();
|
|
||||||
}
|
}
|
||||||
var maxShock = Configuration.MaxValue;
|
var maxShock = Configuration.MaxValue;
|
||||||
if (ImGui.SliderInt("Intensity cap", ref maxShock, 0, 100))
|
if (ImGui.SliderInt("Intensity cap", ref maxShock, 0, 100))
|
||||||
{
|
{
|
||||||
Configuration.MaxValue = maxShock;
|
Configuration.MaxValue = maxShock;
|
||||||
|
}
|
||||||
|
var maxLength = Configuration.MaxDuration;
|
||||||
|
if (ImGui.SliderInt("Duration Cap (sec)", ref maxLength, 1, 30))
|
||||||
|
{
|
||||||
|
// Map the value from [1, 30] to [1000, 30000]
|
||||||
|
Configuration.MaxDuration = MapValue(maxLength, 1, 30, 1000, 30000);
|
||||||
|
}
|
||||||
|
int MapValue(int value, int fromMin, int fromMax, int toMin, int toMax)
|
||||||
|
{
|
||||||
|
return (int)((float)(value - fromMin) / (fromMax - fromMin) * (toMax - toMin) + toMin);
|
||||||
|
}
|
||||||
|
bool isVibrationAllowed = Configuration.IsVibrationAllowed;
|
||||||
|
if (ImGui.Checkbox("Allow Vibration", ref isVibrationAllowed))
|
||||||
|
{
|
||||||
|
Configuration.IsVibrationAllowed = isVibrationAllowed;
|
||||||
|
}
|
||||||
|
ImGui.Spacing();
|
||||||
|
if (ImGui.Button("Save Configuration"))
|
||||||
|
{
|
||||||
Configuration.Save();
|
Configuration.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +1,74 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using System.Net.Http;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace DalamudShock.Windows;
|
namespace DalamudShock.Windows
|
||||||
|
|
||||||
public class MainWindow : Window, IDisposable
|
|
||||||
{
|
{
|
||||||
private Plugin Plugin;
|
public class MainWindow : Window, IDisposable
|
||||||
|
|
||||||
public MainWindow(Plugin plugin)
|
|
||||||
: base("This window has no reason to exist##With a hidden ID", ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
|
|
||||||
{
|
{
|
||||||
SizeConstraints = new WindowSizeConstraints
|
private Plugin Plugin;
|
||||||
|
private string openShockVersion = "Fetching...";
|
||||||
|
|
||||||
|
public MainWindow(Plugin plugin)
|
||||||
|
: base("This window has no reason to exist##69420",
|
||||||
|
ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
|
||||||
{
|
{
|
||||||
MinimumSize = new Vector2(375, 330),
|
SizeConstraints = new WindowSizeConstraints
|
||||||
MaximumSize = new Vector2(float.MaxValue, float.MaxValue)
|
{
|
||||||
};
|
MinimumSize = new Vector2(375, 330),
|
||||||
|
MaximumSize = new Vector2(float.MaxValue, float.MaxValue)
|
||||||
|
};
|
||||||
|
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
}
|
FetchOpenShockVersion();
|
||||||
|
|
||||||
public void Dispose() { }
|
|
||||||
|
|
||||||
public override void Draw()
|
|
||||||
{
|
|
||||||
if (ImGui.Button("Show Settings"))
|
|
||||||
{
|
|
||||||
Plugin.ToggleConfigUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.Spacing();
|
public void Dispose() { }
|
||||||
ImGui.Text("We aren't beating the bottom allegations with this one");
|
|
||||||
|
public override void Draw()
|
||||||
|
{
|
||||||
|
if (ImGui.Button("Show Settings"))
|
||||||
|
{
|
||||||
|
Plugin.ToggleConfigUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.Spacing();
|
||||||
|
ImGui.Text("We aren't beating the bottom allegations with this one");
|
||||||
|
|
||||||
|
// Display the OpenShock version
|
||||||
|
ImGui.Spacing();
|
||||||
|
ImGui.Text($"OpenShock Version: #{openShockVersion}");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void FetchOpenShockVersion()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var client = new HttpClient();
|
||||||
|
client.DefaultRequestHeaders.Add("OpenShockToken", Plugin.Configuration.openshockApiKey);
|
||||||
|
client.DefaultRequestHeaders.Add("User-Agent",
|
||||||
|
"Dalamud/0.2 (Windows; U; Windows NT 10.4; x64) AppleWebKit/602.39 (KHTML, like Gecko)");
|
||||||
|
|
||||||
|
var response = await client.GetAsync("https://api.shocklink.net/1");
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
var responseData = await response.Content.ReadAsStringAsync();
|
||||||
|
var version = JsonConvert.DeserializeObject<dynamic>(responseData)?.data?.commit;
|
||||||
|
openShockVersion = version?.ToString().Substring(0, 7) ?? "Unknown";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
openShockVersion = "Error fetching version";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
openShockVersion = $"Error: {ex.Message}";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue