more helpful ID lookup error messages

pull/5/head
Evan Hemsley 2019-08-22 15:20:10 -07:00
parent 0a2cc2527a
commit fa6958ed95
5 changed files with 82 additions and 7 deletions

View File

@ -166,19 +166,40 @@ namespace Encompass
} }
internal IComponent GetComponentByID(Guid componentID) internal IComponent GetComponentByID(Guid componentID)
{
if (IDToComponent.ContainsKey(componentID))
{ {
return IDToComponent[componentID]; return IDToComponent[componentID];
} }
else
{
throw new ComponentNotFoundException("Component with ID {0} does not exist.", componentID);
}
}
internal Type GetComponentTypeByID(Guid componentID) internal Type GetComponentTypeByID(Guid componentID)
{
if (componentIDToType.ContainsKey(componentID))
{ {
return componentIDToType[componentID]; return componentIDToType[componentID];
} }
else
{
throw new ComponentNotFoundException("Component with ID {0} does not exist.", componentID);
}
}
internal Guid GetEntityIDByComponentID(Guid componentID) internal Guid GetEntityIDByComponentID(Guid componentID)
{
if (componentIDToEntityID.ContainsKey(componentID))
{ {
return componentIDToEntityID[componentID]; return componentIDToEntityID[componentID];
} }
else
{
throw new ComponentNotFoundException("Component with ID {0} does not exist.", componentID);
}
}
internal void MarkAllComponentsOnEntityForRemoval(Guid entityID) internal void MarkAllComponentsOnEntityForRemoval(Guid entityID)
{ {

View File

@ -276,18 +276,39 @@ namespace Encompass
} }
internal IComponent GetComponentByID(Guid componentID) internal IComponent GetComponentByID(Guid componentID)
{
if (componentIDToComponent.ContainsKey(componentID))
{ {
return componentIDToComponent[componentID]; return componentIDToComponent[componentID];
} }
else
{
throw new ComponentNotFoundException("Component with ID {0} does not exist.", componentID);
}
}
internal Type GetComponentTypeByID(Guid componentID) internal Type GetComponentTypeByID(Guid componentID)
{
if (componentIDToType.ContainsKey(componentID))
{ {
return componentIDToType[componentID]; return componentIDToType[componentID];
} }
else
{
throw new ComponentNotFoundException("Component with ID {0} does not exist.", componentID);
}
}
internal Guid GetEntityIDByComponentID(Guid componentID) internal Guid GetEntityIDByComponentID(Guid componentID)
{
if (componentIDToEntityID.ContainsKey(componentID))
{ {
return componentIDToEntityID[componentID]; return componentIDToEntityID[componentID];
} }
else
{
throw new ComponentNotFoundException("Component with ID {0} does not exist.", componentID);
}
}
} }
} }

View File

@ -1,5 +1,7 @@
using System.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Encompass.Exceptions;
namespace Encompass namespace Encompass
{ {
@ -34,9 +36,16 @@ namespace Encompass
} }
public Entity GetEntity(Guid id) public Entity GetEntity(Guid id)
{
if (IDToEntity.ContainsKey(id))
{ {
return IDToEntity[id]; return IDToEntity[id];
} }
else
{
throw new EntityNotFoundException("Entity with ID {0} does not exist.", id);
}
}
public void MarkForDestroy(Guid entityID) public void MarkForDestroy(Guid entityID)
{ {

View File

@ -0,0 +1,12 @@
using System;
namespace Encompass.Exceptions
{
public class ComponentNotFoundException : Exception
{
public ComponentNotFoundException(
string format,
params object[] args
) : base(string.Format(format, args)) { }
}
}

View File

@ -0,0 +1,12 @@
using System;
namespace Encompass.Exceptions
{
public class EntityNotFoundException : Exception
{
public EntityNotFoundException(
string format,
params object[] args
) : base(string.Format(format, args)) { }
}
}