forked from liza/Workshoppa
Change Import/export format to a teamcraft-style list
This means that your new clipboard export would look like: 1x Modified Shark-class Pressure Hull 1x Modified Shark-class Stern 1x Modified Unkiu-class Bow instead of the previous base64 string.
This commit is contained in:
parent
2b5fb62842
commit
9bf055b78c
@ -1,12 +0,0 @@
|
|||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace Workshoppa.Data;
|
|
||||||
|
|
||||||
public class ClipboardItem
|
|
||||||
{
|
|
||||||
[JsonPropertyName("Id")]
|
|
||||||
public uint WorkshopItemId { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("Q")]
|
|
||||||
public int Quantity { get; set; }
|
|
||||||
}
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.RegularExpressions;
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
using Dalamud.Interface.Colors;
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Components;
|
using Dalamud.Interface.Components;
|
||||||
@ -13,7 +13,6 @@ using Dalamud.Plugin.Services;
|
|||||||
using FFXIVClientStructs.FFXIV.Client.Game;
|
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using LLib;
|
using LLib;
|
||||||
using Workshoppa.Data;
|
|
||||||
using Workshoppa.GameData;
|
using Workshoppa.GameData;
|
||||||
|
|
||||||
namespace Workshoppa.Windows;
|
namespace Workshoppa.Windows;
|
||||||
@ -21,7 +20,7 @@ namespace Workshoppa.Windows;
|
|||||||
// FIXME The close button doesn't work near the workshop, either hide it or make it work
|
// FIXME The close button doesn't work near the workshop, either hide it or make it work
|
||||||
internal sealed class MainWindow : LImGui.LWindow
|
internal sealed class MainWindow : LImGui.LWindow
|
||||||
{
|
{
|
||||||
private const string JsonPrefix = "workshoppa:v1:";
|
private static readonly Regex CountAndName = new(@"^(\d{1,5})x?\s+(.*)$", RegexOptions.Compiled);
|
||||||
|
|
||||||
private readonly WorkshopPlugin _plugin;
|
private readonly WorkshopPlugin _plugin;
|
||||||
private readonly DalamudPluginInterface _pluginInterface;
|
private readonly DalamudPluginInterface _pluginInterface;
|
||||||
@ -386,17 +385,28 @@ internal sealed class MainWindow : LImGui.LWindow
|
|||||||
{
|
{
|
||||||
if (ImGui.BeginMenu("Clipboard"))
|
if (ImGui.BeginMenu("Clipboard"))
|
||||||
{
|
{
|
||||||
List<ClipboardItem> fromClipboardItems = new();
|
List<Configuration.QueuedItem> fromClipboardItems = new();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string? clipboardText = GetClipboardText();
|
string? clipboardText = GetClipboardText();
|
||||||
if (!string.IsNullOrWhiteSpace(clipboardText))
|
if (!string.IsNullOrWhiteSpace(clipboardText))
|
||||||
{
|
{
|
||||||
clipboardText = Encoding.UTF8.GetString(Convert.FromBase64String(clipboardText));
|
foreach (var clipboardLine in clipboardText.ReplaceLineEndings().Split(Environment.NewLine))
|
||||||
if (clipboardText.StartsWith(JsonPrefix))
|
|
||||||
{
|
{
|
||||||
clipboardText = clipboardText.Substring(JsonPrefix.Length);
|
var match = CountAndName.Match(clipboardLine);
|
||||||
fromClipboardItems = JsonSerializer.Deserialize<List<ClipboardItem>>(clipboardText) ?? new();
|
if (!match.Success)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var craft = _workshopCache.Crafts.FirstOrDefault(x =>
|
||||||
|
x.Name.Equals(match.Groups[2].Value, StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
if (craft != null && int.TryParse(match.Groups[1].Value, out int quantity))
|
||||||
|
{
|
||||||
|
fromClipboardItems.Add(new Configuration.QueuedItem
|
||||||
|
{
|
||||||
|
WorkshopItemId = craft.WorkshopItemId,
|
||||||
|
Quantity = quantity,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -412,24 +422,20 @@ internal sealed class MainWindow : LImGui.LWindow
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
foreach (var item in fromClipboardItems)
|
foreach (var item in fromClipboardItems)
|
||||||
{
|
{
|
||||||
var craft = _workshopCache.Crafts.FirstOrDefault(x => x.WorkshopItemId == item.WorkshopItemId);
|
var queuedItem =
|
||||||
if (craft != null)
|
_configuration.ItemQueue.FirstOrDefault(x => x.WorkshopItemId == item.WorkshopItemId);
|
||||||
|
if (queuedItem != null)
|
||||||
|
queuedItem.Quantity += item.Quantity;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
var queuedItem =
|
_configuration.ItemQueue.Add(new Configuration.QueuedItem
|
||||||
_configuration.ItemQueue.FirstOrDefault(x => x.WorkshopItemId == item.WorkshopItemId);
|
|
||||||
if (queuedItem != null)
|
|
||||||
queuedItem.Quantity += item.Quantity;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
_configuration.ItemQueue.Add(new Configuration.QueuedItem
|
WorkshopItemId = item.WorkshopItemId,
|
||||||
{
|
Quantity = item.Quantity,
|
||||||
WorkshopItemId = item.WorkshopItemId,
|
});
|
||||||
Quantity = item.Quantity,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
++count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
++count;
|
||||||
}
|
}
|
||||||
|
|
||||||
Save();
|
Save();
|
||||||
@ -441,17 +447,14 @@ internal sealed class MainWindow : LImGui.LWindow
|
|||||||
ImGui.BeginDisabled(_configuration.ItemQueue.Count == 0);
|
ImGui.BeginDisabled(_configuration.ItemQueue.Count == 0);
|
||||||
if (ImGui.MenuItem("Export Queue to Clipboard"))
|
if (ImGui.MenuItem("Export Queue to Clipboard"))
|
||||||
{
|
{
|
||||||
var toClipboardItems = _configuration.ItemQueue.Select(x => new ClipboardItem
|
var toClipboardItems = _configuration.ItemQueue.Select(x =>
|
||||||
{
|
new
|
||||||
WorkshopItemId = x.WorkshopItemId,
|
{
|
||||||
Quantity = x.Quantity
|
_workshopCache.Crafts.Single(y => x.WorkshopItemId == y.WorkshopItemId).Name,
|
||||||
})
|
x.Quantity
|
||||||
.ToList();
|
})
|
||||||
|
.Select(x => $"{x.Quantity}x {x.Name}");
|
||||||
var clipboardText =
|
ImGui.SetClipboardText(string.Join(Environment.NewLine, toClipboardItems));
|
||||||
Convert.ToBase64String(
|
|
||||||
Encoding.UTF8.GetBytes(JsonPrefix + JsonSerializer.Serialize(toClipboardItems)));
|
|
||||||
ImGui.SetClipboardText(clipboardText);
|
|
||||||
|
|
||||||
_chatGui.Print("Copied queue content to clipboard.");
|
_chatGui.Print("Copied queue content to clipboard.");
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0-windows</TargetFramework>
|
<TargetFramework>net7.0-windows</TargetFramework>
|
||||||
<Version>4.0</Version>
|
<Version>4.1</Version>
|
||||||
<LangVersion>11.0</LangVersion>
|
<LangVersion>11.0</LangVersion>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
|
Loading…
Reference in New Issue
Block a user