package framework.spacial.rotational;
import java.io.IOException;
import framework.component.util.FloatValueComponent;
import framework.event.Event;
import framework.event.EventListener;
import framework.event.EventSystem;
import framework.io.CustomInputStream;
import framework.spacial.OrientationComponent;
import framework.timing.SystemClockComponent.TimePassedEvent;
public class SpinComponent extends FloatValueComponent implements EventListener{
public SpinComponent(CustomInputStream in, int baseID, byte versionNum) throws IOException {
super(in, baseID, versionNum);
}
public SpinComponent(float value) {
super(value);
EventSystem.getInstance().registerEventListener(this, "TimePassed", null);
}
@Override
public boolean allowSameTypedSiblings() {
return false;
}
@Override
public void onEvent(Event e) {
if(e != null){
if(e.getType().equals("TimePassed")){
OrientationComponent orientaion = (OrientationComponent) getSiblingByType(OrientationComponent.class.getName());
if(orientaion != null){
TimePassedEvent t = (TimePassedEvent) e;
orientaion.setValue(orientaion.getValue()+t.getDelta()*this.getValue());
}
}
}
}
}