Narrow legacy catalog to item hydration
This commit is contained in:
parent
596534896f
commit
9655d5ad7b
7 changed files with 21 additions and 29 deletions
|
|
@ -65,7 +65,7 @@ public abstract class DatabaseEntry
|
|||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class DatabaseLink<T> : DatabaseLinkBase where T : DatabaseEntry
|
||||
public class DatabaseLink<T> : DatabaseLinkBase where T : ItemData
|
||||
{
|
||||
[IgnoreMember]
|
||||
public T Value => ResolveLegacyCatalog<T>(LinkID);
|
||||
|
|
@ -80,10 +80,10 @@ public class DatabaseLinkBase
|
|||
[IgnoreMember]
|
||||
private static ILegacyCatalogReader Catalog { get; set; }
|
||||
|
||||
protected static T ResolveLegacyCatalog<T>(Guid linkId) where T : DatabaseEntry
|
||||
protected static T ResolveLegacyCatalog<T>(Guid linkId) where T : ItemData
|
||||
{
|
||||
if (Catalog == null)
|
||||
throw new InvalidOperationException("Legacy DatabaseLink resolution is not bound. Open LegacyCatalogBoundary before reading legacy catalog object graphs.");
|
||||
throw new InvalidOperationException("Legacy item link resolution is not bound. Open LegacyCatalogBoundary before reading legacy item object graphs.");
|
||||
|
||||
return Catalog.Get<T>(linkId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ using UniRx;
|
|||
|
||||
public interface ILegacyCatalogReader
|
||||
{
|
||||
DatabaseEntry Get(Guid guid);
|
||||
T Get<T>(Guid guid) where T : DatabaseEntry;
|
||||
ItemData Get(Guid guid);
|
||||
T Get<T>(Guid guid) where T : ItemData;
|
||||
}
|
||||
|
||||
public class LegacyCatalogCache : ILegacyCatalogReader
|
||||
|
|
@ -21,7 +21,7 @@ public class LegacyCatalogCache : ILegacyCatalogReader
|
|||
|
||||
private List<CacheBackingStore> _backingStores = new List<CacheBackingStore>();
|
||||
|
||||
private readonly Dictionary<Guid, DatabaseEntry> _entries = new Dictionary<Guid, DatabaseEntry>();
|
||||
private readonly Dictionary<Guid, ItemData> _entries = new Dictionary<Guid, ItemData>();
|
||||
|
||||
public void AddBackingStore(CacheBackingStore store)
|
||||
{
|
||||
|
|
@ -41,21 +41,21 @@ public class LegacyCatalogCache : ILegacyCatalogReader
|
|||
{
|
||||
lock(addLock)
|
||||
{
|
||||
if (entry != null)
|
||||
if (entry is ItemData item)
|
||||
{
|
||||
_entries[entry.ID] = entry;
|
||||
_entries[item.ID] = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DatabaseEntry Get(Guid guid)
|
||||
public ItemData Get(Guid guid)
|
||||
{
|
||||
DatabaseEntry entry;
|
||||
ItemData entry;
|
||||
_entries.TryGetValue(guid, out entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
public T Get<T>(Guid guid) where T : DatabaseEntry
|
||||
public T Get<T>(Guid guid) where T : ItemData
|
||||
{
|
||||
return Get(guid) as T;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue