forked from nortti/tea_cah
Display $0 correctly in round call card
This commit is contained in:
parent
0959b2c82f
commit
0774f5478a
29
gameloop.py
29
gameloop.py
|
@ -809,7 +809,7 @@ def game(send, notice, voice, devoice, get_event):
|
||||||
|
|
||||||
notice(nick, cards)
|
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
|
# 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
|
# `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
|
# 2. Add the response pointed to by the
|
||||||
# backreference
|
# backreference
|
||||||
# 2. Repeat
|
# 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 $<num>
|
||||||
|
|
||||||
formatting_state = IRCFormattingState()
|
formatting_state = IRCFormattingState()
|
||||||
no_formatting = IRCFormattingState()
|
no_formatting = IRCFormattingState()
|
||||||
|
@ -922,14 +926,21 @@ def game(send, notice, voice, devoice, get_event):
|
||||||
if 0 <= backreference_index < len(responses):
|
if 0 <= backreference_index < len(responses):
|
||||||
# Copy the previous segment fully to `r`
|
# Copy the previous segment fully to `r`
|
||||||
call_segment, formatting_state = handle_control_codes(call_part[segment_start_index:index - 2], formatting_state)
|
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(call_segment)
|
||||||
r.append(to_formatting_state(formatting_state, no_formatting))
|
|
||||||
r.append('[')
|
if dereference_backreferences:
|
||||||
r.append(sanitize(responses[backreference_index], no_formatting))
|
# Add the response this backreference refers to
|
||||||
r.append(']')
|
r.append(to_formatting_state(formatting_state, no_formatting))
|
||||||
r.append(to_formatting_state(no_formatting, formatting_state))
|
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
|
# Start new segment after this char
|
||||||
segment_start_index = index
|
segment_start_index = index
|
||||||
|
@ -962,7 +973,7 @@ def game(send, notice, voice, devoice, get_event):
|
||||||
num_blanks = len(round_call_card.text) - 1
|
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('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
|
# Have bots choose first
|
||||||
for bot in bots.values():
|
for bot in bots.values():
|
||||||
|
|
Loading…
Reference in New Issue