Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / entites / editorComponents / EntityView.java
package gameEngine.entites.editorComponents;

import gameEngine.entites.EditorEntity;
import gameEngine.views.Sprite;
import gameEngine.views.Window;
import org.joml.Vector3f;

import java.util.ArrayList;
import java.util.List;

public class EntityView extends Draggable{

    private Sprite sprite;
    private PortView portviewA;
    private PortView portviewB;

    public EntityView(EditorEntity parent){
        this.parent = parent;
        this.sprite = new Sprite(Window.resourcePath + "EntityView.png");
        sprite.updateSpriteDimensions();
        portviewA = new PortView(PortView.PortType.IN, parent);
        portviewB = new PortView(PortView.PortType.IN, parent);
    }

    @Override
    public EditorComponent copy() {
        return this;
    }

    @Override
    public void init(){
        sprite.update();
        sprite.updateSpriteDimensions();
    }

    @Override
    public void update() {
        sprite.setPosition(parent.transform.position);
        sprite.setRotation(parent.transform.rotation);
        sprite.setScale(parent.transform.scale);
        sprite.update();
        Vector3f pos = new Vector3f(parent.transform.position.x-30,parent.transform.position.y+8,parent.transform.position.z);
        portviewA.update(pos, parent.transform.rotation, parent.transform.scale);
        portviewA.handleDragging();
//        pos = new Vector3f(parent.transform.position.x-15,parent.transform.position.y+40,parent.transform.position.z);
//        portviewB.update(pos, parent.transform.rotation, parent.transform.scale);
    }

    @Override
    protected boolean isMouseOver(float mouseX, float mouseY) {
        return sprite.isMouseOver(mouseX, mouseY);
    }

    @Override
    protected void draggingAction(float mouseX, float mouseY) {
        sprite.setPosition(mouseX - sprite.getDisplayedWidth() / 2,
                mouseY - sprite.getDisplayedHeight() / 2);
    }

    public PortView getPortView() {
        return portviewA;
    }

    public List<ComponentView> getConnectedComponentViews() {
        List<ComponentView> connectedComponentViews = new ArrayList<>();

        for (PortView connectedPort : portviewA.getConnectedPorts()) {
            EditorEntity parentEntity = connectedPort.getParent();

            if (parentEntity != null) {
                for (EditorComponent component : parentEntity.editorComponents) {
                    if (component instanceof ComponentView) {
                        connectedComponentViews.add((ComponentView) component);
                    }
                }
            }
        }
        return connectedComponentViews;
    }
}