Skip to content

Commit

Permalink
checkbox to voice each win
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-kane committed Aug 15, 2024
1 parent c65539b commit 4e48edc
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 12 deletions.
24 changes: 21 additions & 3 deletions cnv/chatlog/npc_chatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ def tail(self):
last_working = time.time()
log.debug('Entering primary log evaluation loop')
while settings.REPLAY or (time.time() - last_working < self.READ_TIMEOUT):
talking = (settings.REPLAY and settings.SPEECH_IN_REPLAY) or not settings.REPLAY

# read the next line, or return "" if we're at EOF
line = handle.readline().strip()

Expand All @@ -555,12 +557,28 @@ def tail(self):
self.speaking_queue.put((None, (" ".join(lstring[4:])), "system"))

elif lstring[0] == "You":
if lstring[1] in ["found", "have", "stole", "begin", "finished"]:
if lstring[1] in ["found", "stole", "begin", "finished"]:
# You found a face mask that is covered in some kind of mold. It appears to be pulsing like it's breathing. You send a short video to Watkins for evidence.
# You have cleared the Snakes from the Arachnos base, and learned something interesting.
# You stole the money!
dialog = plainstring(" ".join(lstring))
if (settings.REPLAY and settings.SPEECH_IN_REPLAY) or not settings.REPLAY:
if talking:
self.speaking_queue.put((None, dialog, "system"))

elif lstring[1] == "have":
# have is tricky. lots of things use have.
dialog = plainstring(" ".join(lstring))
if lstring[2] == "defeated":
enabled = settings.get_toggle(settings.taggify("Acknowledge each win"))
if talking and enabled:
self.speaking_queue.put((None, dialog, "system"))
else:
if not talking:
log.info(f'{talking=}')
else:
log.info(f'{enabled=}')

elif talking:
self.speaking_queue.put((None, dialog, "system"))

elif self.hero and lstring[1] == "gain":
Expand Down Expand Up @@ -625,7 +643,7 @@ def tail(self):
if lstring[1] == "hit":
# You hit Abomination with your Assassin's Psi Blade for 43.22 points of Psionic damage.
m = re.fullmatch(
r"You hit (?P<target>.*) with your (?P<power>.*) for (?P<damage>[0-9]*) points of (?P<damage_type>.*) damage(?P<ASTRIKE> over time| \(ASSASSIN STRIKE\)| \(CRITICAL\)| \(IMPACT!\))?.?",
r"You hit (?P<target>.*) with your (?P<power>.*) for (?P<damage>[0-9]*) points of (?P<damage_type>.*) damage(?P<ASTRIKE> over time| \(ASSASSIN STRIKE\)| \(CRITICAL\)| \(IMPACT!\)| \(ARCANE\))?.?",
" ".join(lstring)
)
if m:
Expand Down
21 changes: 17 additions & 4 deletions cnv/lib/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
"Spanish": ("es", ("es", ))
}

# by default, don't save things players say. It's not likely
# to cache hit anyway.
PERSIST_PLAYER_CHAT = True

REPLAY = False
XP_IN_REPLAY = False
SPEECH_IN_REPLAY = False
Expand Down Expand Up @@ -97,6 +93,23 @@ def get_config_key(key, default=None, cf="config.json"):
return config.get(key, default)


def taggify(instr):
tag = instr.replace(' ', '')
return tag[:10] + "_" + hashlib.sha256(tag.encode('utf8')).hexdigest()[:4]


def set_toggle(key, value):
set_config_key(
key=f'toggle_{key}',
value=value
)

def get_toggle(key):
return get_config_key(
key=f'toggle_{key}'
) == "on"


def get_alias(group):
return get_config_key(key=group, default=group, cf="aliases.json")

Expand Down
44 changes: 40 additions & 4 deletions cnv/tabs/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tkinter as tk
from tkinter import ttk
import customtkinter as ctk
import hashlib
import cnv.lib.settings as settings
from cnv.engines import engines

Expand Down Expand Up @@ -73,10 +74,8 @@ def __init__(self, parent, *args, **kwargs):
panel = engine_ui.auth_ui_class(tab)
panel.pack(fill="both", expand=True)




class ChannelToEngineMap(ttk.Frame):
class ChannelToEngineMap(ctk.CTkFrame):
"""
Allows the user to choose a primary and secondary for each channel. _Current_ channels are
npc, player and system.
Expand Down Expand Up @@ -224,6 +223,42 @@ def normalize_prompt_frame(self, parent, category):
return frame


class SpeakingToggles(ctk.CTkFrame):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.toggles = {}

index = 0
for toggle in [
"Acknowledge each win",
"Persist player chat"
]:
tag = settings.taggify(toggle)
self.toggles[tag] = tk.StringVar(
value="on" if settings.get_toggle(tag) else "off"
)

ctk.CTkCheckBox(
self,
command=self.toggle,
text=toggle,
variable=self.toggles[tag],
onvalue="on",
offvalue="off"
).grid(column=0, row=index, sticky='w')

index += 1

def toggle(self, *args, **kwargs):
for tag in self.toggles:
value = self.toggles[tag].get()
log.info(f"{tag} {value}")
settings.set_toggle(tag, value)
return


class ConfigurationTab(ctk.CTkFrame):

def __init__(self, parent, event_queue, speaking_queue, *args, **kwargs):
Expand All @@ -234,4 +269,5 @@ def __init__(self, parent, event_queue, speaking_queue, *args, **kwargs):
EngineAuthentication(
self,
).pack(side="top", fill="x")
ChannelToEngineMap(self).pack(side="top", fill="x")
ChannelToEngineMap(self).pack(side="top", fill="x")
SpeakingToggles(self).pack(side="top", fill="x")
2 changes: 1 addition & 1 deletion cnv/voices/voice_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create(character, message, session):
rank = 'secondary'

# have we seen this particular phrase before?
if character.category != PLAYER_CATEGORY or settings.PERSIST_PLAYER_CHAT:
if character.category != PLAYER_CATEGORY or settings.get_toggle(settings.taggify("Persist player chat")):
# phrase_id = models.get_or_create_phrase_id(
# name=character.name,
# category=character.category,
Expand Down

0 comments on commit 4e48edc

Please sign in to comment.