diff --git a/gameloop.py b/gameloop.py index 0abcb95..9cd3bcc 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): + def combine_cards(call, responses, dereference_backreferences = 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 @@ -874,6 +874,10 @@ def game(send, notice, voice, devoice, get_event): # 2. Add the response pointed to by the # backreference # 2. Repeat + # + # 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 $ formatting_state = IRCFormattingState() no_formatting = IRCFormattingState() @@ -922,14 +926,21 @@ def game(send, notice, voice, devoice, get_event): if 0 <= backreference_index < len(responses): # Copy the previous segment fully to `r` call_segment, formatting_state = handle_control_codes(call_part[segment_start_index:index - 2], formatting_state) - - # Add the response this backreference refers to r.append(call_segment) - r.append(to_formatting_state(formatting_state, no_formatting)) - r.append('[') - r.append(sanitize(responses[backreference_index], no_formatting)) - r.append(']') - r.append(to_formatting_state(no_formatting, formatting_state)) + + if dereference_backreferences: + # Add the response this backreference refers to + r.append(to_formatting_state(formatting_state, no_formatting)) + r.append('[') + r.append(sanitize(responses[backreference_index], no_formatting)) + r.append(']') + r.append(to_formatting_state(no_formatting, formatting_state)) + + else: + # Add the backreference itself (useful for displaying the call card) + r.append(to_formatting_state(formatting_state, no_formatting)) + r.append('$%i' % backreference_index) + r.append(to_formatting_state(no_formatting, formatting_state)) # Start new segment after this char segment_start_index = index @@ -962,7 +973,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)) + send('[%s]' % combine_cards(round_call_card.text, ['_'] * num_blanks, dereference_backreferences = False)) # Have bots choose first for bot in bots.values():