<commit_before>//
// Created by zakrent on 7/26/17.
//

#include <vector>
#include <iostream>
#include "../../Program.h"
#include "UiSystem.h"
#include "../message/MouseClickMessage.h"
#include "../component/UiComponent.h"
#include "../component/VisualComponent.h"
#include "../component/PositionComponent.h"
#include "../../misc/collision.h"

namespace Entity {
    UiSystem::UiSystem(EntityManager *entityManager)
            :entityManager(entityManager), selectedEntity(nullptr), hasBeenClicked(false), lastClickX(0), lastClickY(0){}

    void UiSystem::update() {
        if(selectedEntity)
            std::cout<<selectedEntity->getComponent<UiComponent>("Ui")->representedPrefabId<<"\n";
        hasBeenClicked = false;
        std::vector<MouseClickMessage> mouseClickMessages = entityManager->getMessges<MouseClickMessage>(0,"MouseClick");
        if(mouseClickMessages.size()>0)
            if(mouseClickMessages.back().pixY<SCREEN_HEIGHT-24){
                //createEntityAtPixPos
            }else{
                hasBeenClicked = true;
                lastClickX = mouseClickMessages.back().pixX;
                lastClickY = mouseClickMessages.back().pixY;
            }
    }

    void UiSystem::updateEntity(Entity *entity, uint64 updateNumber) {
        UiComponent* uiComponent = entity->getComponent<UiComponent>("Ui");
        if(!uiComponent)
            return;
        VisualComponent* visualComponent = entity->getComponent<VisualComponent>("Visual");
        PositionComponent* positionComponent = entity->getComponent<PositionComponent>("Position");
        if(!visualComponent || !positionComponent)
            return;
        SDL_Rect collider = SDL_Rect{positionComponent->x*visualComponent->srcrect.w, positionComponent->y*visualComponent->srcrect.h,  visualComponent->srcrect.w, visualComponent->srcrect.h};
        if(Collision::pointBoxCollision(lastClickX, lastClickY, collider)&&hasBeenClicked){
            selectedEntity = entity;
        }
    }
}<commit_msg>Added spawning at pixPos<commit_after>//
// Created by zakrent on 7/26/17.
//

#include <vector>
#include <iostream>
#include "../../Program.h"
#include "UiSystem.h"
#include "../message/MouseClickMessage.h"
#include "../component/UiComponent.h"
#include "../component/VisualComponent.h"
#include "../component/PositionComponent.h"
#include "../../misc/collision.h"

namespace Entity {
    UiSystem::UiSystem(EntityManager *entityManager)
            :entityManager(entityManager), selectedEntity(nullptr), hasBeenClicked(false), lastClickX(0), lastClickY(0){}

    void UiSystem::update() {
        if(selectedEntity)
            std::cout<<selectedEntity->getComponent<UiComponent>("Ui")->representedPrefabId<<"\n";
        hasBeenClicked = false;
        std::vector<MouseClickMessage> mouseClickMessages = entityManager->getMessges<MouseClickMessage>(0,"MouseClick");
        if(mouseClickMessages.size()>0)
            if(mouseClickMessages.back().pixY<SCREEN_HEIGHT-24){
                entityManager->spawnPrefab(
                        selectedEntity->getComponent<UiComponent>("Ui")->representedPrefabId,
                        int(mouseClickMessages.back().pixX/(24/0.75)),
                        int(mouseClickMessages.back().pixY/(24/0.75))
                );
            }else{
                hasBeenClicked = true;
                lastClickX = mouseClickMessages.back().pixX;
                lastClickY = mouseClickMessages.back().pixY;
            }
    }

    void UiSystem::updateEntity(Entity *entity, uint64 updateNumber) {
        UiComponent* uiComponent = entity->getComponent<UiComponent>("Ui");
        if(!uiComponent)
            return;
        VisualComponent* visualComponent = entity->getComponent<VisualComponent>("Visual");
        PositionComponent* positionComponent = entity->getComponent<PositionComponent>("Position");
        if(!visualComponent || !positionComponent)
            return;
        SDL_Rect collider = SDL_Rect{positionComponent->x*visualComponent->srcrect.w, positionComponent->y*visualComponent->srcrect.h,  visualComponent->srcrect.w, visualComponent->srcrect.h};
        if(Collision::pointBoxCollision(lastClickX, lastClickY, collider)&&hasBeenClicked){
            selectedEntity = entity;
        }
    }
}
{'fraction_non_alphanumeric': 0.13466042154566746, 'fraction_numerical': 0.008430913348946136, 'mean_word_length': 3.1996066863323502, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 49, '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': '2738208', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1163, 'n_words': 170}