using System.Linq;
using Vintagestory.API.Common.Entities;
+using Vintagestory.API.MathTools;
namespace Automap
{
/// <summary>
+ /// Actual Physical Point in space - that is interesting.
+ /// </summary>
+ public struct EntityOfInterest
+ {
+ public string Notes;
+ public BlockPos Location;
+ public DateTimeOffset Timestamp;
+ public long EntityId;
+ }
+
+ /// <summary>
/// Entities of interest.
/// </summary>
/// <remarks>Tracked by ID - these never leave.</remarks>
- public class EntitiesOfInterest
+ public class EntitiesOfInterest : KeyedCollection<long, EntityOfInterest>
{
- private Dictionary<long, PointOfInterest> entitySet = new Dictionary<long, PointOfInterest>(50);
-
- internal void Upsert(Entity something, string message = @"")
+ internal void AddReplace(EntityOfInterest entity)
{
- if (entitySet.ContainsKey(something.EntityId)) {
- var movingPOI = entitySet[something.EntityId];
- movingPOI.Location = something.Pos.AsBlockPos.Copy( );
- movingPOI.Timestamp = DateTimeOffset.UtcNow;
- }
- else {
- PointOfInterest newPOI = new PointOfInterest( );
- newPOI.EntityId = something.EntityId;
- newPOI.Location = something.Pos.AsBlockPos.Copy( );
- newPOI.Timestamp = DateTimeOffset.UtcNow;
- newPOI.Notes = message;
- entitySet.Add(something.EntityId, newPOI );
- }
-
- }
-
+ if (Contains(entity.EntityId))
+ Remove(entity.EntityId);
- public List<PointOfInterest> PointsList {
- get
- {
- return entitySet.Values.ToList();
- }
+ Add(entity);
}
+ protected override long GetKeyForItem(EntityOfInterest item)
+ => item.EntityId;
}
}