package net.mgsx.rainstick.systems;

import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;

import net.mgsx.game.core.GamePipeline;
import net.mgsx.game.core.annotations.Editable;
import net.mgsx.game.core.annotations.EditableSystem;
import net.mgsx.game.core.annotations.Storable;
import net.mgsx.game.plugins.box2d.components.Box2DBodyModel;

@Storable("rainstick.calibration")
@EditableSystem
public class CalibrationSystem extends IteratingSystem
{
	@Editable(readonly=true, realtime=true)
	public float velMax, massMax;
	
	@Editable
	public boolean run;

	public CalibrationSystem() {
		super(Family.all(Box2DBodyModel.class).get(), GamePipeline.AFTER_PHYSICS);
	}
	
	@Editable
	public void reset(){
		velMax = massMax = 0;
	}
	
	@Override
	public void update(float deltaTime) {
		if(run){
			super.update(deltaTime);
		}
	}
	
	@Override
	protected void processEntity(Entity entity, float deltaTime) {
		Box2DBodyModel physics = Box2DBodyModel.components.get(entity);
		velMax = Math.max(physics.body.getLinearVelocity().len(), velMax);
		massMax = Math.max(physics.body.getMass(), massMax);
	}
}

@@ -594,16 +594,28 @@
  massMax
+, xMin, xMax
 ;%0A%09%0A%09@Ed
@@ -808,16 +808,30 @@
 assMax =
+ xMin = xMax =
  0;%0A%09%7D%0A%09
@@ -1194,13 +1194,123 @@
 ssMax);%0A
+%09%09xMin = Math.min(physics.body.getPosition().x, xMin);%0A%09%09xMax = Math.max(physics.body.getPosition().x, xMax);%0A
 %09%7D%0A%7D%0A

add stereo in calibration