Code commit

This commit is contained in:
RisaDev
2024-01-06 01:21:41 +03:00
parent a7d7297c59
commit a486dd2c96
90 changed files with 11576 additions and 0 deletions

View File

@@ -0,0 +1,150 @@
using System;
using System.Collections.Generic;
using System.IO;
using Dalamud.Configuration;
using Dalamud.Interface.Internal.Notifications;
using Newtonsoft.Json;
using OtterGui.Classes;
using OtterGui.Log;
using OtterGui.Widgets;
using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;
using CustomizePlus.Core.Services;
using CustomizePlus.Core.Data;
using CustomizePlus.Configuration.Services;
using CustomizePlus.Game.Services;
using CustomizePlus.UI.Windows;
namespace CustomizePlus.Configuration.Data;
[Serializable]
public class PluginConfiguration : IPluginConfiguration, ISavable
{
public const int CurrentVersion = Constants.ConfigurationVersion;
public int Version { get; set; } = CurrentVersion;
public bool PluginEnabled { get; set; } = true;
public bool DebuggingModeEnabled { get; set; }
/// <summary>
/// Id of the default profile applied to all characters without any profile. Can be set to Empty to disable this feature.
/// </summary>
public Guid DefaultProfile { get; set; } = Guid.Empty;
[Serializable]
public class ChangelogSettingsEntries
{
public int LastSeenVersion { get; set; } = CPlusChangeLog.LastChangelogVersion;
public ChangeLogDisplayType ChangeLogDisplayType { get; set; } = ChangeLogDisplayType.New;
}
public ChangelogSettingsEntries ChangelogSettings { get; set; } = new();
[Serializable]
public class UISettingsEntries
{
public DoubleModifier DeleteTemplateModifier { get; set; } = new(ModifierHotkey.Control, ModifierHotkey.Shift);
public bool FoldersDefaultOpen { get; set; } = true;
public bool HideWindowInCutscene { get; set; } = true;
public bool IncognitoMode { get; set; } = false;
public List<string> ViewedMessageWindows { get; set; } = new();
}
public UISettingsEntries UISettings { get; set; } = new();
[Serializable]
public class EditorConfigurationEntries
{
/// <summary>
/// Hides root position from the UI. DOES NOT DISABLE LOADING IT FROM THE CONFIG!
/// </summary>
public bool RootPositionEditingEnabled { get; set; } = false;
public bool ShowLiveBones { get; set; } = true;
public bool BoneMirroringEnabled { get; set; } = false;
public bool LimitLookupToOwnedObjects { get; set; } = false;
public string? PreviewCharacterName { get; set; } = null;
public int EditorValuesPrecision { get; set; } = 3;
public BoneAttribute EditorMode { get; set; } = BoneAttribute.Position;
}
public EditorConfigurationEntries EditorConfiguration { get; set; } = new();
[JsonIgnore]
private readonly SaveService _saveService;
[JsonIgnore]
private readonly Logger _logger;
[JsonIgnore]
private readonly ChatService _chatService;
[JsonIgnore]
private readonly MessageService _messageService;
public PluginConfiguration(
SaveService saveService,
Logger logger,
ChatService chatService,
MessageService messageService,
ConfigurationMigrator migrator)
{
_saveService = saveService;
_logger = logger;
_chatService = chatService;
_messageService = messageService;
Load(migrator);
}
public void Load(ConfigurationMigrator migrator)
{
static void HandleDeserializationError(object? sender, ErrorEventArgs errorArgs)
{
Plugin.Logger.Error(
$"Error parsing configuration at {errorArgs.ErrorContext.Path}, using default or migrating:\n{errorArgs.ErrorContext.Error}");
errorArgs.ErrorContext.Handled = true;
}
if (!File.Exists(_saveService.FileNames.ConfigFile))
return;
try
{
var text = File.ReadAllText(_saveService.FileNames.ConfigFile);
JsonConvert.PopulateObject(text, this, new JsonSerializerSettings
{
Error = HandleDeserializationError,
});
}
catch (Exception ex)
{
_messageService.NotificationMessage(ex,
"Error reading configuration, reverting to default.\nYou may be able to restore your configuration using the rolling backups in the XIVLauncher/backups/CustomizePlus directory.",
"Error reading configuration", NotificationType.Error);
}
migrator.Migrate(this);
}
public string ToFilename(FilenameService fileNames)
=> fileNames.ConfigFile;
public void Save(StreamWriter writer)
{
using var jWriter = new JsonTextWriter(writer) { Formatting = Formatting.Indented };
var serializer = new JsonSerializer { Formatting = Formatting.Indented };
serializer.Serialize(jWriter, this);
}
public void Save()
=> _saveService.DelaySave(this);
}

View File

@@ -0,0 +1,60 @@
using System;
using System.Numerics;
namespace CustomizePlus.Configuration.Data.Version3;
public class V3BoneTransform
{
private Vector3 _translation;
public Vector3 Translation
{
get => _translation;
set => _translation = ClampVector(value);
}
private Vector3 _rotation;
public Vector3 Rotation
{
get => _rotation;
set => _rotation = ClampAngles(value);
}
private Vector3 _scaling;
public Vector3 Scaling
{
get => _scaling;
set => _scaling = ClampVector(value);
}
/// <summary>
/// Clamp all vector values to be within allowed limits.
/// </summary>
private Vector3 ClampVector(Vector3 vector)
{
return new Vector3
{
X = Math.Clamp(vector.X, -512, 512),
Y = Math.Clamp(vector.Y, -512, 512),
Z = Math.Clamp(vector.Z, -512, 512)
};
}
private static Vector3 ClampAngles(Vector3 rotVec)
{
static float Clamp(float angle)
{
if (angle > 180)
angle -= 360;
else if (angle < -180)
angle += 360;
return angle;
}
rotVec.X = Clamp(rotVec.X);
rotVec.Y = Clamp(rotVec.Y);
rotVec.Z = Clamp(rotVec.Z);
return rotVec;
}
}

View File

@@ -0,0 +1,24 @@
using CustomizePlus.Core.Data;
using System;
using System.Collections.Generic;
namespace CustomizePlus.Configuration.Data.Version3;
/// <summary>
/// Encapsulates the user-controlled aspects of a character profile, ie all of
/// the information that gets saved to disk by the plugin.
/// </summary>
[Serializable]
public sealed class Version3Profile
{
public string CharacterName { get; set; } = "Default";
public string ProfileName { get; set; } = "Profile";
public nint? Address { get; set; } = null;
public bool OwnedOnly { get; set; } = false;
public int ConfigVersion { get; set; } = Constants.ConfigurationVersion;
public bool Enabled { get; set; }
public DateTime CreationDate { get; set; } = DateTime.Now;
public DateTime ModifiedDate { get; set; } = DateTime.Now;
public Dictionary<string, V3BoneTransform> Bones { get; init; } = new();
}