107 lines
3.3 KiB
C#
107 lines
3.3 KiB
C#
#nullable enable
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UVC.Core;
|
|
|
|
namespace UVC.Factory
|
|
{
|
|
public class FactoryObjectManager : SingletonScene<FactoryObjectManager>
|
|
{
|
|
public Dictionary<FactoryObjectInfo, FactoryObject> FactoryObjects { get; private set; } = new Dictionary<FactoryObjectInfo, FactoryObject>();
|
|
|
|
public void RegisterFactoryObject(FactoryObject factoryObject)
|
|
{
|
|
if (factoryObject == null || factoryObject.Info == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(factoryObject), "FactoryObject cannot be null.");
|
|
}
|
|
if (!FactoryObjects.ContainsKey(factoryObject.Info!))
|
|
{
|
|
FactoryObjects.Add(factoryObject.Info!, factoryObject);
|
|
}
|
|
}
|
|
|
|
public void UnregisterFactoryObject(FactoryObjectInfo factoryObjectInfo)
|
|
{
|
|
if (factoryObjectInfo == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(factoryObjectInfo), "factoryObjectInfo cannot be null.");
|
|
}
|
|
FactoryObjects.Remove(factoryObjectInfo);
|
|
}
|
|
|
|
public FactoryObject? GetFactoryObject(FactoryObjectInfo factoryObjectInfo)
|
|
{
|
|
if (factoryObjectInfo == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(factoryObjectInfo), "factoryObjectInfo cannot be null.");
|
|
}
|
|
FactoryObjects.TryGetValue(factoryObjectInfo, out var factoryObject);
|
|
return factoryObject;
|
|
}
|
|
|
|
public FactoryObject? FindByName(string name)
|
|
{
|
|
foreach (var kvp in FactoryObjects)
|
|
{
|
|
if (kvp.Key.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return kvp.Value;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public FactoryObject? FindById(string id)
|
|
{
|
|
foreach (var kvp in FactoryObjects)
|
|
{
|
|
if (kvp.Key.Id.Equals(id, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return kvp.Value;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public FactoryObject? FindByPosition(string position)
|
|
{
|
|
foreach (var kvp in FactoryObjects)
|
|
{
|
|
if (kvp.Key.Position.Equals(position, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return kvp.Value;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public List<FactoryObject> FindByArea(string area)
|
|
{
|
|
List<FactoryObject> foundObjects = new List<FactoryObject>();
|
|
foreach (var kvp in FactoryObjects)
|
|
{
|
|
if (kvp.Key.Area.Equals(area, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
foundObjects.Add(kvp.Value);
|
|
}
|
|
}
|
|
return foundObjects;
|
|
}
|
|
|
|
public List<FactoryObject> FindByFloor(string floor)
|
|
{
|
|
List<FactoryObject> foundObjects = new List<FactoryObject>();
|
|
foreach (var kvp in FactoryObjects)
|
|
{
|
|
if (kvp.Key.Floor.Equals(floor, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
foundObjects.Add(kvp.Value);
|
|
}
|
|
}
|
|
return foundObjects;
|
|
}
|
|
|
|
}
|
|
}
|