TazGraph Project v0.1.0
Loading...
Searching...
No Matches
PortSlotComponent.h
1#pragma once
2
3#include "../../../Components.h"
4
5// todo this can be generally in flexbox
7{
8public:
9 int index = -1;
10
11 TransformComponent* transform = nullptr;
12
14 {
15
16 }
17
19
20 }
21
22 void init() override {
23 transform = &entity->GetComponent<TransformComponent>();
24 }
25
26 void update(float deltaTime) override {
27 Entity* parentEntity = entity->getParentEntity();
28 if (!parentEntity) {
29 return;
30 }
31
32 // Find our index in the parent's portSlots vector
33 if (index == -1) {
34 return;
35 }
36
37 // Calculate and set our position
38 glm::vec3 newPosition = getSlotPosition();
39 transform->local_position = newPosition;
40 }
41
42 glm::vec3 getSlotPosition() const {
43 size_t childrenSize = entity->getParentEntity()->children.size();
44 if (index >= childrenSize) {
45 //TAZ_ERROR("Port Slot index wrong");
46 return entity->getParentEntity()->
47 GetComponent<TransformComponent>().getPosition();
48 }
49
50 glm::vec3 offset(0.0f);
51
52 if (!entity->getParentEntity()->isVertical) {
53 offset.x = (static_cast<float>(index) - (childrenSize - 1) / 2.0f) * entity->getParentEntity()->slotSpacing;
54 }
55 else { // Vertical
56 offset.y = (static_cast<float>(index) - (childrenSize - 1) / 2.0f) * entity->getParentEntity()->slotSpacing;
57 }
58
59 return offset;
60 }
61
62 void draw(size_t v_index, PlaneColorRenderer& batch, TazGraphEngine::Window& window) {
63
64 }
65
66 std::string GetComponentName() override {
67 return "PortSlotComponent";
68 }
69
70 void showGUI(std::vector<BaseComponent*> otherComponents = {}) override {
71 ImGui::Separator();
72 }
73
74 void showGUI(std::vector<BaseComponent*> otherComponents, std::vector<Entity*> otherEntities) override {
75 ImGui::Separator();
76 }
77
78};
Definition GECS.h:131
Definition GECS.h:224
std::map< EntityID, EntityID > children
child_index(id) -> real_entity_id
Definition GECS.h:248
Definition PlaneColorRenderer.h:14
Definition PortSlotComponent.h:7
Definition Window.h:12
Definition TransformComponent.h:7