Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / entites / editorComponents / EntityView.java
NoranekoFelician 14 days ago 1 KB ・DraggableをDraggableComponentに変更
package gameEngine.entites.editorComponents;

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

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

public class EntityView extends DraggableComponent {

    private PortView portviewA;

    public EntityView(EditorEntity parent) {
        this.parent = parent;
        this.sprite = new Sprite(Window.resourcePath + "EntityView.png");
        this.text = new Text(parent.screenTransform.position.x, parent.screenTransform.position.y, "Entity", 14);
        sprite.updateSpriteDimensions();
        portviewA = new PortView(PortView.PortType.IN, parent);
    }

    @Override
    protected void updatePortView(Vector3f actualPosition, Transform transform) {
        Vector3f adjustedPos = new Vector3f(actualPosition.x - 30, actualPosition.y + 8, actualPosition.z);
        portviewA.update(adjustedPos, transform.rotation, transform.scale);
        portviewA.handleDragging();
    }

    @Override
    protected void additionalUpdate(Vector3f actualPosition, Transform transform, Vector3f cameraPosition) {
    }

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

    @Override
    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;
    }
}