Skip to content

Commit 461fb81

Browse files
WisoAltredTrickyLeifastonedDiscord
authored
Chat tick pause multiplier fix + denotes ms instead of multiplier (#1110)
* 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. * Format format * format 2 format 2 * numbers denote ms instead of multiplier also removes unnecessary variables, as well as adds validation fix for commit so it doesn't ruin history * Simpler parse function now defaults to 1s on \p with no numbers Co-Authored-By: Leifa <26681464+TrickyLeifa@users.noreply.github.com> * Change validation from bool check to std optional the voices will tell you this is more "idiomatic" and "readable" * doesnt need to be explicit * Don't need max int anymore. --------- Co-authored-by: Leifa <26681464+TrickyLeifa@users.noreply.github.com> Co-authored-by: stonedDiscord <Tukz@gmx.de>
1 parent 1176bb5 commit 461fb81

1 file changed

Lines changed: 37 additions & 5 deletions

File tree

src/courtroom.cpp

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,6 +3506,29 @@ void Courtroom::handle_ic_speaking()
35063506
start_chat_ticking();
35073507
}
35083508

3509+
struct PauseInfo
3510+
{
3511+
int ms;
3512+
int digit_count;
3513+
};
3514+
3515+
static std::optional<PauseInfo> parse_pause_duration(const QString &text, int start_pos)
3516+
{
3517+
int pos = start_pos;
3518+
while (pos < text.length() && text[pos].isDigit())
3519+
{
3520+
pos++;
3521+
}
3522+
3523+
if (pos == start_pos)
3524+
{
3525+
return PauseInfo{1000, 0};
3526+
}
3527+
3528+
int value = qMin(10000, text.mid(start_pos, pos - start_pos).toInt());
3529+
return std::optional<PauseInfo>{PauseInfo{value, pos - start_pos}};
3530+
}
3531+
35093532
QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos, int default_color)
35103533
{
35113534
QString p_text_escaped;
@@ -3723,6 +3746,13 @@ QString Courtroom::filter_ic_text(QString p_text, bool html, int target_pos, int
37233746
if (f_character == "s" || f_character == "f" || f_character == "p") // screenshake/flash/pause
37243747
{
37253748
skip = true;
3749+
if (f_character == "p") // also skip any following digits
3750+
{
3751+
if (auto info = parse_pause_duration(p_text, check_pos + f_char_bytes))
3752+
{
3753+
check_pos += info->digit_count;
3754+
}
3755+
}
37263756
}
37273757

37283758
parse_escape_seq = false;
@@ -4420,6 +4450,13 @@ void Courtroom::chat_tick()
44204450
if (f_character == "p")
44214451
{
44224452
formatting_char = true;
4453+
if (auto info = parse_pause_duration(f_message, tick_pos))
4454+
{
4455+
tick_pos += info->digit_count;
4456+
real_tick_pos += f_char_length;
4457+
chat_tick_timer->start(info->ms);
4458+
return;
4459+
}
44234460
}
44244461
next_character_is_not_special = false;
44254462
}
@@ -4441,11 +4478,6 @@ void Courtroom::chat_tick()
44414478

44424479
if ((msg_delay <= 0 && tick_pos < f_message.size() - 1) || formatting_char)
44434480
{
4444-
if (f_character == "p")
4445-
{
4446-
chat_tick_timer->start(100); // wait the pause lol
4447-
}
4448-
else
44494481
{
44504482
chat_tick_timer->start(0); // Don't bother rendering anything out as we're
44514483
// doing the SPEED. (there's latency otherwise)

0 commit comments

Comments
 (0)