예제 #1
0
        /// <summary>
        ///    Returns Props of given component's data corresponding actor.
        /// </summary>
        private Props ResolveComponent(SpaceObjectComponent component)
        {
            if (component is Transform transform)
            {
                return(TransformActor.Props(_worldContextFactory, transform));
            }

            throw new TypeLoadException("Can't find corresponding space object component actor type for given data type.");
        }
        protected TickableComponentActor(WorldContextFactory worldContextFactory, SpaceObjectComponent component)
            : base(worldContextFactory, component)
        {
            Receive <Tick>(tick => OnTick(tick));

            Context
            .System
            .Scheduler
            .ScheduleTellRepeatedly(TimeSpan.Zero, TimeSpan.FromMilliseconds(20), Self, new Tick(), Self);
        }
        protected SpaceObjectComponentActor(WorldContextFactory worldContextFactory, SpaceObjectComponent component) :
            base(component)
        {
            WorldContextFactory = worldContextFactory;

            using (var worldContext = worldContextFactory.CreateDbContext())
            {
                // Unlike SpaceObjectActor, it is assumed here that component is already persisted in database.
                // Adding components to already existing SpaceObject is not needed now.
                Boolean idFound = worldContext
                                  .Components
                                  .Any(c => c.Id == component.Id);

                if (!idFound)
                {
                    throw new ArgumentException("Component with given Id not found.");
                }
            }
        }