package com.spaceproject.systems;

import com.badlogic.ashley.core.Engine;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IntervalSystem;
import com.badlogic.ashley.utils.ImmutableArray;
import com.spaceproject.components.ExpireComponent;
import com.spaceproject.components.RemoveComponent;
import com.spaceproject.utility.Mappers;

public class ExpireSystem extends IntervalSystem {
    
    private ImmutableArray<Entity> entities;
    private Engine engine;
    
    public ExpireSystem() {
        super(1);
    }
    
    @Override
    public void addedToEngine(Engine engine) {
        entities = engine.getEntitiesFor(Family.all(ExpireComponent.class).get());
        this.engine = engine;
    }
    
    
    @Override
    protected void updateInterval() {
        //remove entities when their time runs out
        for (Entity entity : entities) {
            ExpireComponent expire = Mappers.expire.get(entity);
            
            expire.time -= 1;
            
            if (expire.time <= 0) {
                entity.add(new RemoveComponent());
            }
        }
        
    }
    
    
}

@@ -499,35 +499,8 @@
 es;%0A
-    private Engine engine;%0A
     
@@ -709,44 +709,9 @@
     
-    this.engine = engine;%0A    %7D%0A    
+%7D
 %0A   
@@ -1096,23 +1096,9 @@
     
-    %0A    %7D%0A    
+%7D
 %0A   

Update ExpireSystem.java