Refactor alot of stuff

This commit is contained in:
2026-10-29 22:54:29 +01:00
parent c23b666ee4
commit 260abc2c98
138 changed files with 2835 additions and 466 deletions
+18 -2
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using KernelPanic.Data;
namespace KernelPanic.Meta
@@ -22,6 +23,7 @@ namespace KernelPanic.Meta
private readonly PlayerCollection _collection;
private readonly PackageDatabase _database;
private readonly Dictionary<string, Dictionary<PackageSlot, string>> _equippedByDistro = new(StringComparer.OrdinalIgnoreCase);
public List<string> MigrationNotices { get; } = new();
public PackageLoadout(PlayerCollection collection, PackageDatabase database)
{
@@ -137,21 +139,35 @@ namespace KernelPanic.Meta
Dictionary<PackageSlot, string> equipped = EnsureDistro(distroId);
equipped.Clear();
foreach (PackageLoadoutSlotSaveEntry slotEntry in slots ?? Array.Empty<PackageLoadoutSlotSaveEntry>())
// Keep items already in their category first, then relocate old equipment.
// A collision never changes ownership or upgrade levels.
foreach (PackageLoadoutSlotSaveEntry slotEntry in (slots ?? Array.Empty<PackageLoadoutSlotSaveEntry>())
.Where(s => s != null)
.OrderBy(s => _database?.FindById(s.packageId)?.Slot == s.slot ? 0 : 1)
.ThenBy(s => s.slot).ThenBy(s => s.packageId, StringComparer.Ordinal))
{
PackageDefinition package = _database == null ? null : _database.FindById(slotEntry?.packageId);
if (package == null || !_collection.IsPackageOwned(package.Id) || package.Slot != slotEntry.slot)
if (package == null || !_collection.IsPackageOwned(package.Id) || !package.AcceptsSavedSlot(slotEntry.slot))
{
continue;
}
if (equipped.TryGetValue(package.Slot, out string existing))
{
if (existing != package.Id)
MigrationNotices.Add($"{distroId}: {package.DisplayName} is now in {package.Slot.DisplayName()}. Unequipped because that slot is occupied; ownership and upgrades are retained.");
continue;
}
equipped[package.Slot] = package.Id;
if (package.Slot != slotEntry.slot)
MigrationNotices.Add($"{distroId}: {package.DisplayName} moved to {package.Slot.DisplayName()}.");
}
}
public void Clear()
{
_equippedByDistro.Clear();
MigrationNotices.Clear();
}
private void AddIfEquipped(string distroId, PackageSlot slot, List<PackageDefinition> packages)