feat: add import/export
This commit is contained in:
parent
82a7e10aa8
commit
1282abae67
@ -1,6 +1,7 @@
|
||||
using Dalamud.Configuration;
|
||||
using Dalamud.Plugin;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using FFXIV_Vibe_Plugin.Triggers;
|
||||
@ -28,6 +29,7 @@ namespace FFXIV_Vibe_Plugin {
|
||||
public List<Pattern> PatternList = new();
|
||||
public string BUTTPLUG_SERVER_HOST { get; set; } = "127.0.0.1";
|
||||
public int BUTTPLUG_SERVER_PORT { get; set; } = 12345;
|
||||
public string EXPORT_DIR = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"\\FFXIV_Vibe_Plugin";
|
||||
public List<Triggers.Trigger> TRIGGERS { get; set; } = new();
|
||||
public Dictionary<string, FFXIV_Vibe_Plugin.Device.Device> VISITED_DEVICES = new();
|
||||
|
||||
@ -37,6 +39,11 @@ namespace FFXIV_Vibe_Plugin {
|
||||
private DalamudPluginInterface? pluginInterface;
|
||||
public void Initialize(DalamudPluginInterface pluginInterface) {
|
||||
this.pluginInterface = pluginInterface;
|
||||
try {
|
||||
Directory.CreateDirectory(this.EXPORT_DIR);
|
||||
} catch {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
public void Save() {
|
||||
this.pluginInterface!.SavePluginConfig(this);
|
||||
@ -121,6 +128,8 @@ namespace FFXIV_Vibe_Plugin {
|
||||
public string BUTTPLUG_SERVER_HOST { get; set; } = "127.0.0.1";
|
||||
public int BUTTPLUG_SERVER_PORT { get; set; } = 12345;
|
||||
|
||||
public string EXPORT_DIR = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\FFXIV_Vibe_Plugin";
|
||||
|
||||
public List<Triggers.Trigger> TRIGGERS { get; set; } = new();
|
||||
|
||||
public Dictionary<string, FFXIV_Vibe_Plugin.Device.Device> VISITED_DEVICES = new();
|
||||
|
@ -3,8 +3,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using FFXIV_Vibe_Plugin.Device;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FFXIV_Vibe_Plugin.Triggers {
|
||||
public enum KIND {
|
||||
@ -20,7 +22,7 @@ namespace FFXIV_Vibe_Plugin.Triggers {
|
||||
Self
|
||||
}
|
||||
|
||||
public class Trigger : IComparable<Trigger> {
|
||||
public class Trigger : IComparable<Trigger>, IEquatable<Trigger> {
|
||||
private static readonly int _initAmountMinValue = -1;
|
||||
private static readonly int _initAmountMaxValue = 10000000;
|
||||
|
||||
@ -49,8 +51,10 @@ namespace FFXIV_Vibe_Plugin.Triggers {
|
||||
public List<TriggerDevice> Devices = new();
|
||||
|
||||
public Trigger(string name) {
|
||||
this.Id = Guid.NewGuid().ToString();
|
||||
this.Name = name;
|
||||
byte[] textBytes = System.Text.Encoding.UTF8.GetBytes(name);
|
||||
byte[] hashed = SHA256.Create().ComputeHash(textBytes);
|
||||
this.Id = BitConverter.ToString(hashed).Replace("-", String.Empty);
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
@ -59,13 +63,12 @@ namespace FFXIV_Vibe_Plugin.Triggers {
|
||||
|
||||
public int CompareTo(Trigger? other) {
|
||||
if(other == null) { return 1; }
|
||||
if(this.SortOder < other.SortOder) {
|
||||
return 1;
|
||||
} else if(this.SortOder > other.SortOder) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
return other.Name.CompareTo(this.Name);
|
||||
}
|
||||
|
||||
public bool Equals(Trigger? other) {
|
||||
if (other == null) return false;
|
||||
return this.Name.Equals(other.Name);
|
||||
}
|
||||
|
||||
public string GetShortID() {
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Dalamud libs
|
||||
using ImGuiNET;
|
||||
@ -14,6 +15,11 @@ using Dalamud.Interface.Windowing;
|
||||
|
||||
// FFXIV_Vibe_Plugin libs
|
||||
using FFXIV_Vibe_Plugin.Commons;
|
||||
using FFXIV_Vibe_Plugin.Triggers;
|
||||
|
||||
// Json libs
|
||||
using Newtonsoft.Json;
|
||||
using System.Text.Json;
|
||||
|
||||
|
||||
|
||||
@ -74,6 +80,7 @@ namespace FFXIV_Vibe_Plugin {
|
||||
// Trigger
|
||||
private Triggers.Trigger? SelectedTrigger = null;
|
||||
private string triggersViewMode = "default"; // default|edit|delete;
|
||||
string _tmp_exportPatternResponse = "";
|
||||
|
||||
/** Constructor */
|
||||
|
||||
@ -331,6 +338,39 @@ namespace FFXIV_Vibe_Plugin {
|
||||
}
|
||||
ImGui.EndChild();
|
||||
|
||||
ImGui.TextColored(ImGuiColors.DalamudViolet, "Trigger Import/Export Settings");
|
||||
ImGui.BeginChild("###EXPORT_OPTIONS_ZONE", new Vector2(-1, 100f), true);
|
||||
{
|
||||
// Init table
|
||||
ImGui.BeginTable("###EXPORT_OPTIONS_TABLE", 2);
|
||||
|
||||
ImGui.TableSetupColumn("###EXPORT_OPTIONS_TABLE_COL1", ImGuiTableColumnFlags.WidthFixed, 250);
|
||||
ImGui.TableSetupColumn("###EXPORT_OPTIONS_TABLE_COL2", ImGuiTableColumnFlags.WidthStretch);
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.Text("Trigger Import/Export Directory:");
|
||||
ImGui.TableNextColumn();
|
||||
if (ImGui.InputText("###EXPORT_DIRECTORY_INPUT", ref this.ConfigurationProfile.EXPORT_DIR, 200)) {
|
||||
this.Configuration.EXPORT_DIR = this.ConfigurationProfile.EXPORT_DIR;
|
||||
this.Configuration.Save();
|
||||
}
|
||||
ImGui.TableNextRow();
|
||||
ImGui.TableNextColumn();
|
||||
if (ImGui.Button("Clear Import/Export Directory")) {
|
||||
if (!this.ConfigurationProfile.EXPORT_DIR.Equals("")) {
|
||||
try {
|
||||
foreach (var filename in Directory.GetFiles(this.ConfigurationProfile.EXPORT_DIR)) {
|
||||
File.Delete(filename);
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
ImGui.SameLine();
|
||||
ImGuiComponents.HelpMarker("Deletes ALL files in the Import/Export Directory.");
|
||||
ImGui.EndTable();
|
||||
}
|
||||
ImGui.EndChild();
|
||||
|
||||
if (this.ConfigurationProfile.VERBOSE_CHAT || this.ConfigurationProfile.VERBOSE_SPELL) {
|
||||
ImGui.TextColored(ImGuiColors.DalamudOrange, "Please, disabled chat and spell logs for better ingame performance.");
|
||||
}
|
||||
@ -771,6 +811,16 @@ namespace FFXIV_Vibe_Plugin {
|
||||
ImGui.TableNextRow();
|
||||
}
|
||||
ImGui.EndTable();
|
||||
ImGui.Separator();
|
||||
|
||||
if (ImGui.Button("Export")) {
|
||||
this._tmp_exportPatternResponse = export_trigger(SelectedTrigger);
|
||||
}
|
||||
ImGui.SameLine();
|
||||
ImGuiComponents.HelpMarker("Writes this trigger to your export directory.");
|
||||
ImGui.SameLine();
|
||||
ImGui.Text($"{this._tmp_exportPatternResponse}");
|
||||
ImGui.Separator();
|
||||
|
||||
ImGui.TextColored(ImGuiColors.DalamudViolet, "Actions & Devices");
|
||||
ImGui.Separator();
|
||||
@ -964,7 +1014,12 @@ namespace FFXIV_Vibe_Plugin {
|
||||
}
|
||||
|
||||
if (ImGui.Button("Add")) {
|
||||
Triggers.Trigger trigger = new("New Trigger");
|
||||
int index = 0;
|
||||
Triggers.Trigger trigger = new($"New Trigger {index}");
|
||||
while (this.TriggerController.GetTriggers().Contains(trigger)) {
|
||||
index++;
|
||||
trigger = new($"New Trigger {index}");
|
||||
}
|
||||
this.TriggerController.AddTrigger(trigger);
|
||||
this.SelectedTrigger = trigger;
|
||||
this.triggersViewMode = "edit";
|
||||
@ -974,7 +1029,28 @@ namespace FFXIV_Vibe_Plugin {
|
||||
if (ImGui.Button("Delete")) {
|
||||
this.triggersViewMode = "delete";
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("Import Triggers")) {
|
||||
if (!this.ConfigurationProfile.EXPORT_DIR.Equals("")) {
|
||||
try {
|
||||
foreach (var filename in Directory.GetFiles(this.ConfigurationProfile.EXPORT_DIR)) {
|
||||
Trigger t = JsonConvert.DeserializeObject<Trigger>(File.ReadAllText(filename));
|
||||
// Remove any triggers with the same name due to .Equals override
|
||||
this.TriggerController.RemoveTrigger(t);
|
||||
// Import the new trigger
|
||||
this.TriggerController.AddTrigger(t);
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("Export All")) {
|
||||
if (!this.ConfigurationProfile.EXPORT_DIR.Equals("")) {
|
||||
foreach (Trigger t in this.TriggerController.GetTriggers()) {
|
||||
export_trigger(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawPatternsTab() {
|
||||
@ -1119,6 +1195,22 @@ namespace FFXIV_Vibe_Plugin {
|
||||
this._tmp_void = "50:1000|100:2000";
|
||||
ImGui.InputText("###HELP_PATTERN_EXAMPLE", ref this._tmp_void, 50);
|
||||
}
|
||||
public string export_trigger(Trigger trigger) {
|
||||
if (this.ConfigurationProfile.EXPORT_DIR.Equals("")) {
|
||||
return "No export directory has been set! Set one in Options.";
|
||||
} else {
|
||||
try {
|
||||
File.WriteAllText(
|
||||
Path.Join(this.ConfigurationProfile.EXPORT_DIR, $"{trigger.Name}.json"),
|
||||
JsonConvert.SerializeObject(trigger, Formatting.Indented)
|
||||
);
|
||||
return "Successfully exported trigger!";
|
||||
} catch {
|
||||
return "Something went wrong while exporting!";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
23
README.md
23
README.md
@ -29,6 +29,7 @@ A plugin for FFXIV that will let you vibe your controller or toys.
|
||||
- Custom patterns per motor (save, with easy import, export).
|
||||
- Vibe or trigger a pattern on HP Changed
|
||||
- HP Changed can have custom min/max values or percentages
|
||||
- Export/Import triggers
|
||||
|
||||
## Prerequisites
|
||||
- [FFXIV QuickLauncher](https://github.com/goatcorp/FFXIVQuickLauncher).
|
||||
@ -64,7 +65,27 @@ not make a living from it.
|
||||
|
||||
|
||||
## Build yourself
|
||||
You can build yourself, instructions are here: [Build yourself](./Docs/BUILD.md)
|
||||
You can build yourself, instructions are here: [Build yourself](./Docs/BUILD.md)o
|
||||
|
||||
## Import triggers
|
||||
1. Start the game and make sure the plugin is working.
|
||||
2. On your computer, go to your `%userprofile%` folder (eg: C:\\Users\\<yourname>) folder.
|
||||
3. The go in the `FFXIV\_Vibe\_Plugin` folder (or create if it does not exists)
|
||||
4. Add the triggers file you want to import (eg: `MyTrigger.json`)
|
||||
5. In the plugin go to the `Triggers` tab and click on `Import Triggers` at the bottom.
|
||||
|
||||
That's it. It should load all of the triggers.
|
||||
Note: you can define a custom directory to read/write in the `Options` tab.
|
||||
|
||||
## Export triggers
|
||||
1. On your computre, go to your `%userprofile%` folder (eg: C:\\Users\\<yourname>) folder.
|
||||
2. Go to the `FFXIV\_Vibe\_Plugin` folder (or create if it does not exists)
|
||||
3. In the plugin, go to the `Triggers` tab.
|
||||
4. Create your triggers (if they does not exist).
|
||||
5. Select the trigger you want to export and click on the `Export` button.
|
||||
|
||||
That's it. You should see them in your userprofile directory.
|
||||
Note: you can define a custom directory to read/write in the `Options` tab.
|
||||
|
||||
## USB Dongle vs Lovense Dongle vs Other
|
||||
We recommend you to use a bluetooth dongle. Here is the one we are using: [TP-Link Nano USB Dongle Bluetooth 5.0](https://www.amazon.fr/gp/product/B09C25VRXD/ref=as_li_tl?ie=UTF8&camp=1642&creative=6746&creativeASIN=B09C25VRXD&linkCode=as2&tag=kaciexx-21&linkId=8b6c8c6e693ab549216c2dacad34e03b)
|
||||
|
Loading…
Reference in New Issue
Block a user