Ejemplo n.º 1
0
        /// <summary>
        /// Asynchronously creates a new <see cref="SharperEntity"/> and registers it to the game.
        /// </summary>
        /// <returns>A <see cref="Task{TResult}"/> that will contain the new <see cref="SharperEntity"/> on completion.</returns>
        public Task <SharperEntity> CreateEntityAsync()
        {
            var ent = new SharperEntity();

            Entities.Add(ent);
            return(Task.FromResult(ent)); //I have no idea if this is ok LUL
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers a component of type <typeparamref name="T"/> and assigns it to the target <see cref="SharperEntity"/>.
        /// </summary>
        /// <param name="entity">The target entity.</param>
        /// <param name="args">the values for the new component.</param>
        /// <returns>Returns a <see cref="Task"/> that represents the registration work.</returns>
        public Task RegisterComponentAsync(SharperEntity entity, params object[] args)
        {
            var inputArr = new object[args.Length + 1];

            inputArr[0] = entity;

            for (int i = 1; i < inputArr.Length; i++)
            {
                inputArr[i] = args[i - 1];
            }

            T component = (T)Activator.CreateInstance(typeof(T), inputArr);

            Components.Add(component);

            ComponentRegistered?.Invoke(this, new SharperComponentEventArgs(component));
            return(Task.CompletedTask);
        }
Ejemplo n.º 3
0
 public SharperEntityEventArgs(SharperEntity entity)
 {
     Entity = entity;
 }
Ejemplo n.º 4
0
 public Task UnregisterAllComponentsByEntityAsync(SharperEntity entity)
 {
     Components.RemoveAll(x => x.Entity == entity);
     return(Task.CompletedTask);
 }
 public bool EntityHasComponent(BaseSharperComponent component, SharperEntity entity)
 {
     return(Components.Find(c => c == component).Entity == entity);
 }
 public bool EntityHasComponentOfManagingType(SharperEntity entity)
 {
     return(Components.Any(x => x.Entity == entity));
 }
Ejemplo n.º 7
0
 public ISharperConnection GetConnectionByEntity(SharperEntity entity)
 {
     return(Components.First(x => x.Entity == entity).BindingSource);
 }
Ejemplo n.º 8
0
 public Task <bool> EntityHasComponentOfManagingTypeAsync(SharperEntity entity)
 {
     return(Task.FromResult(Components.Any(x => x.Entity == entity)));
 }
 public SharperInputComponent(SharperEntity entity, ISharperConnection bindingSource) : base(entity)
 {
     BindingSource = bindingSource;
 }
Ejemplo n.º 10
0
 public SharperInputComponent(SharperEntity entity, IUniverseCommandSource bindingSource) : base(entity)
 {
     BindingSource = bindingSource;
 }