#include "GameObject.hpp"

GameObject::GameObject(std::string name) {
    m_name = name;
}

GameObject::~GameObject() {
    for (int i = 0; i < m_components.size(); i++) {
        delete m_components[i];
    }
}

void GameObject::AddComponent(Component *c) {
    m_components.push_back(c);
}

void GameObject::RemoveComponent(Component *c) {
    for (int i = 0; i < m_components.size(); i++) {
        if (m_components[i] == c) {
            m_components.erase(m_components.begin() + i);
        }
    }
}

void GameObject::Update(SDL_Event e, int frame, std::vector<std::string> broadcastList) {
    for (int i = 0; i < m_components.size(); i++) {
        m_components[i]->Update(e, frame, broadcastList);
    }
}

void GameObject::Render(SDL_Renderer *ren) {
    for (int i = 0; i < m_components.size(); i++) {
        m_components[i]->Render(ren);
    }
}

const std::vector<Component*> GameObject::ListComponents() {
    return m_components;
}

std::string GameObject::GetName(){
    return m_name;
}