Skip to content

Commit

Permalink
!swap - Seating Guests can change seats
Browse files Browse the repository at this point in the history
  • Loading branch information
FlavioFS committed Feb 27, 2023
1 parent 1756d4b commit a9aeb61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 19 additions & 10 deletions ParsecSoda/HotseatManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,29 @@ void HotseatManager::decrementDesiredSeat(size_t guestIndex)
m_waitingGuests[guestIndex].desiredSeatIndex = seatIndex;
}

int HotseatManager::setDesiredSeat(uint32_t userID, int seatIndex)
int HotseatManager::setDesiredSeat(uint32_t userID, int desiredSeatIndex)
{
int result = -1;

findGuestIndex(userID, [&](size_t index) {
if (isSeatIndexInRange(seatIndex) || seatIndex == HotseatGuest::ANY_SEAT)
{
result = seatIndex;
}
else
if (isSeatIndexInRange(desiredSeatIndex) || desiredSeatIndex == HotseatGuest::ANY_SEAT)
{
result = desiredSeatIndex;
}
else
{
result = HotseatGuest::ANY_SEAT;
}

findGuestIndex(userID, [&](size_t guestIndex) {
m_waitingGuests[guestIndex].desiredSeatIndex = result;
});

findSeatByGuest(userID, [&](Hotseat& seat, int currentSeatIndex) {
if (desiredSeatIndex != currentSeatIndex && desiredSeatIndex != HotseatGuest::ANY_SEAT)
{
result = HotseatGuest::ANY_SEAT;
seat.guest.desiredSeatIndex = result;
reverse(currentSeatIndex);
}

m_waitingGuests[index].desiredSeatIndex = result;
});

return result;
Expand Down Expand Up @@ -180,6 +188,7 @@ void HotseatManager::reverse(const uint32_t seatIndex)
if (!isSeatIndexInRange(seatIndex)) return;

m_waitingGuests.insert(m_waitingGuests.begin(), m_seats[seatIndex].guest);
spectateSeat(seatIndex);
}

void HotseatManager::setTimer(const uint32_t duration)
Expand Down
2 changes: 1 addition & 1 deletion ParsecSoda/HotseatManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class HotseatManager
void incrementDesiredSeat(size_t guestIndex);
void decrementDesiredSeatByUserID(uint32_t userID);
void decrementDesiredSeat(size_t guestIndex);
int setDesiredSeat(uint32_t userID, int seatIndex);
int setDesiredSeat(uint32_t userID, int seatIndex);

/**
* Turn target into spectator (remove guest from queue).
Expand Down

0 comments on commit a9aeb61

Please sign in to comment.