diff options
| author | yum <yum.food.vr@gmail.com> | 2022-11-26 17:08:09 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2022-11-26 17:13:36 -0800 |
| commit | 480463b0578407a8f5a6585eb7018933e6ec7186 (patch) | |
| tree | 2a11d8298aaca6169581008f225f7fcbcc70bae8 /osc_ctrl.py | |
| parent | 89a929fe76e4dbd56436288055366d9416c13e74 (diff) | |
Add emotes
Add emotes.py. It accepts a list of images and creates a texture with 64 total
embedded images.
The shader knows how to draw these into fixed 6-character-wide slots. Each slot
must be aligned to a 6-character boundary. osc_ctrl has to pad with spaces
to make this work.
This whole patch is a little more complicated than it has any right to be, but
my brain feels fuzzy and I don't know where to start fixing it, so I'm going to
leave it shitty-but-functional for now.
There's also some bug where writing a character into the 11th slot causes it to
show up at the end of the board. I'll figure that out later, idk.
I didn't include any of the emotes I use since I couldn't find any info on
their licenses. I'm just banking on having a good workflow later on so
people can add their own.
Diffstat (limited to 'osc_ctrl.py')
| -rw-r--r-- | osc_ctrl.py | 58 |
1 files changed, 46 insertions, 12 deletions
diff --git a/osc_ctrl.py b/osc_ctrl.py index 46c7997..34d1a36 100644 --- a/osc_ctrl.py +++ b/osc_ctrl.py @@ -20,6 +20,8 @@ from generate_utils import NUM_LAYERS from generate_utils import BOARD_ROWS from generate_utils import BOARD_COLS +import emotes + # Based on a couple experiments, this seems like about as fast as we can go # before players start losing events. SYNC_FREQ_HZ = 5.0 @@ -53,12 +55,33 @@ def encodeMessage(lines): result = [] lines_tmp = lines + [" "] * ((BOARD_ROWS - len(lines)) % BOARD_ROWS) for line in lines_tmp: - #print("encode line {}".format(line)) - for char in line: - if not char in state.encoding: - print("skip unrecognized char {}".format(char)) + first_word = True + for word in line.split(): + if first_word: + first_word = False + else: + result.append(state.encoding[' ']) + + emote_word, emote_word_idx = emotes.lookup(word) + if emote_word: + + word_align = 0 + if len(result) > 0: + word_align = (6 - len(result) % 6) % 6 + word = ' ' * word_align + word + + for i in range(0, word_align): + result.append(state.encoding[' ']) + + for i in range(0, 6): + result.append((emote_word_idx, 0xE0)) continue - result.append(state.encoding[char]) + + for char in word: + if not char in state.encoding: + print("skip unrecognized char {}".format(char)) + continue + result.append(state.encoding[char]) result += [state.encoding[' ']] * (BOARD_COLS - len(line)) return result @@ -77,7 +100,7 @@ def disable(client): client.send_message(addr, False) # Send a cell all at once. -# `which_cell` is an integer in the range [0,2**INDEX_BITS). +# `which_cell` is an integer in the range [0,NUM_REGIONS) def sendMessageCellDiscrete(client, msg_cell, which_cell): empty_cell = [state.encoding[' ']] * NUM_LAYERS @@ -86,7 +109,7 @@ def sendMessageCellDiscrete(client, msg_cell, which_cell): client.send_message(addr, True) # Really long messages just wrap back around. - which_cell = (which_cell % (2 ** generate_utils.INDEX_BITS)) + which_cell = (which_cell % generate_utils.NUM_REGIONS) enable(client) @@ -113,10 +136,26 @@ def splitMessage(msg): lines = [] line = "" for word in msg.split(): + # Hack: if the word is an emote, we make it 6 characters wide, then + # encode it differently later on. + emote_word, emote_word_idx = emotes.lookup(word) + if emote_word: + word = word.ljust(6) + # Due to some fuckery I do in the shader, emotes have to be rendered on + # a 6-character boundary. So pad the word on the left with spaces + # to get it onto that boundary. + word_align = 0 + if len(line) > 0: + word_align = (6 - (len(line) + 1) % 6) % 6 + print("len line: {}".format(len(line))) + print("word align: {}".format(word_align)) + word = ' ' * word_align + word + while len(word) > BOARD_COLS: if len(line) != 0: lines.append(line) line = "" + word_prefix = word[0:BOARD_COLS-1] + "-" word_suffix = word[BOARD_COLS-1:] #print("append prefix {}".format(word_prefix)) @@ -308,11 +347,6 @@ if __name__ == "__main__": state.encoding = generateEncoding() - sendRawMessage(client, [ \ - (65,0), \ - (0x20,0xAD), \ - ]) - tx_state = OscTxState() for line in fileinput.input(): while sendMessageLazy(client, line, tx_state) != SEND_MSG_LAZY_DONE: |
