Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / entites / editorComponents / CameraView.java
NoranekoFelician 13 days ago 2 KB ・Editor用のCameraViewを追加
package gameEngine.entites.editorComponents;

import gameEngine.entites.EditorEntity;
import gameEngine.geometry.Transform;
import gameEngine.input.Input;
import gameEngine.input.MouseInput;
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 CameraView extends DraggableComponent {

    private PortView portviewA;
    public Sprite meshSprite;

    public CameraView(EditorEntity parent) {
        this.parent = parent;
        meshSprite = new Sprite(Window.resourcePath + "CameraFrameView.png");
        this.sprite = new Sprite(Window.resourcePath + "CameraView.png");
        this.text = new Text(parent.screenTransform.position.x, parent.screenTransform.position.y, "Camera", 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) {
        if (meshSprite != null) {
            meshSprite.setPosition(new Vector3f(actualPosition.x, actualPosition.y, actualPosition.z));
            meshSprite.setRotation(transform.rotation);
            meshSprite.setScale(transform.scale);
            meshSprite.update();
        }
    }
    @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;
    }
}