Merge pull request #92 from ebolam/united

Hopefully Last Redo Fix
This commit is contained in:
henk717 2022-03-05 19:26:15 +01:00 committed by GitHub
commit 6f2febb142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

View File

@ -2788,7 +2788,7 @@ def actionback():
vars.recentback = True vars.recentback = True
remove_story_chunk(last_key + 1) remove_story_chunk(last_key + 1)
#for the redo to not get out of whack, need to reset the max # in the actions sequence #for the redo to not get out of whack, need to reset the max # in the actions sequence
vars.actions.set_next_id(vars.actions.get_last_key()) vars.actions.set_next_id(last_key)
elif(len(vars.genseqs) == 0): elif(len(vars.genseqs) == 0):
emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."}) emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."})
else: else:
@ -2801,10 +2801,9 @@ def actionredo():
genout = [{"generated_text": item['Text']} for item in vars.actions_metadata[vars.actions.get_last_key()+1]['Alternative Text'] if (item["Previous Selection"]==True)] genout = [{"generated_text": item['Text']} for item in vars.actions_metadata[vars.actions.get_last_key()+1]['Alternative Text'] if (item["Previous Selection"]==True)]
if len(genout) > 0: if len(genout) > 0:
genout = genout + [{"generated_text": item['Text']} for item in vars.actions_metadata[vars.actions.get_last_key()+1]['Alternative Text'] if (item["Pinned"]==True) and (item["Previous Selection"]==False)] genout = genout + [{"generated_text": item['Text']} for item in vars.actions_metadata[vars.actions.get_last_key()+1]['Alternative Text'] if (item["Pinned"]==True) and (item["Previous Selection"]==False)]
if len(genout) == 1: if len(genout) == 1:
vars.actions_metadata[vars.actions.get_last_key()+1]['Alternative Text'] = [item for item in vars.actions_metadata[vars.actions.get_last_key()+1]['Alternative Text'] if (item["Previous Selection"]!=True)] vars.actions_metadata[vars.actions.get_last_key()+1]['Alternative Text'] = [item for item in vars.actions_metadata[vars.actions.get_last_key()+1]['Alternative Text'] if (item["Previous Selection"]!=True)]
genresult(genout[0]['generated_text'], flash=True) genresult(genout[0]['generated_text'], flash=True, ignore_formatting=True)
else: else:
# Store sequences in memory until selection is made # Store sequences in memory until selection is made
vars.genseqs = genout vars.genseqs = genout
@ -2812,6 +2811,7 @@ def actionredo():
# Send sequences to UI for selection # Send sequences to UI for selection
genout = [[item['Text'], "redo"] for item in vars.actions_metadata[vars.actions.get_last_key()+1]['Alternative Text'] if (item["Previous Selection"]==True)] genout = [[item['Text'], "redo"] for item in vars.actions_metadata[vars.actions.get_last_key()+1]['Alternative Text'] if (item["Previous Selection"]==True)]
emit('from_server', {'cmd': 'genseqs', 'data': genout}, broadcast=True) emit('from_server', {'cmd': 'genseqs', 'data': genout}, broadcast=True)
else: else:
emit('from_server', {'cmd': 'popuperror', 'data': "There's nothing to undo"}, broadcast=True) emit('from_server', {'cmd': 'popuperror', 'data': "There's nothing to undo"}, broadcast=True)
@ -3192,11 +3192,12 @@ def generate(txt, minimum, maximum, found_entries=None):
#==================================================================# #==================================================================#
# Deal with a single return sequence from generate() # Deal with a single return sequence from generate()
#==================================================================# #==================================================================#
def genresult(genout, flash=True): def genresult(genout, flash=True, ignore_formatting=False):
if not vars.quiet: if not vars.quiet:
print("{0}{1}{2}".format(colors.CYAN, genout, colors.END)) print("{0}{1}{2}".format(colors.CYAN, genout, colors.END))
# Format output before continuing # Format output before continuing
if not ignore_formatting:
genout = applyoutputformatting(genout) genout = applyoutputformatting(genout)
vars.lua_koboldbridge.feedback = genout vars.lua_koboldbridge.feedback = genout
@ -4619,8 +4620,6 @@ def loadRequest(loadpath, filename=None):
emit('from_server', {'cmd': 'hidegenseqs', 'data': ''}, broadcast=True) emit('from_server', {'cmd': 'hidegenseqs', 'data': ''}, broadcast=True)
print("{0}Story loaded from {1}!{2}".format(colors.GREEN, filename, colors.END)) print("{0}Story loaded from {1}!{2}".format(colors.GREEN, filename, colors.END))
print([k for k in vars.actions])
print([k for k in vars.actions_metadata])
send_debug() send_debug()
#==================================================================# #==================================================================#
@ -5031,7 +5030,7 @@ def send_debug():
except: except:
pass pass
try: try:
debug_info = "{}Actions: {}\n".format(debug_info, vars.actions.get_last_key()) debug_info = "{}Actions: {}\n".format(debug_info, [k for k in vars.actions])
except: except:
pass pass
try: try:

View File

@ -19,9 +19,15 @@ class KoboldStoryRegister(collections.OrderedDict):
return self.popitem()[1] return self.popitem()[1]
def get_first_key(self) -> int: def get_first_key(self) -> int:
if len(self) == 0:
return -1
else:
return next(iter(self)) return next(iter(self))
def get_last_key(self) -> int: def get_last_key(self) -> int:
if len(self) == 0:
return -1
else:
return next(reversed(self)) return next(reversed(self))
def __getitem__(self, k: int) -> str: def __getitem__(self, k: int) -> str: