<commit_before>#include "Transform.hpp"

Transform::_addToComponentsCreator Transform::_componentsCreatorAdder;

Transform* Transform::clone() const {
    return new Transform(*this);
}

void Transform::serialize(json& jsonData) const {
    jsonData["position"]["x"] = getPosition().x;
    jsonData["position"]["y"] = getPosition().y;

    jsonData["scale"]["x"] = getScale().x;
    jsonData["scale"]["y"] = getScale().y;

    jsonData["rotation"] = getRotation();
}

void Transform::deserialize(const json& jsonData) {
    setPosition(sf::Vector2f(jsonData["position"]["x"],
                             jsonData["position"]["y"]));

    setScale(sf::Vector2f(jsonData["scale"]["x"],
                          jsonData["scale"]["y"]));

    setRotation(jsonData["rotation"]);
}

void Transform::update(float deltaTime) {
    if (entity->getParent() == nullptr) {
        if (toBeUpdated) {
            globalTransform = localTransform;
        }
    } else {
        Transform* parentTransform = &entity->getParent()->getComponent<Transform>();

        if (toBeUpdated |= parentTransform->toBeUpdated) {
            globalTransform = parentTransform->globalTransform;
            const_cast<sf::Transform&>(globalTransform.getTransform()).combine(localTransform.getTransform());

            parentTransform->toBeUpdated = false;
            if (entity->getEntities().size() == 0) {
                toBeUpdated = false; //No more children to change transform, so set flag to false
            }

            if (entity->hasComponent<Sprite>())
                entity->sendMessage<Sprite>("transform changed", globalTransform);
        }
    }
}

void Transform::move(const sf::Vector2f& offset) {
    localTransform.move(offset);
    toBeUpdated = true;
}

void Transform::scale(const sf::Vector2f& factors) {
    localTransform.scale(factors);
    toBeUpdated = true;
}

void Transform::rotate(float angle) {
    localTransform.rotate(angle);
    toBeUpdated = true;
}

void Transform::setPosition(const sf::Vector2f& position) {
    localTransform.setPosition(position);
    toBeUpdated = true;<commit_msg>Add updating transformable, not only transform<commit_after>#include "Transform.hpp"

Transform::_addToComponentsCreator Transform::_componentsCreatorAdder;

Transform* Transform::clone() const {
    return new Transform(*this);
}

void Transform::serialize(json& jsonData) const {
    jsonData["position"]["x"] = getPosition().x;
    jsonData["position"]["y"] = getPosition().y;

    jsonData["scale"]["x"] = getScale().x;
    jsonData["scale"]["y"] = getScale().y;

    jsonData["rotation"] = getRotation();
}

void Transform::deserialize(const json& jsonData) {
    setPosition(sf::Vector2f(jsonData["position"]["x"],
                             jsonData["position"]["y"]));

    setScale(sf::Vector2f(jsonData["scale"]["x"],
                          jsonData["scale"]["y"]));

    setRotation(jsonData["rotation"]);
}

void Transform::update(float deltaTime) {
    if (entity->getParent() == nullptr) {
        if (toBeUpdated) {
            globalTransform = localTransform;
        }
    } else {
        Transform* parentTransform = &entity->getParent()->getComponent<Transform>();

        if (toBeUpdated |= parentTransform->toBeUpdated) {
            globalTransform = parentTransform->globalTransform;

            globalTransform.move(localTransform.getPosition());
            globalTransform.rotate(localTransform.getRotation());
            globalTransform.scale(localTransform.getScale());

            parentTransform->toBeUpdated = false;
            if (entity->getEntities().size() == 0) {
                toBeUpdated = false; //No more children to change transform, so set flag to false
            }

            if (entity->hasComponent<Sprite>())
                entity->sendMessage<Sprite>("transform changed", globalTransform);
        }
    }
}

void Transform::move(const sf::Vector2f& offset) {
    localTransform.move(offset);
    toBeUpdated = true;
}

void Transform::scale(const sf::Vector2f& factors) {
    localTransform.scale(factors);
    toBeUpdated = true;
}

void Transform::rotate(float angle) {
    localTransform.rotate(angle);
    toBeUpdated = true;
}

void Transform::setPosition(const sf::Vector2f& position) {
    localTransform.setPosition(position);
    toBeUpdated = true;
{'fraction_non_alphanumeric': 0.14648212226066898, 'fraction_numerical': 0.002768166089965398, 'mean_word_length': 3.3975659229208923, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3721921', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1183, 'n_words': 212}