Remove legacy catalog enumeration bridges
This commit is contained in:
parent
0cfa9ea2df
commit
06f32937b6
5 changed files with 17 additions and 134 deletions
|
|
@ -5,8 +5,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using MessagePack;
|
||||
using UniRx;
|
||||
|
||||
|
|
@ -14,7 +12,6 @@ public interface ILegacyCatalogReader
|
|||
{
|
||||
DatabaseEntry Get(Guid guid);
|
||||
T Get<T>(Guid guid) where T : DatabaseEntry;
|
||||
IEnumerable<T> GetAll<T>() where T : DatabaseEntry;
|
||||
}
|
||||
|
||||
public class LegacyCatalogCache : ILegacyCatalogReader
|
||||
|
|
@ -24,36 +21,15 @@ public class LegacyCatalogCache : ILegacyCatalogReader
|
|||
|
||||
private List<CacheBackingStore> _backingStores = new List<CacheBackingStore>();
|
||||
|
||||
private readonly Dictionary<Type, CacheBackingStore> _typeStores = new Dictionary<Type, CacheBackingStore>();
|
||||
private readonly Dictionary<CacheBackingStore, Type[]> _storeTypes = new Dictionary<CacheBackingStore, Type[]>();
|
||||
|
||||
private readonly Dictionary<Guid, DatabaseEntry> _entries = new Dictionary<Guid, DatabaseEntry>();
|
||||
|
||||
private readonly Dictionary<Type, DatabaseEntry> _globals = new Dictionary<Type, DatabaseEntry>();
|
||||
private readonly Dictionary<Type, HashSet<DatabaseEntry>> _types = new Dictionary<Type, HashSet<DatabaseEntry>>();
|
||||
|
||||
public IEnumerable<DatabaseEntry> AllEntries => _entries.Values;
|
||||
|
||||
public LegacyCatalogCache()
|
||||
{
|
||||
foreach (var type in typeof(DatabaseEntry).GetAllChildClasses())
|
||||
{
|
||||
_types[type] = new HashSet<DatabaseEntry>();
|
||||
|
||||
if (type.GetCustomAttribute<GlobalSettingsAttribute>() != null)
|
||||
{
|
||||
_globals[type] = null;
|
||||
AddInternal(Activator.CreateInstance(type) as DatabaseEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddBackingStore(CacheBackingStore store, params Type[] domain)
|
||||
{
|
||||
if (domain.Length > 0)
|
||||
{
|
||||
_storeTypes[store] = domain;
|
||||
foreach (var t in domain) _typeStores[t] = store;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -77,34 +53,11 @@ public class LegacyCatalogCache : ILegacyCatalogReader
|
|||
{
|
||||
if (entry != null)
|
||||
{
|
||||
var exists = _entries.ContainsKey(entry.ID);
|
||||
|
||||
var type = entry.GetType();
|
||||
|
||||
if (_globals.ContainsKey(type))
|
||||
{
|
||||
if(_globals[type]!=null)
|
||||
{
|
||||
RemoveInternal(_globals[type]);
|
||||
exists = true;
|
||||
}
|
||||
_globals[type] = entry;
|
||||
}
|
||||
|
||||
_entries[entry.ID] = entry;
|
||||
_types[type].Add(entry);
|
||||
foreach (var parentType in type.GetParentTypes())
|
||||
{
|
||||
if(_types.ContainsKey(parentType))
|
||||
_types[parentType].Add(entry);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsGlobal(DatabaseEntry entry) => _globals.ContainsKey(entry.GetType());
|
||||
|
||||
public DatabaseEntry Get(Guid guid)
|
||||
{
|
||||
DatabaseEntry entry;
|
||||
|
|
@ -116,39 +69,6 @@ public class LegacyCatalogCache : ILegacyCatalogReader
|
|||
{
|
||||
return Get(guid) as T;
|
||||
}
|
||||
|
||||
public DatabaseEntry GetGlobal(Type type)
|
||||
{
|
||||
if (_globals.ContainsKey(type)) return _globals[type];
|
||||
return null;
|
||||
}
|
||||
|
||||
public T GetGlobal<T>() where T : DatabaseEntry
|
||||
{
|
||||
return GetGlobal(typeof(T)) as T;
|
||||
}
|
||||
|
||||
public IEnumerable<DatabaseEntry> GetAll(Type type)
|
||||
{
|
||||
return !_types.ContainsKey(type) ? Enumerable.Empty<DatabaseEntry>() : _types[type];
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetAll<T>() where T : DatabaseEntry
|
||||
{
|
||||
var type = typeof(T);
|
||||
return !_types.ContainsKey(type) ? Enumerable.Empty<T>() : _types[type].Cast<T>();
|
||||
}
|
||||
|
||||
private void RemoveInternal(DatabaseEntry entry)
|
||||
{
|
||||
_entries.Remove(entry.ID);
|
||||
var type = entry.GetType();
|
||||
foreach (var parentType in type.GetParentTypes())
|
||||
{
|
||||
if(_types.ContainsKey(parentType))
|
||||
_types[parentType].Remove(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class CacheBackingStore
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ public class ItemManager
|
|||
|
||||
// private Guid _forceLoadZone;
|
||||
|
||||
// public GlobalData GlobalData => _globalData ?? (_globalData = GetCatalogEntries<GlobalData>().FirstOrDefault());
|
||||
private readonly ILegacyCatalogReader _itemData;
|
||||
public GameplaySettings GameplaySettings { get; }
|
||||
|
||||
|
|
@ -59,55 +58,11 @@ public class ItemManager
|
|||
return _itemData.Get<T>(id);
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetCatalogEntries<T>() where T : DatabaseEntry
|
||||
{
|
||||
return _itemData.GetAll<T>();
|
||||
}
|
||||
|
||||
public void Log(string s)
|
||||
{
|
||||
_logger(s);
|
||||
}
|
||||
|
||||
// public void Update()
|
||||
// {
|
||||
// foreach(var zone in _zones.Values)
|
||||
// zone.Update((float) Time, _deltaTime);
|
||||
//
|
||||
// foreach (var corporation in Cache.GetAll<Corporation>())
|
||||
// {
|
||||
// foreach (var tasks in corporation.Tasks
|
||||
// .Select(id => Cache.Get<AgentTask>(id)) // Fetch the tasks from the database cache
|
||||
// .Where(task => !task.Reserved) // Filter out tasks that have already been reserved
|
||||
// .GroupBy(task => task.Type)) // Group tasks by type
|
||||
// {
|
||||
// // Create a list of available controllers for this task type
|
||||
// var availableControllers = CorporationControllers[corporation.ID]
|
||||
// .Where(controller => controller.Available && controller.TaskType == tasks.Key).ToList();
|
||||
//
|
||||
// // Iterate over the highest priority tasks for which controllers are available
|
||||
// foreach (var task in tasks.OrderByDescending(task => task.Priority).Take(availableControllers.Count))
|
||||
// {
|
||||
// // Find the nearest controller for this task
|
||||
// IController nearestController = availableControllers[0];
|
||||
// List<ZoneDefinition> nearestControllerPath = FindPath(GalaxyZones[availableControllers.First().Zone.Data.ID], GalaxyZones[task.Zone], true);
|
||||
// foreach (var controller in availableControllers.Skip(1))
|
||||
// {
|
||||
// var path = FindPath(GalaxyZones[controller.Zone.Data.ID], GalaxyZones[task.Zone], true);
|
||||
// if (path.Count < nearestControllerPath.Count)
|
||||
// {
|
||||
// nearestControllerPath = path;
|
||||
// nearestController = controller;
|
||||
// }
|
||||
// }
|
||||
// task.Reserved = true;
|
||||
// nearestController.AssignTask(task.ID);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
// public int ItemTier(CraftedItemData itemData)
|
||||
// {
|
||||
// if (Tier.ContainsKey(itemData)) return Tier[itemData];
|
||||
|
|
|
|||
|
|
@ -167,12 +167,12 @@ public class LoadoutGenerator
|
|||
|
||||
if (requestedType == typeof(GearData))
|
||||
{
|
||||
return item.Category is "GearData" or "WeaponItemData";
|
||||
return item.Category == "GearData" || item.Category == "WeaponItemData";
|
||||
}
|
||||
|
||||
if (requestedType == typeof(CargoBayData))
|
||||
{
|
||||
return item.Category is "CargoBayData" or "DockingBayData";
|
||||
return item.Category == "CargoBayData" || item.Category == "DockingBayData";
|
||||
}
|
||||
|
||||
return string.Equals(item.Category, requestedType.Name, StringComparison.Ordinal);
|
||||
|
|
|
|||
Loading…
Reference in a new issue