Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / entites / editorComponents / EntityView.java
  1. package gameEngine.entites.editorComponents;
  2.  
  3. import gameEngine.entites.EditorEntity;
  4. import gameEngine.views.Sprite;
  5. import gameEngine.views.Window;
  6. import org.joml.Vector3f;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.List;
  10.  
  11. public class EntityView extends Draggable{
  12.  
  13. private Sprite sprite;
  14. private PortView portviewA;
  15. private PortView portviewB;
  16.  
  17. public EntityView(EditorEntity parent){
  18. this.parent = parent;
  19. this.sprite = new Sprite(Window.resourcePath + "EntityView.png");
  20. sprite.updateSpriteDimensions();
  21. portviewA = new PortView(PortView.PortType.IN, parent);
  22. //portviewB = new PortView(PortView.PortType.IN, parent);
  23. }
  24.  
  25. @Override
  26. public EditorComponent copy() {
  27. return this;
  28. }
  29.  
  30. @Override
  31. public void init(){
  32. sprite.update();
  33. sprite.updateSpriteDimensions();
  34. }
  35.  
  36. @Override
  37. public void update() {
  38. sprite.setPosition(parent.transform.position);
  39. sprite.setRotation(parent.transform.rotation);
  40. sprite.setScale(parent.transform.scale);
  41. sprite.update();
  42. Vector3f pos = new Vector3f(parent.transform.position.x-30,parent.transform.position.y+8,parent.transform.position.z);
  43. portviewA.update(pos, parent.transform.rotation, parent.transform.scale);
  44. portviewA.handleDragging();
  45. // pos = new Vector3f(parent.transform.position.x-15,parent.transform.position.y+40,parent.transform.position.z);
  46. // portviewB.update(pos, parent.transform.rotation, parent.transform.scale);
  47. }
  48.  
  49. @Override
  50. protected boolean isMouseOver(float mouseX, float mouseY) {
  51. return sprite.isMouseOver(mouseX, mouseY);
  52. }
  53.  
  54. @Override
  55. protected void leftDraggingAction(float mouseX, float mouseY) {
  56. sprite.setPosition(mouseX - sprite.getDisplayedWidth() / 2,
  57. mouseY - sprite.getDisplayedHeight() / 2);
  58. }
  59.  
  60. @Override
  61. protected void rightDraggingAction(float mouseX, float mouseY) {
  62. float deltaX = mouseX - sprite.getDisplayedWidth() / 2 - sprite.position.x;
  63. float deltaY = mouseY - sprite.getDisplayedHeight() / 2 - sprite.position.y;
  64. sprite.setPosition(mouseX - sprite.getDisplayedWidth() / 2,
  65. mouseY - sprite.getDisplayedHeight() / 2);
  66.  
  67. List<ComponentView> connectedComponents = getConnectedComponentViews();
  68. for (ComponentView component : connectedComponents) {
  69. EditorEntity componentParent = component.parent; // ComponentViewのSprite取得
  70. componentParent.transform.setPosition(componentParent.transform.position.x + deltaX,
  71. componentParent.transform.position.y + deltaY, componentParent.transform.position.z);
  72. }
  73. }
  74.  
  75. public PortView getPortView() {
  76. return portviewA;
  77. }
  78.  
  79. public List<ComponentView> getConnectedComponentViews() {
  80. List<ComponentView> connectedComponentViews = new ArrayList<>();
  81.  
  82. for (PortView connectedPort : portviewA.getConnectedPorts()) {
  83. EditorEntity parentEntity = connectedPort.getParent();
  84.  
  85. if (parentEntity != null) {
  86. for (EditorComponent component : parentEntity.editorComponents) {
  87. if (component instanceof ComponentView) {
  88. connectedComponentViews.add((ComponentView) component);
  89. }
  90. }
  91. }
  92. }
  93. return connectedComponentViews;
  94. }
  95. }