Skip to content

Commit 7b1be28

Browse files
committed
Change pause special character behavior (\p) to allow multiplications instead of having to spam it.
Adds a parser to any numbers after a detected \p for pause chat message, matches it upto a given max to be multiplied to a given base const. (The regex will limit this to 1000 regardless, but the const is hard-coded either way.). ordered them according to the pattern in courtroom.h but it would be nicer if they were not separated. Also skips by the given amount of characters by calculating it via the text pos, so \p20 would skip 4, \p200 would skip 5, etc. Currently technically silently fails if the user tries doing -1 or \p50000 or so, so it spits out any numbers beyond the initial 4 digits to at least indicate that.
1 parent 54afcee commit 7b1be28

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/courtroom.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3506,6 +3506,31 @@ void Courtroom::handle_ic_speaking()
35063506
start_chat_ticking();
35073507
}
35083508

3509+
struct PauseInfo
3510+
{
3511+
int multiplier;
3512+
int digit_count;
3513+
};
3514+
3515+
3516+
// returns multiplier and number of digits to skip
3517+
static PauseInfo parse_pause_multiplier(const QString &text, int start_pos)
3518+
{
3519+
3520+
// matches upto 999 (and 1000) and also prevents leading zeros
3521+
static QRegularExpression pause_regex("^([1-9]\\d{0,2}|1000)");
3522+
QRegularExpressionMatch match = pause_regex.match(text.mid(start_pos));
3523+
3524+
if (match.hasMatch())
3525+
{
3526+
int value = match.captured(1).toInt();
3527+
int length = match.capturedLength(0);
3528+
return {value, length};
3529+
}
3530+
3531+
return {1, 0}; // default: multiplier=1, no digits to skip
3532+
}
3533+
35093534
QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos, int default_color)
35103535
{
35113536
QString p_text_escaped;
@@ -3723,6 +3748,12 @@ QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos, int
37233748
if (f_character == "s" || f_character == "f" || f_character == "p") // screenshake/flash/pause
37243749
{
37253750
skip = true;
3751+
// also skip any following digits
3752+
if (f_character == "p")
3753+
{
3754+
PauseInfo info = parse_pause_multiplier(p_text, check_pos + f_char_bytes);
3755+
check_pos += info.digit_count;
3756+
}
37263757
}
37273758

37283759
parse_escape_seq = false;
@@ -4201,6 +4232,7 @@ void Courtroom::start_chat_ticking()
42014232

42024233
tick_pos = 0;
42034234
blip_ticker = 0;
4235+
pause_multiplier = 1;
42044236
text_crawl = Options::getInstance().textCrawlSpeed();
42054237
blip_rate = Options::getInstance().blipRate();
42064238
blank_blip = Options::getInstance().blankBlip();
@@ -4420,6 +4452,9 @@ void Courtroom::chat_tick()
44204452
if (f_character == "p")
44214453
{
44224454
formatting_char = true;
4455+
PauseInfo info = parse_pause_multiplier(f_message, tick_pos);
4456+
pause_multiplier = info.multiplier;
4457+
tick_pos += info.digit_count;
44234458
}
44244459
next_character_is_not_special = false;
44254460
}
@@ -4443,7 +4478,7 @@ void Courtroom::chat_tick()
44434478
{
44444479
if (f_character == "p")
44454480
{
4446-
chat_tick_timer->start(100); // wait the pause lol
4481+
chat_tick_timer->start(pause_base_ms * pause_multiplier);
44474482
}
44484483
else
44494484
{

src/courtroom.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ class Courtroom : public QMainWindow
378378
int real_tick_pos = 0;
379379
// used to determine how often blips sound
380380
int blip_ticker = 0;
381+
// pause multiplier for \p{numbers}
382+
int pause_multiplier = 1;
381383
int blip_rate = 2;
382384
int rainbow_counter = 0;
383385
bool rainbow_appended = false;
@@ -450,6 +452,11 @@ class Courtroom : public QMainWindow
450452
// amount by which we multiply the delay when we parse punctuation chars
451453
const int punctuation_modifier = 3;
452454

455+
// maximum pause multiplier for \p{numbers} so it does not just pause forever
456+
const int pause_multiplier_max = 1000;
457+
// base pause duration for a \p with no digits
458+
const int pause_base_ms = 100;
459+
453460
// amount of ghost blocks
454461
int ghost_blocks = 0;
455462

0 commit comments

Comments
 (0)