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

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

public class ComponentView extends Draggable{
    private final Sprite sprite;
    public EditorEntity.Connectiontype connectionType;
    private final PortView portview;

    public ComponentView(EditorEntity parent, EditorEntity.Connectiontype connectionType){
        this.parent = parent;
        this.sprite = new Sprite("GameEngine/resources/ComponentView.png");
        sprite.updateSpriteDimensions();
        portview = new PortView(PortView.PortType.OUT, parent);
        this.connectionType = connectionType;
    }

    @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+92,parent.transform.position.y,parent.transform.position.z);
        portview.update(pos, parent.transform.rotation, parent.transform.scale);
        portview.handleDragging();
    }

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

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