refactor + statemento jump fixgger
This commit is contained in:
parent
5219410dc1
commit
07a9f7b565
@ -20,6 +20,29 @@ PacketInfo PacketMS::getPacketInfo() const
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList handleStatementJump(AOClient& client, AreaData* area, const QString& client_name, int statementIndex, const QString& actionMessage, const QString& edgeCaseMessage = "", AreaData::TestimonyProgress edgeCaseProgress = AreaData::TestimonyProgress::OK, bool broadcast = true) {
|
||||||
|
auto l_statement = area->jumpToStatement(statementIndex);
|
||||||
|
auto& l_args = l_statement.first;
|
||||||
|
auto& l_progress = l_statement.second;
|
||||||
|
|
||||||
|
client.m_pos = l_args[5];
|
||||||
|
|
||||||
|
if (broadcast) {
|
||||||
|
client.sendServerMessageArea(client_name + " " + actionMessage);
|
||||||
|
} else {
|
||||||
|
client.sendServerMessage(client_name + " " + actionMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!edgeCaseMessage.isEmpty() && l_progress == edgeCaseProgress) {
|
||||||
|
if (broadcast)
|
||||||
|
client.sendServerMessageArea(edgeCaseMessage);
|
||||||
|
else
|
||||||
|
client.sendServerMessage(edgeCaseMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return l_args;
|
||||||
|
}
|
||||||
|
|
||||||
void PacketMS::handlePacket(AreaData *area, AOClient &client) const
|
void PacketMS::handlePacket(AreaData *area, AOClient &client) const
|
||||||
{
|
{
|
||||||
if (client.m_is_muted) {
|
if (client.m_is_muted) {
|
||||||
@ -464,65 +487,21 @@ AOPacket *PacketMS::validateIcPacket(AOClient &client) const
|
|||||||
l_args = client.updateStatement(l_args);
|
l_args = client.updateStatement(l_args);
|
||||||
}
|
}
|
||||||
else if (area->testimonyRecording() == AreaData::TestimonyRecording::PLAYBACK) {
|
else if (area->testimonyRecording() == AreaData::TestimonyRecording::PLAYBACK) {
|
||||||
AreaData::TestimonyProgress l_progress;
|
|
||||||
|
|
||||||
if (l_args[4] == ">") {
|
if (l_args[4] == ">") {
|
||||||
auto l_statement = area->jumpToStatement(area->statement() + 1);
|
l_args = handleStatementJump(client, area, client_name, area->statement() + 1, "moved to the next statement.", "Last statement reached. Looping to first statement.", AreaData::TestimonyProgress::LOOPED);
|
||||||
l_args = l_statement.first;
|
|
||||||
l_progress = l_statement.second;
|
|
||||||
client.m_pos = l_args[5];
|
|
||||||
|
|
||||||
client.sendServerMessageArea(client_name + " moved to the next statement.");
|
|
||||||
|
|
||||||
if (l_progress == AreaData::TestimonyProgress::LOOPED) {
|
|
||||||
client.sendServerMessageArea("Last statement reached. Looping to first statement.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (l_args[4] == "<") {
|
else if (l_args[4] == "<") {
|
||||||
auto l_statement = area->jumpToStatement(area->statement() - 1);
|
l_args = handleStatementJump(client, area, client_name, area->statement() - 1, "moved to the previous statement.", "First statement reached.", AreaData::TestimonyProgress::STAYED_AT_FIRST, false);
|
||||||
l_args = l_statement.first;
|
|
||||||
l_progress = l_statement.second;
|
|
||||||
client.m_pos = l_args[5];
|
|
||||||
|
|
||||||
client.sendServerMessageArea(client_name + " moved to the previous statement.");
|
|
||||||
|
|
||||||
if (l_progress == AreaData::TestimonyProgress::STAYED_AT_FIRST) {
|
|
||||||
client.sendServerMessage("First statement reached.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (l_args[4] == "=") {
|
else if (l_args[4] == "=") {
|
||||||
auto l_statement = area->jumpToStatement(area->statement());
|
l_args = handleStatementJump(client, area, client_name, area->statement(), "repeated the current statement.");
|
||||||
l_args = l_statement.first;
|
|
||||||
l_progress = l_statement.second;
|
|
||||||
client.m_pos = l_args[5];
|
|
||||||
|
|
||||||
client.sendServerMessageArea(client_name + " repeated the current statement.");
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
QRegularExpressionMatch match = isTestimonyJumpCommand(client.decodeMessage(l_args[4])); // Get rid of that pesky encoding, then do the fun part
|
QRegularExpressionMatch match = isTestimonyJumpCommand(l_args[4]);
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
int jump_idx = match.captured("int").toInt();
|
int jump_idx = match.captured("int").toInt();
|
||||||
auto l_statement = area->jumpToStatement(jump_idx);
|
l_args = handleStatementJump(client, area, client_name, jump_idx, "jumped to statement number " + QString::number(jump_idx) + ".");
|
||||||
l_args = l_statement.first;
|
|
||||||
l_progress = l_statement.second;
|
|
||||||
|
|
||||||
client.sendServerMessageArea(client_name + " jumped to statement number " + QString::number(jump_idx) + ".");
|
|
||||||
|
|
||||||
switch (l_progress) {
|
|
||||||
case AreaData::TestimonyProgress::LOOPED:
|
|
||||||
{
|
|
||||||
client.sendServerMessageArea("Last statement reached. Looping to first statement.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case AreaData::TestimonyProgress::STAYED_AT_FIRST:
|
|
||||||
{
|
|
||||||
client.sendServerMessage("First statement reached.");
|
|
||||||
Q_FALLTHROUGH();
|
|
||||||
}
|
|
||||||
case AreaData::TestimonyProgress::OK:
|
|
||||||
default:
|
|
||||||
// No need to handle.
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -541,4 +520,4 @@ QRegularExpressionMatch PacketMS::isTestimonyJumpCommand(QString message) const
|
|||||||
// get well soon
|
// get well soon
|
||||||
QRegularExpression jump("(?<arrow>>|<)(?<int>\\d+)");
|
QRegularExpression jump("(?<arrow>>|<)(?<int>\\d+)");
|
||||||
return jump.match(message);
|
return jump.match(message);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user