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

@ -167,17 +167,38 @@ namespace Encompass
internal IComponent GetComponentByID(Guid componentID) internal IComponent GetComponentByID(Guid componentID)
{ {
return IDToComponent[componentID]; if (IDToComponent.ContainsKey(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)
{ {
return componentIDToType[componentID]; if (componentIDToType.ContainsKey(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)
{ {
return componentIDToEntityID[componentID]; if (componentIDToEntityID.ContainsKey(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

@ -277,17 +277,38 @@ namespace Encompass
internal IComponent GetComponentByID(Guid componentID) internal IComponent GetComponentByID(Guid componentID)
{ {
return componentIDToComponent[componentID]; if (componentIDToComponent.ContainsKey(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)
{ {
return componentIDToType[componentID]; if (componentIDToType.ContainsKey(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)
{ {
return componentIDToEntityID[componentID]; if (componentIDToEntityID.ContainsKey(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
{ {
@ -35,7 +37,14 @@ namespace Encompass
public Entity GetEntity(Guid id) public Entity GetEntity(Guid id)
{ {
return IDToEntity[id]; if (IDToEntity.ContainsKey(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)) { }
}
}