package framework.component.util;
import java.io.IOException;
import framework.component.Component;
import framework.event.Event;
import framework.event.EventListener;
import framework.event.EventSystem;
import framework.io.CustomInputStream;
import framework.spacial.PositionComponent;
import framework.userinput.MouseListenerSystem.MouseMovedEvent;
public class MouseFollowerComponent extends Component implements EventListener{
public MouseFollowerComponent() {
super();
EventSystem.getInstance().registerEventListener(this, "MouseMoved", null);
}
public MouseFollowerComponent(CustomInputStream in, int baseID, byte versionNum) throws IOException {
super(in, baseID, versionNum);
EventSystem.getInstance().registerEventListener(this, "MouseMoved", null);
}
@Override
public boolean allowSameTypedSiblings() {
return false;
}
@Override
protected byte getDataFormatVersion() {
return 0;
}
@Override
public void onEvent(Event e) {
if(e != null && e.getType().equals("MouseMoved")){
PositionComponent pos = (PositionComponent) getSiblingByType(PositionComponent.class.getName());
if(pos != null){
MouseMovedEvent m = (MouseMovedEvent) e;
pos.setVector(m.getTo());
}
}
}
}