mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2026-02-19 05:57:42 +01:00
Starting rework.
This commit is contained in:
parent
0fc8992271
commit
7af38aa2ce
58 changed files with 8857 additions and 4923 deletions
|
|
@ -1,22 +1,16 @@
|
|||
using Glamourer.FileSystem;
|
||||
using System;
|
||||
|
||||
namespace Glamourer.Designs
|
||||
namespace Glamourer.Designs;
|
||||
|
||||
public class Design
|
||||
{
|
||||
public class Design : IFileSystemBase
|
||||
{
|
||||
public Folder Parent { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Name { get; }
|
||||
public bool ReadOnly;
|
||||
|
||||
public CharacterSave Data { get; set; }
|
||||
public DateTimeOffset CreationDate { get; }
|
||||
public DateTimeOffset LastUpdateDate { get; }
|
||||
public CharacterSave Data { get; }
|
||||
|
||||
internal Design(Folder parent, string name)
|
||||
{
|
||||
Parent = parent;
|
||||
Name = name;
|
||||
Data = new CharacterSave();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
=> Name;
|
||||
}
|
||||
public override string ToString()
|
||||
=> Name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,157 +3,155 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using Dalamud.Logging;
|
||||
using Glamourer.FileSystem;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Glamourer.Designs
|
||||
namespace Glamourer.Designs;
|
||||
|
||||
public class DesignManager
|
||||
{
|
||||
public class DesignManager
|
||||
{
|
||||
public const string FileName = "Designs.json";
|
||||
private readonly FileInfo _saveFile;
|
||||
|
||||
public SortedList<string, CharacterSave> Designs = null!;
|
||||
public FileSystem.FileSystem FileSystem { get; } = new();
|
||||
|
||||
public DesignManager()
|
||||
{
|
||||
var saveFolder = new DirectoryInfo(Dalamud.PluginInterface.GetPluginConfigDirectory());
|
||||
if (!saveFolder.Exists)
|
||||
Directory.CreateDirectory(saveFolder.FullName);
|
||||
|
||||
_saveFile = new FileInfo(Path.Combine(saveFolder.FullName, FileName));
|
||||
|
||||
LoadFromFile();
|
||||
}
|
||||
|
||||
private void BuildStructure()
|
||||
{
|
||||
FileSystem.Clear();
|
||||
var anyChanges = false;
|
||||
foreach (var (path, save) in Designs.ToArray())
|
||||
{
|
||||
try
|
||||
{
|
||||
var (folder, name) = FileSystem.CreateAllFolders(path);
|
||||
var design = new Design(folder, name) { Data = save };
|
||||
folder.FindOrAddChild(design);
|
||||
var fixedPath = design.FullName();
|
||||
if (string.Equals(fixedPath, path, StringComparison.InvariantCultureIgnoreCase))
|
||||
continue;
|
||||
|
||||
Designs.Remove(path);
|
||||
Designs[fixedPath] = save;
|
||||
anyChanges = true;
|
||||
PluginLog.Debug($"Problem loading saved designs, {path} was renamed to {fixedPath}.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PluginLog.Error($"Problem loading saved designs, {path} was removed because:\n{e}");
|
||||
Designs.Remove(path);
|
||||
}
|
||||
}
|
||||
|
||||
if (anyChanges)
|
||||
SaveToFile();
|
||||
}
|
||||
|
||||
private bool UpdateRoot(string oldPath, Design child)
|
||||
{
|
||||
var newPath = child.FullName();
|
||||
if (string.Equals(newPath, oldPath, StringComparison.InvariantCultureIgnoreCase))
|
||||
return false;
|
||||
|
||||
Designs.Remove(oldPath);
|
||||
Designs[child.FullName()] = child.Data;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void UpdateChild(string oldRootPath, string newRootPath, Design child)
|
||||
{
|
||||
var newPath = child.FullName();
|
||||
var oldPath = $"{oldRootPath}{newPath.Remove(0, newRootPath.Length)}";
|
||||
Designs.Remove(oldPath);
|
||||
Designs[newPath] = child.Data;
|
||||
}
|
||||
|
||||
public void DeleteAllChildren(IFileSystemBase root, bool deleteEmpty)
|
||||
{
|
||||
if (root is Folder f)
|
||||
foreach (var child in f.AllLeaves(SortMode.Lexicographical))
|
||||
Designs.Remove(child.FullName());
|
||||
var fullPath = root.FullName();
|
||||
root.Parent.RemoveChild(root, deleteEmpty);
|
||||
Designs.Remove(fullPath);
|
||||
|
||||
SaveToFile();
|
||||
}
|
||||
|
||||
public void UpdateAllChildren(string oldPath, IFileSystemBase root)
|
||||
{
|
||||
var changes = false;
|
||||
switch (root)
|
||||
{
|
||||
case Design d:
|
||||
changes |= UpdateRoot(oldPath, d);
|
||||
break;
|
||||
case Folder f:
|
||||
{
|
||||
var newRootPath = root.FullName();
|
||||
if (!string.Equals(oldPath, newRootPath, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
changes = true;
|
||||
foreach (var descendant in f.AllLeaves(SortMode.Lexicographical).Where(l => l is Design).Cast<Design>())
|
||||
UpdateChild(oldPath, newRootPath, descendant);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (changes)
|
||||
SaveToFile();
|
||||
}
|
||||
|
||||
public void SaveToFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = JsonConvert.SerializeObject(Designs, Formatting.Indented);
|
||||
File.WriteAllText(_saveFile.FullName, data);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PluginLog.Error($"Could not write to save file {_saveFile.FullName}:\n{e}");
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadFromFile()
|
||||
{
|
||||
_saveFile.Refresh();
|
||||
SortedList<string, CharacterSave>? designs = null;
|
||||
if (_saveFile.Exists)
|
||||
try
|
||||
{
|
||||
var data = File.ReadAllText(_saveFile.FullName);
|
||||
designs = JsonConvert.DeserializeObject<SortedList<string, CharacterSave>>(data);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PluginLog.Error($"Could not load save file {_saveFile.FullName}:\n{e}");
|
||||
}
|
||||
|
||||
if (designs == null)
|
||||
{
|
||||
Designs = new SortedList<string, CharacterSave>();
|
||||
SaveToFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
Designs = designs;
|
||||
}
|
||||
|
||||
BuildStructure();
|
||||
}
|
||||
}
|
||||
//public const string FileName = "Designs.json";
|
||||
//private readonly FileInfo _saveFile;
|
||||
//
|
||||
//public SortedList<string, CharacterSave> Designs = null!;
|
||||
//public FileSystem.FileSystem FileSystem { get; } = new();
|
||||
//
|
||||
//public DesignManager()
|
||||
//{
|
||||
// var saveFolder = new DirectoryInfo(Dalamud.PluginInterface.GetPluginConfigDirectory());
|
||||
// if (!saveFolder.Exists)
|
||||
// Directory.CreateDirectory(saveFolder.FullName);
|
||||
//
|
||||
// _saveFile = new FileInfo(Path.Combine(saveFolder.FullName, FileName));
|
||||
//
|
||||
// LoadFromFile();
|
||||
//}
|
||||
//
|
||||
//private void BuildStructure()
|
||||
//{
|
||||
// FileSystem.Clear();
|
||||
// var anyChanges = false;
|
||||
// foreach (var (path, save) in Designs.ToArray())
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var (folder, name) = FileSystem.CreateAllFolders(path);
|
||||
// var design = new Design(folder, name) { Data = save };
|
||||
// folder.FindOrAddChild(design);
|
||||
// var fixedPath = design.FullName();
|
||||
// if (string.Equals(fixedPath, path, StringComparison.InvariantCultureIgnoreCase))
|
||||
// continue;
|
||||
//
|
||||
// Designs.Remove(path);
|
||||
// Designs[fixedPath] = save;
|
||||
// anyChanges = true;
|
||||
// PluginLog.Debug($"Problem loading saved designs, {path} was renamed to {fixedPath}.");
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// PluginLog.Error($"Problem loading saved designs, {path} was removed because:\n{e}");
|
||||
// Designs.Remove(path);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (anyChanges)
|
||||
// SaveToFile();
|
||||
//}
|
||||
//
|
||||
//private bool UpdateRoot(string oldPath, Design child)
|
||||
//{
|
||||
// var newPath = child.FullName();
|
||||
// if (string.Equals(newPath, oldPath, StringComparison.InvariantCultureIgnoreCase))
|
||||
// return false;
|
||||
//
|
||||
// Designs.Remove(oldPath);
|
||||
// Designs[child.FullName()] = child.Data;
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//private void UpdateChild(string oldRootPath, string newRootPath, Design child)
|
||||
//{
|
||||
// var newPath = child.FullName();
|
||||
// var oldPath = $"{oldRootPath}{newPath.Remove(0, newRootPath.Length)}";
|
||||
// Designs.Remove(oldPath);
|
||||
// Designs[newPath] = child.Data;
|
||||
//}
|
||||
//
|
||||
//public void DeleteAllChildren(IFileSystemBase root, bool deleteEmpty)
|
||||
//{
|
||||
// if (root is Folder f)
|
||||
// foreach (var child in f.AllLeaves(SortMode.Lexicographical))
|
||||
// Designs.Remove(child.FullName());
|
||||
// var fullPath = root.FullName();
|
||||
// root.Parent.RemoveChild(root, deleteEmpty);
|
||||
// Designs.Remove(fullPath);
|
||||
//
|
||||
// SaveToFile();
|
||||
//}
|
||||
//
|
||||
//public void UpdateAllChildren(string oldPath, IFileSystemBase root)
|
||||
//{
|
||||
// var changes = false;
|
||||
// switch (root)
|
||||
// {
|
||||
// case Design d:
|
||||
// changes |= UpdateRoot(oldPath, d);
|
||||
// break;
|
||||
// case Folder f:
|
||||
// {
|
||||
// var newRootPath = root.FullName();
|
||||
// if (!string.Equals(oldPath, newRootPath, StringComparison.InvariantCultureIgnoreCase))
|
||||
// {
|
||||
// changes = true;
|
||||
// foreach (var descendant in f.AllLeaves(SortMode.Lexicographical).Where(l => l is Design).Cast<Design>())
|
||||
// UpdateChild(oldPath, newRootPath, descendant);
|
||||
// }
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (changes)
|
||||
// SaveToFile();
|
||||
//}
|
||||
//
|
||||
//public void SaveToFile()
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// var data = JsonConvert.SerializeObject(Designs, Formatting.Indented);
|
||||
// File.WriteAllText(_saveFile.FullName, data);
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// PluginLog.Error($"Could not write to save file {_saveFile.FullName}:\n{e}");
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//public void LoadFromFile()
|
||||
//{
|
||||
// _saveFile.Refresh();
|
||||
// SortedList<string, CharacterSave>? designs = null;
|
||||
// if (_saveFile.Exists)
|
||||
// try
|
||||
// {
|
||||
// var data = File.ReadAllText(_saveFile.FullName);
|
||||
// designs = JsonConvert.DeserializeObject<SortedList<string, CharacterSave>>(data);
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// PluginLog.Error($"Could not load save file {_saveFile.FullName}:\n{e}");
|
||||
// }
|
||||
//
|
||||
// if (designs == null)
|
||||
// {
|
||||
// Designs = new SortedList<string, CharacterSave>();
|
||||
// SaveToFile();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Designs = designs;
|
||||
// }
|
||||
//
|
||||
// BuildStructure();
|
||||
//}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,193 +1,188 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Dalamud.Game.ClientState.Objects.Enums;
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Dalamud.Logging;
|
||||
using Glamourer.FileSystem;
|
||||
using Glamourer.Structs;
|
||||
using Penumbra.GameData.Enums;
|
||||
using Penumbra.PlayerWatch;
|
||||
|
||||
namespace Glamourer.Designs
|
||||
namespace Glamourer.Designs;
|
||||
|
||||
public class FixedDesigns : IDisposable
|
||||
{
|
||||
public class FixedDesigns : IDisposable
|
||||
//public class FixedDesign
|
||||
//{
|
||||
// public string Name;
|
||||
// public JobGroup Jobs;
|
||||
// public Design Design;
|
||||
// public bool Enabled;
|
||||
//
|
||||
// public GlamourerConfig.FixedDesign ToSave()
|
||||
// => new()
|
||||
// {
|
||||
// Name = Name,
|
||||
// Path = Design.FullName(),
|
||||
// Enabled = Enabled,
|
||||
// JobGroups = Jobs.Id,
|
||||
// };
|
||||
//
|
||||
// public FixedDesign(string name, Design design, bool enabled, JobGroup jobs)
|
||||
// {
|
||||
// Name = name;
|
||||
// Design = design;
|
||||
// Enabled = enabled;
|
||||
// Jobs = jobs;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//public List<FixedDesign> Data;
|
||||
//public Dictionary<string, List<FixedDesign>> EnabledDesigns;
|
||||
//public readonly IReadOnlyDictionary<ushort, JobGroup> JobGroups;
|
||||
//
|
||||
//public bool EnableDesign(FixedDesign design)
|
||||
//{
|
||||
// var changes = !design.Enabled;
|
||||
//
|
||||
// if (!EnabledDesigns.TryGetValue(design.Name, out var designs))
|
||||
// {
|
||||
// EnabledDesigns[design.Name] = new List<FixedDesign> { design };
|
||||
// // TODO
|
||||
// changes = true;
|
||||
// }
|
||||
// else if (!designs.Contains(design))
|
||||
// {
|
||||
// designs.Add(design);
|
||||
// changes = true;
|
||||
// }
|
||||
//
|
||||
// design.Enabled = true;
|
||||
// // TODO
|
||||
// //if (Glamourer.Config.ApplyFixedDesigns)
|
||||
// //{
|
||||
// // var character =
|
||||
// // CharacterFactory.Convert(Dalamud.Objects.FirstOrDefault(o
|
||||
// // => o.ObjectKind == ObjectKind.Player && o.Name.ToString() == design.Name));
|
||||
// // if (character != null)
|
||||
// // OnPlayerChange(character);
|
||||
// //}
|
||||
//
|
||||
// return changes;
|
||||
//}
|
||||
//
|
||||
//public bool DisableDesign(FixedDesign design)
|
||||
//{
|
||||
// if (!design.Enabled)
|
||||
// return false;
|
||||
//
|
||||
// design.Enabled = false;
|
||||
// if (!EnabledDesigns.TryGetValue(design.Name, out var designs))
|
||||
// return false;
|
||||
// if (!designs.Remove(design))
|
||||
// return false;
|
||||
//
|
||||
// if (designs.Count == 0)
|
||||
// {
|
||||
// EnabledDesigns.Remove(design.Name);
|
||||
// // TODO
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
//}
|
||||
//
|
||||
//public FixedDesigns(DesignManager designs)
|
||||
//{
|
||||
// JobGroups = GameData.JobGroups(Dalamud.GameData);
|
||||
// Data = new List<FixedDesign>(Glamourer.Config.FixedDesigns.Count);
|
||||
// EnabledDesigns = new Dictionary<string, List<FixedDesign>>(Glamourer.Config.FixedDesigns.Count);
|
||||
// var changes = false;
|
||||
// for (var i = 0; i < Glamourer.Config.FixedDesigns.Count; ++i)
|
||||
// {
|
||||
// var save = Glamourer.Config.FixedDesigns[i];
|
||||
// if (designs.FileSystem.Find(save.Path, out var d) && d is Design design)
|
||||
// {
|
||||
// if (!JobGroups.TryGetValue((ushort)save.JobGroups, out var jobGroup))
|
||||
// jobGroup = JobGroups[1];
|
||||
// Data.Add(new FixedDesign(save.Name, design, save.Enabled, jobGroup));
|
||||
// if (save.Enabled)
|
||||
// changes |= EnableDesign(Data.Last());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// PluginLog.Warning($"{save.Path} does not exist anymore, removing {save.Name} from fixed designs.");
|
||||
// Glamourer.Config.FixedDesigns.RemoveAt(i--);
|
||||
// changes = true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (changes)
|
||||
// Glamourer.Config.Save();
|
||||
//}
|
||||
//
|
||||
//private void OnPlayerChange(Character character)
|
||||
//{
|
||||
// //var name = character.Name.ToString();
|
||||
// //if (!EnabledDesigns.TryGetValue(name, out var designs))
|
||||
// // return;
|
||||
// //
|
||||
// //var design = designs.OrderBy(d => d.Jobs.Count).FirstOrDefault(d => d.Jobs.Fits(character.ClassJob.Id));
|
||||
// //if (design == null)
|
||||
// // return;
|
||||
// //
|
||||
// //PluginLog.Debug("Redrawing {CharacterName} with {DesignName} for job {JobGroup}.", name, design.Design.FullName(),
|
||||
// // design.Jobs.Name);
|
||||
// //design.Design.Data.Apply(character);
|
||||
// //Glamourer.PlayerWatcher.UpdatePlayerWithoutEvent(character);
|
||||
// //Glamourer.Penumbra.RedrawObject(character, RedrawType.Redraw, false);
|
||||
//}
|
||||
//
|
||||
//public void Add(string name, Design design, JobGroup group, bool enabled = false)
|
||||
//{
|
||||
// Data.Add(new FixedDesign(name, design, enabled, group));
|
||||
// Glamourer.Config.FixedDesigns.Add(Data.Last().ToSave());
|
||||
//
|
||||
// if (enabled)
|
||||
// EnableDesign(Data.Last());
|
||||
//
|
||||
// Glamourer.Config.Save();
|
||||
//}
|
||||
//
|
||||
//public void Remove(FixedDesign design)
|
||||
//{
|
||||
// var idx = Data.IndexOf(design);
|
||||
// if (idx < 0)
|
||||
// return;
|
||||
//
|
||||
// Data.RemoveAt(idx);
|
||||
// Glamourer.Config.FixedDesigns.RemoveAt(idx);
|
||||
// if (design.Enabled)
|
||||
// {
|
||||
// EnabledDesigns.Remove(design.Name);
|
||||
// // TODO
|
||||
// }
|
||||
//
|
||||
// Glamourer.Config.Save();
|
||||
//}
|
||||
//
|
||||
//public void Move(FixedDesign design, int newIdx)
|
||||
//{
|
||||
// if (newIdx < 0)
|
||||
// newIdx = 0;
|
||||
// if (newIdx >= Data.Count)
|
||||
// newIdx = Data.Count - 1;
|
||||
//
|
||||
// var idx = Data.IndexOf(design);
|
||||
// if (idx < 0 || idx == newIdx)
|
||||
// return;
|
||||
//
|
||||
// Data.RemoveAt(idx);
|
||||
// Data.Insert(newIdx, design);
|
||||
// Glamourer.Config.FixedDesigns.RemoveAt(idx);
|
||||
// Glamourer.Config.FixedDesigns.Insert(newIdx, design.ToSave());
|
||||
// Glamourer.Config.Save();
|
||||
//}
|
||||
//
|
||||
public void Dispose()
|
||||
{
|
||||
public class FixedDesign
|
||||
{
|
||||
public string Name;
|
||||
public JobGroup Jobs;
|
||||
public Design Design;
|
||||
public bool Enabled;
|
||||
|
||||
public GlamourerConfig.FixedDesign ToSave()
|
||||
=> new()
|
||||
{
|
||||
Name = Name,
|
||||
Path = Design.FullName(),
|
||||
Enabled = Enabled,
|
||||
JobGroups = Jobs.Id,
|
||||
};
|
||||
|
||||
public FixedDesign(string name, Design design, bool enabled, JobGroup jobs)
|
||||
{
|
||||
Name = name;
|
||||
Design = design;
|
||||
Enabled = enabled;
|
||||
Jobs = jobs;
|
||||
}
|
||||
}
|
||||
|
||||
public List<FixedDesign> Data;
|
||||
public Dictionary<string, List<FixedDesign>> EnabledDesigns;
|
||||
public readonly IReadOnlyDictionary<ushort, JobGroup> JobGroups;
|
||||
|
||||
public bool EnableDesign(FixedDesign design)
|
||||
{
|
||||
var changes = !design.Enabled;
|
||||
|
||||
if (!EnabledDesigns.TryGetValue(design.Name, out var designs))
|
||||
{
|
||||
EnabledDesigns[design.Name] = new List<FixedDesign> { design };
|
||||
Glamourer.PlayerWatcher.AddPlayerToWatch(design.Name);
|
||||
changes = true;
|
||||
}
|
||||
else if (!designs.Contains(design))
|
||||
{
|
||||
designs.Add(design);
|
||||
changes = true;
|
||||
}
|
||||
|
||||
design.Enabled = true;
|
||||
if (Glamourer.Config.ApplyFixedDesigns)
|
||||
{
|
||||
var character =
|
||||
CharacterFactory.Convert(Dalamud.Objects.FirstOrDefault(o
|
||||
=> o.ObjectKind == ObjectKind.Player && o.Name.ToString() == design.Name));
|
||||
if (character != null)
|
||||
OnPlayerChange(character);
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
public bool DisableDesign(FixedDesign design)
|
||||
{
|
||||
if (!design.Enabled)
|
||||
return false;
|
||||
|
||||
design.Enabled = false;
|
||||
if (!EnabledDesigns.TryGetValue(design.Name, out var designs))
|
||||
return false;
|
||||
if (!designs.Remove(design))
|
||||
return false;
|
||||
|
||||
if (designs.Count == 0)
|
||||
{
|
||||
EnabledDesigns.Remove(design.Name);
|
||||
Glamourer.PlayerWatcher.RemovePlayerFromWatch(design.Name);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public FixedDesigns(DesignManager designs)
|
||||
{
|
||||
JobGroups = GameData.JobGroups(Dalamud.GameData);
|
||||
Data = new List<FixedDesign>(Glamourer.Config.FixedDesigns.Count);
|
||||
EnabledDesigns = new Dictionary<string, List<FixedDesign>>(Glamourer.Config.FixedDesigns.Count);
|
||||
Glamourer.PlayerWatcher.PlayerChanged += OnPlayerChange;
|
||||
var changes = false;
|
||||
for (var i = 0; i < Glamourer.Config.FixedDesigns.Count; ++i)
|
||||
{
|
||||
var save = Glamourer.Config.FixedDesigns[i];
|
||||
if (designs.FileSystem.Find(save.Path, out var d) && d is Design design)
|
||||
{
|
||||
if (!JobGroups.TryGetValue((ushort) save.JobGroups, out var jobGroup))
|
||||
jobGroup = JobGroups[1];
|
||||
Data.Add(new FixedDesign(save.Name, design, save.Enabled, jobGroup));
|
||||
if (save.Enabled)
|
||||
changes |= EnableDesign(Data.Last());
|
||||
}
|
||||
else
|
||||
{
|
||||
PluginLog.Warning($"{save.Path} does not exist anymore, removing {save.Name} from fixed designs.");
|
||||
Glamourer.Config.FixedDesigns.RemoveAt(i--);
|
||||
changes = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changes)
|
||||
Glamourer.Config.Save();
|
||||
}
|
||||
|
||||
private void OnPlayerChange(Character character)
|
||||
{
|
||||
//var name = character.Name.ToString();
|
||||
//if (!EnabledDesigns.TryGetValue(name, out var designs))
|
||||
// return;
|
||||
//
|
||||
//var design = designs.OrderBy(d => d.Jobs.Count).FirstOrDefault(d => d.Jobs.Fits(character.ClassJob.Id));
|
||||
//if (design == null)
|
||||
// return;
|
||||
//
|
||||
//PluginLog.Debug("Redrawing {CharacterName} with {DesignName} for job {JobGroup}.", name, design.Design.FullName(),
|
||||
// design.Jobs.Name);
|
||||
//design.Design.Data.Apply(character);
|
||||
//Glamourer.PlayerWatcher.UpdatePlayerWithoutEvent(character);
|
||||
//Glamourer.Penumbra.RedrawObject(character, RedrawType.Redraw, false);
|
||||
}
|
||||
|
||||
public void Add(string name, Design design, JobGroup group, bool enabled = false)
|
||||
{
|
||||
Data.Add(new FixedDesign(name, design, enabled, group));
|
||||
Glamourer.Config.FixedDesigns.Add(Data.Last().ToSave());
|
||||
|
||||
if (enabled)
|
||||
EnableDesign(Data.Last());
|
||||
|
||||
Glamourer.Config.Save();
|
||||
}
|
||||
|
||||
public void Remove(FixedDesign design)
|
||||
{
|
||||
var idx = Data.IndexOf(design);
|
||||
if (idx < 0)
|
||||
return;
|
||||
|
||||
Data.RemoveAt(idx);
|
||||
Glamourer.Config.FixedDesigns.RemoveAt(idx);
|
||||
if (design.Enabled)
|
||||
{
|
||||
EnabledDesigns.Remove(design.Name);
|
||||
Glamourer.PlayerWatcher.RemovePlayerFromWatch(design.Name);
|
||||
}
|
||||
|
||||
Glamourer.Config.Save();
|
||||
}
|
||||
|
||||
public void Move(FixedDesign design, int newIdx)
|
||||
{
|
||||
if (newIdx < 0)
|
||||
newIdx = 0;
|
||||
if (newIdx >= Data.Count)
|
||||
newIdx = Data.Count - 1;
|
||||
|
||||
var idx = Data.IndexOf(design);
|
||||
if (idx < 0 || idx == newIdx)
|
||||
return;
|
||||
|
||||
Data.RemoveAt(idx);
|
||||
Data.Insert(newIdx, design);
|
||||
Glamourer.Config.FixedDesigns.RemoveAt(idx);
|
||||
Glamourer.Config.FixedDesigns.Insert(newIdx, design.ToSave());
|
||||
Glamourer.Config.Save();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Glamourer.Config.FixedDesigns = Data.Select(d => d.ToSave()).ToList();
|
||||
Glamourer.Config.Save();
|
||||
}
|
||||
//Glamourer.Config.FixedDesigns = Data.Select(d => d.ToSave()).ToList();
|
||||
//Glamourer.Config.Save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,42 +1,40 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
|
||||
namespace Glamourer.Designs
|
||||
namespace Glamourer.Designs;
|
||||
|
||||
public class RevertableDesigns
|
||||
{
|
||||
public class RevertableDesigns
|
||||
public readonly Dictionary<string, CharacterSave> Saves = new();
|
||||
|
||||
public bool Add(Character actor)
|
||||
{
|
||||
public readonly ConcurrentDictionary<string, CharacterSave> Saves = new();
|
||||
//var name = actor.Name.ToString();
|
||||
//if (Saves.TryGetValue(name, out var save))
|
||||
// return false;
|
||||
//
|
||||
//save = new CharacterSave();
|
||||
//save.LoadCharacter(actor);
|
||||
//Saves[name] = save;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Add(Character actor)
|
||||
{
|
||||
var name = actor.Name.ToString();
|
||||
if (Saves.TryGetValue(name, out var save))
|
||||
return false;
|
||||
public bool RevertByNameWithoutApplication(string actorName)
|
||||
{
|
||||
if (!Saves.ContainsKey(actorName))
|
||||
return false;
|
||||
|
||||
save = new CharacterSave();
|
||||
save.LoadCharacter(actor);
|
||||
Saves[name] = save;
|
||||
return true;
|
||||
}
|
||||
Saves.Remove(actorName);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool RevertByNameWithoutApplication(string actorName)
|
||||
{
|
||||
if (!Saves.ContainsKey(actorName))
|
||||
return false;
|
||||
|
||||
Saves.Remove(actorName, out _);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Revert(Character actor)
|
||||
{
|
||||
if (!Saves.TryGetValue(actor.Name.ToString(), out var save))
|
||||
return false;
|
||||
|
||||
save.Apply(actor);
|
||||
Saves.Remove(actor.Name.ToString(), out _);
|
||||
return true;
|
||||
}
|
||||
public bool Revert(Character actor)
|
||||
{
|
||||
//if (!Saves.TryGetValue(actor.Name.ToString(), out var save))
|
||||
// return false;
|
||||
//
|
||||
//save.Apply(actor);
|
||||
//Saves.Remove(actor.Name.ToString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue