From dff760e0f47d6fabd752a3c2a8029c5dd74a327c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Tue, 21 May 2019 17:29:00 +0300 Subject: [PATCH] =?UTF-8?q?[Foo=20[=5F]]=20=E2=86=92=20[Foo=20=5F]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gameloop.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/gameloop.py b/gameloop.py index 7bf058b..c444619 100644 --- a/gameloop.py +++ b/gameloop.py @@ -809,7 +809,7 @@ def game(send, notice, voice, devoice, get_event): notice(nick, cards) - def combine_cards(call, responses, dereference_backreferences = True): + def combine_cards(call, responses, dereference_responses = True): # This function is really messy, in part due to the format used # # `call` is a list of strings, and here I'll refer to each of @@ -877,7 +877,11 @@ def game(send, notice, voice, devoice, get_event): # # Additionally, we have a special mode in case we are displaying # the round call card, where we do not look up the responses - # pointed to by backreferences, but instead add the $ + # pointed to by backreferences or blanks, but instead add the + # $ or _. In this mode `responses` still has to be correct + # length in order to recognize valid backreferences and to + # distinguish between a blank and end of a card (this could + # admitedly use some work). formatting_state = IRCFormattingState() no_formatting = IRCFormattingState() @@ -899,11 +903,19 @@ def game(send, notice, voice, devoice, get_event): # If there is still one, add the response coming # after that segment if part_index < len(responses): - r.append(to_formatting_state(formatting_state, no_formatting)) - r.append('[') - r.append(sanitize(responses[part_index], no_formatting)) - r.append(']') - r.append(to_formatting_state(no_formatting, formatting_state)) + if dereference_responses: + # Add response + r.append(to_formatting_state(formatting_state, no_formatting)) + r.append('[') + r.append(sanitize(responses[part_index], no_formatting)) + r.append(']') + r.append(to_formatting_state(no_formatting, formatting_state)) + + else: + # Add the blank itself (useful for displaying the call card) + r.append(to_formatting_state(formatting_state, no_formatting)) + r.append('_') + r.append(to_formatting_state(no_formatting, formatting_state)) # Start on a new part as well as a new segment part_index += 1 @@ -928,7 +940,7 @@ def game(send, notice, voice, devoice, get_event): call_segment, formatting_state = handle_control_codes(call_part[segment_start_index:index - 2], formatting_state) r.append(call_segment) - if dereference_backreferences: + if dereference_responses: # Add the response this backreference refers to r.append(to_formatting_state(formatting_state, no_formatting)) r.append('[') @@ -973,7 +985,7 @@ def game(send, notice, voice, devoice, get_event): num_blanks = len(round_call_card.text) - 1 send('Round %i. %s is czar. %s choose your cards' % (round_number, czar.nick, ', '.join(i.nick for i in choosers))) - send('[%s]' % combine_cards(round_call_card.text, ['_'] * num_blanks, dereference_backreferences = False)) + send('[%s]' % combine_cards(round_call_card.text, ['_'] * num_blanks, dereference_responses = False)) # Have bots choose first for bot in bots.values():