Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / ConnectionManager.java
package gameEngine;

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

import gameEngine.entites.Entity;
import gameEngine.entites.GameObject;
import gameEngine.entites.gameComponents.*;
import gameEngine.input.Input;
import gameEngine.input.MouseInput;

public class ConnectionManager {
    private List<Connection> connections = new ArrayList<>();
    private PortView pressedPort;

    public void handlePortPress(PortView port) {
        pressedPort = port;
    }

    public void handlePortRelease(PortView port) {
        if (pressedPort != null && pressedPort != port && pressedPort.getPortType() != port.getPortType()) {
            System.out.println("Connect!");
            Connection newConnection = new Connection(pressedPort, port);
            connections.add(newConnection);

            GameObject entityA = (GameObject) pressedPort.getParent();
            GameObject entityB = (GameObject) port.getParent();
            if(entityA.getComponent(EntityView.class) != null){
                entityA.ComponentConnections.add(entityB.getComponent(ComponentView.class).connectionType);
            }else {
                entityB.ComponentConnections.add(entityA.getComponent(ComponentView.class).connectionType);
            }
        }
        pressedPort = null;
    }

    public void update() {
        for (Connection connection : connections) {
            connection.render();
        }

        if (Input.GetMouseButtonDown(0)) {
            float mouseX = MouseInput.getX();
            float mouseY = MouseInput.getY();

            for (Connection connection : connections) {
                if(connection.isClicked(mouseX, mouseY)) System.out.println("Clicked");
                else System.out.println("o");
            }
        }
    }
}