Add Vibration and MaxDuration in Plugin setting, randomize shock/vibrate

This commit is contained in:
Mercurio 2024-09-19 15:10:30 +02:00
parent 55efc96a1a
commit 910e9d1473
4 changed files with 96 additions and 32 deletions

View file

@ -11,6 +11,8 @@ namespace DalamudShock
public string openshockApiKey { get; set; } = string.Empty;
public string OpenshockShockerID { get; set; } = string.Empty;
public int MaxValue { get; set; } = 100;
public int MaxDuration { get; set; } = 30;
public bool IsVibrationAllowed { get; set; } = false;
public bool IsConfigWindowMovable { get; set; } = true;
@ -18,5 +20,6 @@ namespace DalamudShock
{
Plugin.PluginInterface.SavePluginConfig(this);
}
}
}

View file

@ -101,27 +101,33 @@ namespace DalamudShock
return;
}
var isVibrationAllowed = Configuration.IsVibrationAllowed;
var random = new Random();
int intensity = random.Next(0, Configuration.MaxValue);
int duration = random.Next(1000, 25000);
var intensity = random.Next(0, Configuration.MaxValue);
var duration = random.Next(1000, Configuration.MaxDuration);
var type = isVibrationAllowed && random.Next(2) == 0 ? "shock" : "vibrate";
var requestData = new[]
{
new
{
id = Configuration.OpenshockShockerID,
type = "shock",
type = type,
intensity = intensity,
duration = duration
}
};
var jsonContent = JsonConvert.SerializeObject(requestData);
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
using var client = new HttpClient();
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
{
@ -129,7 +135,7 @@ namespace DalamudShock
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
{

View file

@ -12,7 +12,7 @@ namespace DalamudShock.Windows
{
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
ImGuiWindowFlags.NoScrollWithMouse;
Size = new Vector2(400, 200);
Size = new Vector2(600, 400);
SizeCondition = ImGuiCond.Always;
Configuration = plugin.Configuration;
}
@ -37,19 +37,36 @@ namespace DalamudShock.Windows
if (ImGui.InputText("OpenShock API Key", ref apiKey, 100))
{
Configuration.openshockApiKey = apiKey;
Configuration.Save();
}
var shockerID = Configuration.OpenshockShockerID;
if (ImGui.InputText("OpenShock Shocker ID", ref shockerID, 100))
{
Configuration.OpenshockShockerID = shockerID;
Configuration.Save();
}
var maxShock = Configuration.MaxValue;
if (ImGui.SliderInt("Intensity cap", ref maxShock, 0, 100))
{
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();
}
}

View file

@ -1,16 +1,20 @@
using System;
using System.Numerics;
using System.Net.Http;
using Dalamud.Interface.Windowing;
using ImGuiNET;
using Newtonsoft.Json;
namespace DalamudShock.Windows;
public class MainWindow : Window, IDisposable
namespace DalamudShock.Windows
{
public class MainWindow : Window, IDisposable
{
private Plugin Plugin;
private string openShockVersion = "Fetching...";
public MainWindow(Plugin plugin)
: base("This window has no reason to exist##With a hidden ID", ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
: base("This window has no reason to exist##69420",
ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoScrollWithMouse)
{
SizeConstraints = new WindowSizeConstraints
{
@ -19,6 +23,7 @@ public class MainWindow : Window, IDisposable
};
Plugin = plugin;
FetchOpenShockVersion();
}
public void Dispose() { }
@ -32,5 +37,38 @@ public class MainWindow : Window, IDisposable
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}";
}
}
}
}