package com.bitdecay.game.system;

import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.bitdecay.game.component.PositionComponent;
import com.bitdecay.game.component.RemoveNowComponent;
import com.bitdecay.game.component.SonarPingComponent;
import com.bitdecay.game.gameobject.MyGameObject;
import com.bitdecay.game.room.AbstractRoom;
import com.bitdecay.game.system.abstracted.AbstractDrawableSystem;

/**
 * Created by Monday on 1/21/2017.
 */
public class SonarPingSystem extends AbstractDrawableSystem {
    public float propagationSpeed = 6f;
    public float maxSonarRange = 2000f;

    public SonarPingSystem(AbstractRoom room) {
        super(room);
    }

    @Override
    protected boolean validateGob(MyGameObject gob) {
        return gob.hasComponents(PositionComponent.class, SonarPingComponent.class);
    }

    @Override
    public void preDraw(SpriteBatch spriteBatch, OrthographicCamera camera) {
        DrawSystem.pingShader.begin();
        gobs.forEach(gob -> {
            gob.forEachComponentDo(SonarPingComponent.class, ping -> {
                ping.radius += propagationSpeed;
                if (ping.radius > maxSonarRange){
                    gob.addComponent(new RemoveNowComponent(gob));
                }
                DrawSystem.pingShader.setUniformf("f_sweepRadius", ping.radius);
            });

            gob.forEachComponentDo(PositionComponent.class, pos -> {
                Vector3 projected = camera.project(new Vector3(pos.x, pos.y, 0));
                DrawSystem.pingShader.setUniformf("v_center",projected.x, projected.y);
            });
        });
        DrawSystem.pingShader.end();
    }

    @Override
    public void draw(SpriteBatch spriteBatch, OrthographicCamera camera) {
        // no op
    }
}

@@ -673,17 +673,17 @@
 Range = 
-2
+4
 000f;%0A%0A 
@@ -1230,17 +1230,18 @@
 .radius 
-%3E
+%3C=
  maxSona
@@ -1249,16 +1249,126 @@
 Range)%7B%0A
+                    DrawSystem.pingShader.setUniformf(%22f_sweepRadius%22, ping.radius);%0A                %7D else %7B%0A
         
@@ -1434,22 +1434,8 @@
     
-            %7D%0A
     
@@ -1493,37 +1493,45 @@
 eepRadius%22, 
-ping.radius);
+0);%0A                %7D
 %0A           

fix sonar