mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 10:17:23 +01:00
Improve DesignStorage slightly.
This commit is contained in:
parent
a284d5adc5
commit
fce8b058b0
7 changed files with 48 additions and 56 deletions
|
|
@ -1,7 +1,6 @@
|
|||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Dalamud.Plugin;
|
||||
using Glamourer.Designs;
|
||||
using Glamourer.Events;
|
||||
using Glamourer.Interop.Structs;
|
||||
using Glamourer.State;
|
||||
using Penumbra.Api.Helpers;
|
||||
|
|
@ -138,5 +137,5 @@ public partial class GlamourerIpc
|
|||
}
|
||||
|
||||
private void ApplyDesignByGuid(Guid identifier, IEnumerable<ActorIdentifier> actors, uint lockCode)
|
||||
=> ApplyDesign(_designManager.Designs.FirstOrDefault(x => x.Identifier == identifier), actors, DesignConverter.Version, lockCode);
|
||||
=> ApplyDesign(_designManager.Designs.ByIdentifier(identifier), actors, DesignConverter.Version, lockCode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -480,8 +480,7 @@ public class AutoDesignManager : ISavable, IReadOnlyList<AutoDesignSet>, IDispos
|
|||
return null;
|
||||
}
|
||||
|
||||
design = _designs.Designs.FirstOrDefault(d => d.Identifier == guid);
|
||||
if (design == null)
|
||||
if (!_designs.Designs.TryGetValue(guid, out design))
|
||||
{
|
||||
Glamourer.Messager.NotificationMessage(
|
||||
$"Error parsing automatically applied design for set {setName}: The specified design {guid} does not exist.",
|
||||
|
|
|
|||
|
|
@ -11,21 +11,10 @@ using OtterGui.Classes;
|
|||
|
||||
namespace Glamourer.Designs;
|
||||
|
||||
public class DesignColorUi
|
||||
public class DesignColorUi(DesignColors colors, Configuration config)
|
||||
{
|
||||
private readonly DesignColors _colors;
|
||||
private readonly DesignManager _designs;
|
||||
private readonly Configuration _config;
|
||||
|
||||
private string _newName = string.Empty;
|
||||
|
||||
public DesignColorUi(DesignColors colors, DesignManager designs, Configuration config)
|
||||
{
|
||||
_colors = colors;
|
||||
_designs = designs;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
using var table = ImRaii.Table("designColors", 3, ImGuiTableFlags.RowBg);
|
||||
|
|
@ -44,7 +33,7 @@ public class DesignColorUi
|
|||
|
||||
ImGui.TableNextColumn();
|
||||
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Recycle.ToIconString(), buttonSize,
|
||||
"Revert the color used for missing design colors to its default.", _colors.MissingColor == DesignColors.MissingColorDefault,
|
||||
"Revert the color used for missing design colors to its default.", colors.MissingColor == DesignColors.MissingColorDefault,
|
||||
true))
|
||||
{
|
||||
changeString = DesignColors.MissingColorName;
|
||||
|
|
@ -52,7 +41,7 @@ public class DesignColorUi
|
|||
}
|
||||
|
||||
ImGui.TableNextColumn();
|
||||
if (DrawColorButton(DesignColors.MissingColorName, _colors.MissingColor, out var newColor))
|
||||
if (DrawColorButton(DesignColors.MissingColorName, colors.MissingColor, out var newColor))
|
||||
{
|
||||
changeString = DesignColors.MissingColorName;
|
||||
changeValue = newColor;
|
||||
|
|
@ -64,12 +53,12 @@ public class DesignColorUi
|
|||
ImGuiUtil.HoverTooltip("This color is used when the color specified in a design is not available.");
|
||||
|
||||
|
||||
var disabled = !_config.DeleteDesignModifier.IsActive();
|
||||
var disabled = !config.DeleteDesignModifier.IsActive();
|
||||
var tt = "Delete this color. This does not remove it from designs using it.";
|
||||
if (disabled)
|
||||
tt += $"\nHold {_config.DeleteDesignModifier} to delete.";
|
||||
tt += $"\nHold {config.DeleteDesignModifier} to delete.";
|
||||
|
||||
foreach (var ((name, color), idx) in _colors.WithIndex())
|
||||
foreach (var ((name, color), idx) in colors.WithIndex())
|
||||
{
|
||||
using var id = ImRaii.PushId(idx);
|
||||
ImGui.TableNextColumn();
|
||||
|
|
@ -97,7 +86,7 @@ public class DesignColorUi
|
|||
? ("Specify a name for a new color first.", true)
|
||||
: _newName is DesignColors.MissingColorName or DesignColors.AutomaticName
|
||||
? ($"You can not use the name {DesignColors.MissingColorName} or {DesignColors.AutomaticName}, choose a different one.", true)
|
||||
: _colors.ContainsKey(_newName)
|
||||
: colors.ContainsKey(_newName)
|
||||
? ($"The color {_newName} already exists, please choose a different name.", true)
|
||||
: ($"Add a new color {_newName} to your list.", false);
|
||||
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Plus.ToIconString(), buttonSize, tt, disabled, true))
|
||||
|
|
@ -119,9 +108,9 @@ public class DesignColorUi
|
|||
if (changeString.Length > 0)
|
||||
{
|
||||
if (!changeValue.HasValue)
|
||||
_colors.DeleteColor(changeString);
|
||||
colors.DeleteColor(changeString);
|
||||
else
|
||||
_colors.SetColor(changeString, changeValue.Value);
|
||||
colors.SetColor(changeString, changeValue.Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,16 +21,14 @@ public class DesignManager
|
|||
private readonly HumanModelList _humans;
|
||||
private readonly SaveService _saveService;
|
||||
private readonly DesignChanged _event;
|
||||
private readonly DesignStorage _designs;
|
||||
private readonly Dictionary<Guid, DesignData> _undoStore = [];
|
||||
|
||||
public IReadOnlyList<Design> Designs
|
||||
=> _designs;
|
||||
public DesignStorage Designs { get; }
|
||||
|
||||
public DesignManager(SaveService saveService, ItemManager items, CustomizeService customizations,
|
||||
DesignChanged @event, HumanModelList humans, DesignStorage storage, DesignLinkLoader designLinkLoader, Configuration config)
|
||||
{
|
||||
_designs = storage;
|
||||
Designs = storage;
|
||||
_config = config;
|
||||
_saveService = saveService;
|
||||
_items = items;
|
||||
|
|
@ -55,7 +53,7 @@ public class DesignManager
|
|||
_items.ItemData.Awaiter.Wait();
|
||||
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
_designs.Clear();
|
||||
Designs.Clear();
|
||||
var skipped = 0;
|
||||
ThreadLocal<List<(Design, string)>> designs = new(() => [], true);
|
||||
Parallel.ForEach(_saveService.FileNames.Designs(), (f, _) =>
|
||||
|
|
@ -79,15 +77,15 @@ public class DesignManager
|
|||
{
|
||||
if (design.Identifier.ToString() != Path.GetFileNameWithoutExtension(path))
|
||||
invalidNames.Add((design, path));
|
||||
if (_designs.Any(d => d.Identifier == design.Identifier))
|
||||
if (Designs.Contains(design.Identifier))
|
||||
{
|
||||
Glamourer.Log.Error($"Could not load design, skipped: Identifier {design.Identifier} was not unique.");
|
||||
++skipped;
|
||||
continue;
|
||||
}
|
||||
|
||||
design.Index = _designs.Count;
|
||||
_designs.Add(design);
|
||||
design.Index = Designs.Count;
|
||||
Designs.Add(design);
|
||||
}
|
||||
|
||||
var failed = MoveInvalidNames(invalidNames);
|
||||
|
|
@ -96,7 +94,7 @@ public class DesignManager
|
|||
$"Moved {invalidNames.Count - failed} designs to correct names.{(failed > 0 ? $" Failed to move {failed} designs to correct names." : string.Empty)}");
|
||||
|
||||
Glamourer.Log.Information(
|
||||
$"Loaded {_designs.Count} designs in {stopwatch.ElapsedMilliseconds} ms.{(skipped > 0 ? $" Skipped loading {skipped} designs due to errors." : string.Empty)}");
|
||||
$"Loaded {Designs.Count} designs in {stopwatch.ElapsedMilliseconds} ms.{(skipped > 0 ? $" Skipped loading {skipped} designs due to errors." : string.Empty)}");
|
||||
_event.Invoke(DesignChanged.Type.ReloadedAll, null!, null);
|
||||
}
|
||||
|
||||
|
|
@ -118,9 +116,9 @@ public class DesignManager
|
|||
LastEdit = DateTimeOffset.UtcNow,
|
||||
Identifier = CreateNewGuid(),
|
||||
Name = actualName,
|
||||
Index = _designs.Count,
|
||||
Index = Designs.Count,
|
||||
};
|
||||
_designs.Add(design);
|
||||
Designs.Add(design);
|
||||
Glamourer.Log.Debug($"Added new design {design.Identifier}.");
|
||||
_saveService.ImmediateSave(design);
|
||||
_event.Invoke(DesignChanged.Type.Created, design, path);
|
||||
|
|
@ -137,10 +135,10 @@ public class DesignManager
|
|||
LastEdit = DateTimeOffset.UtcNow,
|
||||
Identifier = CreateNewGuid(),
|
||||
Name = actualName,
|
||||
Index = _designs.Count,
|
||||
Index = Designs.Count,
|
||||
};
|
||||
|
||||
_designs.Add(design);
|
||||
Designs.Add(design);
|
||||
Glamourer.Log.Debug($"Added new design {design.Identifier} by cloning Temporary Design.");
|
||||
_saveService.ImmediateSave(design);
|
||||
_event.Invoke(DesignChanged.Type.Created, design, path);
|
||||
|
|
@ -157,9 +155,9 @@ public class DesignManager
|
|||
LastEdit = DateTimeOffset.UtcNow,
|
||||
Identifier = CreateNewGuid(),
|
||||
Name = actualName,
|
||||
Index = _designs.Count,
|
||||
Index = Designs.Count,
|
||||
};
|
||||
_designs.Add(design);
|
||||
Designs.Add(design);
|
||||
Glamourer.Log.Debug(
|
||||
$"Added new design {design.Identifier} by cloning {clone.Identifier.ToString()}.");
|
||||
_saveService.ImmediateSave(design);
|
||||
|
|
@ -170,9 +168,9 @@ public class DesignManager
|
|||
/// <summary> Delete a design. </summary>
|
||||
public void Delete(Design design)
|
||||
{
|
||||
foreach (var d in _designs.Skip(design.Index + 1))
|
||||
foreach (var d in Designs.Skip(design.Index + 1))
|
||||
--d.Index;
|
||||
_designs.RemoveAt(design.Index);
|
||||
Designs.RemoveAt(design.Index);
|
||||
_saveService.ImmediateDelete(design);
|
||||
_event.Invoke(DesignChanged.Type.Deleted, design, null);
|
||||
}
|
||||
|
|
@ -591,7 +589,7 @@ public class DesignManager
|
|||
var errors = 0;
|
||||
var skips = 0;
|
||||
var successes = 0;
|
||||
var oldDesigns = _designs.ToList();
|
||||
var oldDesigns = Designs.ToList();
|
||||
try
|
||||
{
|
||||
var text = File.ReadAllText(_saveService.FileNames.MigrationDesignFile);
|
||||
|
|
@ -697,7 +695,7 @@ public class DesignManager
|
|||
while (true)
|
||||
{
|
||||
var guid = Guid.NewGuid();
|
||||
if (_designs.All(d => d.Identifier != guid))
|
||||
if (!Designs.Contains(guid))
|
||||
return guid;
|
||||
}
|
||||
}
|
||||
|
|
@ -709,11 +707,11 @@ public class DesignManager
|
|||
/// </summary>
|
||||
private bool Add(Design design, string? message)
|
||||
{
|
||||
if (_designs.Any(d => d == design || d.Identifier == design.Identifier))
|
||||
if (Designs.Any(d => d == design || d.Identifier == design.Identifier))
|
||||
return false;
|
||||
|
||||
design.Index = _designs.Count;
|
||||
_designs.Add(design);
|
||||
design.Index = Designs.Count;
|
||||
Designs.Add(design);
|
||||
if (!message.IsNullOrEmpty())
|
||||
Glamourer.Log.Debug(message);
|
||||
_saveService.ImmediateSave(design);
|
||||
|
|
@ -740,9 +738,10 @@ public class DesignManager
|
|||
}
|
||||
|
||||
/// <summary> Change a mainhand weapon and either fix or apply appropriate offhand and potentially gauntlets. </summary>
|
||||
private bool ChangeMainhandPeriphery(Design design, EquipItem currentMain, EquipItem currentOff, EquipItem newMain, out EquipItem? newOff, out EquipItem? newGauntlets)
|
||||
private bool ChangeMainhandPeriphery(Design design, EquipItem currentMain, EquipItem currentOff, EquipItem newMain, out EquipItem? newOff,
|
||||
out EquipItem? newGauntlets)
|
||||
{
|
||||
newOff = null;
|
||||
newOff = null;
|
||||
newGauntlets = null;
|
||||
if (newMain.Type != currentMain.Type)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,4 +3,16 @@
|
|||
namespace Glamourer.Designs;
|
||||
|
||||
public class DesignStorage : List<Design>, IService
|
||||
{}
|
||||
{
|
||||
public bool TryGetValue(Guid identifier, [NotNullWhen(true)] out Design? design)
|
||||
{
|
||||
design = ByIdentifier(identifier);
|
||||
return design != null;
|
||||
}
|
||||
|
||||
public Design? ByIdentifier(Guid identifier)
|
||||
=> this.FirstOrDefault(d => d.Identifier == identifier);
|
||||
|
||||
public bool Contains(Guid identifier)
|
||||
=> ByIdentifier(identifier) != null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -587,7 +587,7 @@ public class CommandService : IDisposable
|
|||
|
||||
if (Guid.TryParse(argument, out var guid))
|
||||
{
|
||||
design = _designManager.Designs.FirstOrDefault(d => d.Identifier == guid);
|
||||
design = _designManager.Designs.ByIdentifier(guid);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
namespace Glamourer.Services
|
||||
{
|
||||
internal interface IGamePathParser
|
||||
{
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue