This commit is contained in:
Ottermandias 2023-06-16 16:13:26 +02:00
parent 7463aafa13
commit 27f151c55a
32 changed files with 1744 additions and 151 deletions

View file

@ -0,0 +1,56 @@
using System;
using System.IO;
using Glamourer.Gui;
using Newtonsoft.Json.Linq;
namespace Glamourer.Services;
public class ConfigMigrationService
{
private readonly SaveService _saveService;
private Configuration _config = null!;
private JObject _data = null!;
public ConfigMigrationService(SaveService saveService)
=> _saveService = saveService;
public void Migrate(Configuration config)
{
_config = config;
if (config.Version >= Configuration.Constants.CurrentVersion || !File.Exists(_saveService.FileNames.ConfigFile))
{
AddColors(config, false);
return;
}
_data = JObject.Parse(File.ReadAllText(_saveService.FileNames.ConfigFile));
MigrateV1To2();
AddColors(config, true);
}
private void MigrateV1To2()
{
if (_config.Version > 1)
return;
_config.Version = 2;
var customizationColor = _data["CustomizationColor"]?.ToObject<uint>() ?? ColorId.CustomizationDesign.Data().DefaultColor;
_config.Colors[ColorId.CustomizationDesign] = customizationColor;
var stateColor = _data["StateColor"]?.ToObject<uint>() ?? ColorId.StateDesign.Data().DefaultColor;
_config.Colors[ColorId.StateDesign] = stateColor;
var equipmentColor = _data["EquipmentColor"]?.ToObject<uint>() ?? ColorId.EquipmentDesign.Data().DefaultColor;
_config.Colors[ColorId.EquipmentDesign] = equipmentColor;
}
private static void AddColors(Configuration config, bool forceSave)
{
var save = false;
foreach (var color in Enum.GetValues<ColorId>())
save |= config.Colors.TryAdd(color, color.Data().DefaultColor);
if (save || forceSave)
config.Save();
Colors.SetColors(config);
}
}

View file

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;
using Dalamud.Plugin;
using Glamourer.Designs;
namespace Glamourer.Services;
@ -32,4 +33,7 @@ public class FilenameService
public string DesignFile(string identifier)
=> Path.Combine(DesignDirectory, $"{identifier}.json");
public string DesignFile(Design design)
=> DesignFile(design.Identifier.ToString());
}

View file

@ -16,6 +16,8 @@ public class ItemManager : IDisposable
public const string SmallClothesNpc = "Smallclothes (NPC)";
public const ushort SmallClothesNpcModel = 9903;
private readonly Configuration _config;
public readonly IdentifierService IdentifierService;
public readonly ExcelSheet<Lumina.Excel.GeneratedSheets.Item> ItemSheet;
public readonly StainData Stains;
@ -24,8 +26,10 @@ public class ItemManager : IDisposable
public readonly EquipItem DefaultSword;
public ItemManager(DalamudPluginInterface pi, DataManager gameData, IdentifierService identifierService, ItemService itemService)
public ItemManager(Configuration config, DalamudPluginInterface pi, DataManager gameData, IdentifierService identifierService,
ItemService itemService)
{
_config = config;
ItemSheet = gameData.GetExcelSheet<Lumina.Excel.GeneratedSheets.Item>()!;
IdentifierService = identifierService;
Stains = new StainData(pi, gameData, gameData.Language);
@ -42,10 +46,8 @@ public class ItemManager : IDisposable
public (bool, CharacterArmor) ResolveRestrictedGear(CharacterArmor armor, EquipSlot slot, Race race, Gender gender)
// TODO
//if (_config.UseRestrictedGearProtection)
=> RestrictedGear.ResolveRestricted(armor, slot, race, gender);
//return (false, armor);
=> _config.UseRestrictedGearProtection ? RestrictedGear.ResolveRestricted(armor, slot, race, gender) : (false, armor);
public static uint NothingId(EquipSlot slot)
=> uint.MaxValue - 128 - (uint)slot.ToSlot();
@ -82,6 +84,20 @@ public class ItemManager : IDisposable
return item;
}
public EquipItem Resolve(FullEquipType type, uint itemId)
{
if (itemId == NothingId(type))
return NothingItem(type);
if (!ItemService.AwaitedService.TryGetValue(itemId, false, out var item))
return new EquipItem(string.Intern($"Unknown #{itemId}"), itemId, 0, 0, 0, 0, 0);
if (item.Type != type)
return new EquipItem(string.Intern($"Invalid #{itemId}"), itemId, item.IconId, item.ModelId, item.WeaponType, item.Variant, 0);
return item;
}
public EquipItem Identify(EquipSlot slot, SetId id, byte variant)
{
slot = slot.ToSlot();

View file

@ -0,0 +1,17 @@
using OtterGui.Classes;
using OtterGui.Log;
namespace Glamourer.Services;
/// <summary>
/// Any file type that we want to save via SaveService.
/// </summary>
public interface ISavable : ISavable<FilenameService>
{ }
public sealed class SaveService : SaveServiceBase<FilenameService>
{
public SaveService(Logger log, FrameworkManager framework, FilenameService fileNames)
: base(log, framework, fileNames)
{ }
}

View file

@ -36,7 +36,11 @@ public static class ServiceManager
private static IServiceCollection AddMeta(this IServiceCollection services)
=> services.AddSingleton<ChatService>()
.AddSingleton<FilenameService>()
.AddSingleton<BackupService>();
.AddSingleton<BackupService>()
.AddSingleton<FrameworkManager>()
.AddSingleton<SaveService>()
.AddSingleton<ConfigMigrationService>()
.AddSingleton<Configuration>();
private static IServiceCollection AddEvents(this IServiceCollection services)
=> services.AddSingleton<VisorStateChanged>()
@ -54,11 +58,11 @@ public static class ServiceManager
.AddSingleton<ChangeCustomizeService>()
.AddSingleton<UpdateSlotService>()
.AddSingleton<WeaponService>()
.AddSingleton<PenumbraService>();
.AddSingleton<PenumbraService>()
.AddSingleton<ObjectManager>();
private static IServiceCollection AddUi(this IServiceCollection services)
=> services
.AddSingleton<DebugTab>()
=> services.AddSingleton<DebugTab>()
.AddSingleton<MainWindow>()
.AddSingleton<GlamourerWindowSystem>();

View file

@ -51,7 +51,7 @@ public abstract class AsyncServiceWrapper<T> : IDisposable
else
{
Service = service;
Item.Log.Verbose($"[{Name}] Created.");
Glamourer.Log.Verbose($"[{Name}] Created.");
_task = null;
}
});
@ -71,7 +71,7 @@ public abstract class AsyncServiceWrapper<T> : IDisposable
_task = null;
if (Service is IDisposable d)
d.Dispose();
Item.Log.Verbose($"[{Name}] Disposed.");
Glamourer.Log.Verbose($"[{Name}] Disposed.");
}
}