entity from wal now have a comparaison operator using uid

This commit is contained in:
arthur.jamet
2021-06-08 08:53:13 +02:00
parent d41670ae40
commit f56a488a7e
7 changed files with 86 additions and 32 deletions

View File

@@ -12,17 +12,20 @@
namespace BBM
{
MenuControllableSystem::MenuControllableSystem(WAL::Wal &wal)
: System(wal), wal(wal)
: System(wal), wal(wal), currentButton()
{}
void MenuControllableSystem::updateButtonIndex(int length)
void MenuControllableSystem::updateCurrentButton()
{
_buttonIndex -= (move.y > 0);
_buttonIndex += (move.y < 0);
if (_buttonIndex < 0)
_buttonIndex = length - 1;
if (_buttonIndex == length)
_buttonIndex = 0;
auto buttonComponent = this->currentButton->getComponent<OnClickComponent>();
if (move.y > 0 && buttonComponent._up)
this->currentButton = buttonComponent._up;
if (move.y < 0 && buttonComponent._down)
this->currentButton = buttonComponent._down;
if (move.x > 0 && buttonComponent._right)
this->currentButton = buttonComponent._right;
if (move.x < 0 && buttonComponent._left)
this->currentButton = buttonComponent._left;
}
@@ -37,19 +40,17 @@ namespace BBM
move = controllable.move;
select = controllable.bomb;
auto &buttons = wal.scene->view<OnClickComponent>();
ssize_t index = 0;
//std::sort(buttons.begin(), buttons.end(),
//[](WAL::Entity &first, WAL::Entity &second) {
// auto &posA = first.getComponent<PositionComponent>();
// auto &posB = second.getComponent<PositionComponent>();
//
// return (posA.position.y < posB.position.y);
//});
updateButtonIndex(buttons.size());
auto &buttons = _wal.scene->view<OnClickComponent>();
if (currentButton == nullptr && buttons.size()) {
currentButton = &static_cast<WAL::Entity &>(buttons.front());
std::cout << currentButton->getName() << std::endl;
std::cout << currentButton->getUid() << std::endl;
printf("%p\n", currentButton);
}
this->updateCurrentButton();
for (auto &button : buttons) {
auto &buttonEntity = static_cast<WAL::Entity &>(button);
if (index++ == _buttonIndex) {
if (buttonEntity == *currentButton) {
buttonEntity.getComponent<OnHoverComponent>().onEvent(button);
if (select)
button.get<OnClickComponent>().onEvent(button);