package gameEngine.entites.editorComponents; import gameEngine.entites.EditorEntity; import gameEngine.geometry.Transform; 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() { Transform transform = parent.transform; sprite.setPosition(transform.position); sprite.setRotation(transform.rotation); sprite.setScale(transform.scale); sprite.update(); Vector3f pos = new Vector3f(transform.position.x-30,transform.position.y+8, transform.position.z); portviewA.update(pos, transform.rotation, transform.scale); portviewA.handleDragging(); } @Override protected boolean isMouseOver(float mouseX, float mouseY) { return sprite.isMouseOver(mouseX, mouseY); } @Override protected void leftDraggingAction(float mouseX, float mouseY) { sprite.setPosition(mouseX - sprite.getDisplayedWidth() / 2, mouseY - sprite.getDisplayedHeight() / 2); } @Override protected void rightDraggingAction(float mouseX, float mouseY) { float deltaX = mouseX - sprite.getDisplayedWidth() / 2 - sprite.position.x; float deltaY = mouseY - sprite.getDisplayedHeight() / 2 - sprite.position.y; sprite.setPosition(mouseX - sprite.getDisplayedWidth() / 2, mouseY - sprite.getDisplayedHeight() / 2); List<ComponentView> connectedComponents = getConnectedComponentViews(); for (ComponentView component : connectedComponents) { EditorEntity componentParent = component.parent; // ComponentViewのSprite取得 componentParent.transform.setPosition(componentParent.transform.position.x + deltaX, componentParent.transform.position.y + deltaY, componentParent.transform.position.z); } } 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; } }