v2/v3 clipboard support

This commit is contained in:
RisaDev
2024-02-04 22:26:40 +03:00
parent 74fd503272
commit 695375d93c
6 changed files with 139 additions and 24 deletions

View File

@@ -0,0 +1,16 @@
using System;
using System.Numerics;
namespace CustomizePlus.Configuration.Data.Version2;
[Serializable]
public struct V2BoneEditsContainer
{
public Vector3 Position { get; set; } = Vector3.Zero;
public Vector3 Rotation { get; set; } = Vector3.Zero;
public Vector3 Scale { get; set; } = Vector3.One;
public V2BoneEditsContainer()
{
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
namespace CustomizePlus.Configuration.Data.Version2;
[Serializable]
public class Version2Profile
{
public static Dictionary<string, bool> BoneVisibility = new();
public string CharacterName { get; set; } = string.Empty;
public string ScaleName { get; set; } = string.Empty;
public bool BodyScaleEnabled { get; set; } = true;
public Dictionary<string, V2BoneEditsContainer> Bones { get; set; } = new();
}

View File

@@ -0,0 +1,38 @@
using CustomizePlus.Configuration.Data.Version2;
using CustomizePlus.Configuration.Data.Version3;
using CustomizePlus.Core.Data;
using System.Numerics;
namespace CustomizePlus.Configuration.Helpers;
internal static class V2ProfileToV3Converter
{
public static Version3Profile Convert(Version2Profile v2Profile)
{
Version3Profile newProfile = new()
{
CharacterName = v2Profile.CharacterName,
ProfileName = v2Profile.ScaleName,
Enabled = v2Profile.BodyScaleEnabled
};
foreach (var kvp in v2Profile.Bones)
{
var novelValues = kvp.Value.Position != Vector3.Zero
|| kvp.Value.Rotation != Vector3.Zero
|| kvp.Value.Scale != Vector3.One;
if (novelValues || kvp.Key == Constants.RootBoneName)
{
newProfile.Bones[kvp.Key] = new V3BoneTransform
{
Translation = kvp.Value.Position,
Rotation = kvp.Value.Rotation,
Scaling = kvp.Value.Scale
};
}
}
return newProfile;
}
}

View File

@@ -25,11 +25,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="Configuration\Data\Version2\**" />
<Compile Remove="Util\**" /> <Compile Remove="Util\**" />
<EmbeddedResource Remove="Configuration\Data\Version2\**" />
<EmbeddedResource Remove="Util\**" /> <EmbeddedResource Remove="Util\**" />
<None Remove="Configuration\Data\Version2\**" />
<None Remove="Util\**" /> <None Remove="Util\**" />
</ItemGroup> </ItemGroup>

View File

@@ -26,6 +26,11 @@ using CustomizePlus.Profiles.Data;
using CustomizePlus.Templates.Events; using CustomizePlus.Templates.Events;
using CustomizePlus.Profiles.Events; using CustomizePlus.Profiles.Events;
using CustomizePlus.Templates.Data; using CustomizePlus.Templates.Data;
using CustomizePlus.Configuration.Helpers;
using CustomizePlus.Configuration.Data.Version3;
using CustomizePlus.GameData.Data;
using static OtterGui.Classes.MessageService;
using CustomizePlus.Configuration.Data.Version2;
namespace CustomizePlus.UI.Windows.MainWindow.Tabs.Templates; namespace CustomizePlus.UI.Windows.MainWindow.Tabs.Templates;
@@ -90,6 +95,8 @@ public class TemplateFileSystemSelector : FileSystemSelector<Template, TemplateS
_popupSystem = popupSystem; _popupSystem = popupSystem;
_popupSystem.RegisterPopup("template_editor_active_warn", "You need to stop bone editing before doing this action"/*, false, new Vector2(5, 12)*/); _popupSystem.RegisterPopup("template_editor_active_warn", "You need to stop bone editing before doing this action"/*, false, new Vector2(5, 12)*/);
_popupSystem.RegisterPopup("clipboard_data_not_longterm", "Warning: clipboard data is not designed to be used as long-term way of storing your templates.\nCompatibility of clipboard data between different Customize+ is not guaranteed."/*, false, new Vector2(5, 12)*/);
_popupSystem.RegisterPopup("clipboard_data_unsupported_version", "Clipboard data you are trying to use cannot be used in this version of Customize+.");
_templateChangedEvent.Subscribe(OnTemplateChange, TemplateChanged.Priority.TemplateFileSystemSelector); _templateChangedEvent.Subscribe(OnTemplateChange, TemplateChanged.Priority.TemplateFileSystemSelector);
_profileChangedEvent.Subscribe(OnProfileChange, ProfileChanged.Priority.TemplateFileSystemSelector); _profileChangedEvent.Subscribe(OnProfileChange, ProfileChanged.Priority.TemplateFileSystemSelector);
@@ -159,37 +166,78 @@ public class TemplateFileSystemSelector : FileSystemSelector<Template, TemplateS
if (!ImGuiUtil.OpenNameField("##NewTemplate", ref _newName)) if (!ImGuiUtil.OpenNameField("##NewTemplate", ref _newName))
return; return;
try
{
if (_clipboardText != null) if (_clipboardText != null)
{ {
var importVer = Base64Helper.ImportFromBase64(Clipboard.GetText(), out var json); var importVer = Base64Helper.ImportFromBase64(_clipboardText, out var json);
var template = Convert.ToInt32(importVer) switch var template = Convert.ToInt32(importVer) switch
{ {
//0 => ProfileConverter.ConvertFromConfigV0(json), 2 => GetTemplateFromV2Profile(json),
//2 => ProfileConverter.ConvertFromConfigV2(json), 3 => GetTemplateFromV3Profile(json),
//3 =>
4 => JsonConvert.DeserializeObject<Template>(json), 4 => JsonConvert.DeserializeObject<Template>(json),
_ => null _ => null
}; };
if (template is Template tpl) if (template is Template tpl && tpl != null)
_templateManager.Clone(tpl, _newName, true); _templateManager.Clone(tpl, _newName, true);
else else
//Messager.NotificationMessage("Could not create a template, clipboard did not contain valid template data.", NotificationType.Error, false); _popupSystem.ShowPopup("clipboard_data_unsupported_version");
throw new Exception("Invalid template"); //todo: temporary
_clipboardText = null;
} }
else if (_cloneTemplate != null) else if (_cloneTemplate != null)
{ {
_templateManager.Clone(_cloneTemplate, _newName, true); _templateManager.Clone(_cloneTemplate, _newName, true);
_cloneTemplate = null;
} }
else else
{ {
_templateManager.Create(_newName, true); _templateManager.Create(_newName, true);
} }
}
catch(Exception ex)
{
_logger.Error($"Error while performing clipboard/clone/create template action: {ex}");
_popupSystem.ShowPopup("action_error");
}
finally
{
_clipboardText = null;
_cloneTemplate = null;
_newName = string.Empty; _newName = string.Empty;
} }
}
private Template? GetTemplateFromV2Profile(string json)
{
var profile = JsonConvert.DeserializeObject<Version2Profile>(json);
if (profile != null)
{
var v3Profile = V2ProfileToV3Converter.Convert(profile);
(var _, var template) = V3ProfileToV4Converter.Convert(v3Profile);
if (template != null)
return template;
}
return null;
}
private Template? GetTemplateFromV3Profile(string json)
{
var profile = JsonConvert.DeserializeObject<Version3Profile>(json);
if (profile != null)
{
if (profile.ConfigVersion != 3)
throw new Exception("Incompatible profile version");
(var _, var template) = V3ProfileToV4Converter.Convert(profile);
if (template != null)
return template;
}
return null;
}
private void OnTemplateChange(TemplateChanged.Type type, Template? nullable, object? arg3 = null) private void OnTemplateChange(TemplateChanged.Type type, Template? nullable, object? arg3 = null)
{ {

View File

@@ -22,6 +22,8 @@ public class PopupSystem
{ {
_logger = logger; _logger = logger;
_configuration = configuration; _configuration = configuration;
RegisterPopup("action_error", "Error while performing selected action.\nDetails have been printed to Dalamud log (/xllog in chat).");
} }
public void RegisterPopup(string name, string text, bool displayOnce = false, Vector2? sizeDividers = null) public void RegisterPopup(string name, string text, bool displayOnce = false, Vector2? sizeDividers = null)