Merge pull request #90 from ebolam/united

Redo Bug Fix
This commit is contained in:
henk717 2022-03-04 22:10:49 +01:00 committed by GitHub
commit 8e12b7df61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 65 additions and 32 deletions

View File

@ -2677,8 +2677,8 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False,
# we now need to update the actions_metadata
# we'll have two conditions.
# 1. This is totally new (user entered)
if vars.actions.get_next_id()-1 not in vars.actions_metadata:
vars.actions_metadata.append({"Selected Text": data, "Alternative Text": []})
if vars.actions.get_last_key() not in vars.actions_metadata:
vars.actions_metadata[vars.actions.get_last_key()] = {"Selected Text": data, "Alternative Text": []}
else:
# 2. We've selected a chunk of text that is was presented previously
try:
@ -2688,9 +2688,9 @@ def actionsubmit(data, actionmode=0, force_submit=False, force_prompt_gen=False,
print(vars.actions_metadata)
raise
if data in alternatives:
alternatives = [item for item in vars.actions_metadata[vars.actions.get_next_id()-1 ]["Alternative Text"] if item['Text'] != data]
vars.actions_metadata[vars.actions.get_next_id()-1]["Alternative Text"] = alternatives
vars.actions_metadata[vars.actions.get_next_id()-1]["Selected Text"] = data
alternatives = [item for item in vars.actions_metadata[vars.actions.get_last_key() ]["Alternative Text"] if item['Text'] != data]
vars.actions_metadata[vars.actions.get_last_key()]["Alternative Text"] = alternatives
vars.actions_metadata[vars.actions.get_last_key()]["Selected Text"] = data
update_story_chunk('last')
send_debug()
@ -2748,11 +2748,11 @@ def actionretry(data):
if(vars.gamestarted if vars.useprompt else len(vars.actions) > 0):
if(not vars.recentback and len(vars.actions) != 0 and len(vars.genseqs) == 0): # Don't pop if we're in the "Select sequence to keep" menu or if there are no non-prompt actions
# We are going to move the selected text to alternative text in the actions_metadata variable so we can redo this action
vars.actions_metadata[vars.actions.get_next_id()-1 ]['Alternative Text'] = [{'Text': vars.actions_metadata[vars.actions.get_next_id()-1 ]['Selected Text'],
vars.actions_metadata[vars.actions.get_last_key() ]['Alternative Text'] = [{'Text': vars.actions_metadata[vars.actions.get_last_key() ]['Selected Text'],
'Pinned': False,
"Previous Selection": True,
"Edited": False}] + vars.actions_metadata[vars.actions.get_next_id()-1 ]['Alternative Text']
vars.actions_metadata[vars.actions.get_next_id()-1]['Selected Text'] = ""
"Edited": False}] + vars.actions_metadata[vars.actions.get_last_key() ]['Alternative Text']
vars.actions_metadata[vars.actions.get_last_key()]['Selected Text'] = ""
@ -2776,18 +2776,18 @@ def actionback():
# Remove last index of actions and refresh game screen
if(len(vars.genseqs) == 0 and len(vars.actions) > 0):
# We are going to move the selected text to alternative text in the actions_metadata variable so we can redo this action
vars.actions_metadata[vars.actions.get_next_id()-1 ]['Alternative Text'] = [{'Text': vars.actions_metadata[vars.actions.get_next_id()-1 ]['Selected Text'],
vars.actions_metadata[vars.actions.get_last_key() ]['Alternative Text'] = [{'Text': vars.actions_metadata[vars.actions.get_last_key() ]['Selected Text'],
'Pinned': False,
"Previous Selection": True,
"Edited": False}] + vars.actions_metadata[vars.actions.get_next_id()-1 ]['Alternative Text']
vars.actions_metadata[vars.actions.get_next_id()-1 ]['Selected Text'] = ""
"Edited": False}] + vars.actions_metadata[vars.actions.get_last_key() ]['Alternative Text']
vars.actions_metadata[vars.actions.get_last_key() ]['Selected Text'] = ""
last_key = vars.actions.get_last_key()
vars.actions.pop()
vars.recentback = True
remove_story_chunk(last_key + 1)
#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_next_id()-1)
vars.actions.set_next_id(vars.actions.get_last_key())
elif(len(vars.genseqs) == 0):
emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."})
else:
@ -3208,10 +3208,10 @@ def genresult(genout, flash=True):
vars.prompt = genout
else:
vars.actions.append(genout)
if vars.actions.get_next_id()-1 not in vars.actions_metadata:
vars.actions_metadata[vars.actions.get_next_id()-1] = {'Selected Text': genout, 'Alternative Text': []}
if vars.actions.get_last_key() not in vars.actions_metadata:
vars.actions_metadata[vars.actions.get_last_key()] = {'Selected Text': genout, 'Alternative Text': []}
else:
vars.actions_metadata[vars.actions.get_next_id()-1]['Selected Text'] = genout
vars.actions_metadata[vars.actions.get_last_key()]['Selected Text'] = genout
update_story_chunk('last')
if(flash):
emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() + 1 if len(vars.actions) else 0}, broadcast=True)
@ -3264,8 +3264,8 @@ def selectsequence(n):
if(len(vars.lua_koboldbridge.feedback) != 0):
vars.actions.append(vars.lua_koboldbridge.feedback)
#We'll want to remove the option from the alternative text and put it in selected text
vars.actions_metadata[vars.actions.get_next_id()-1 ]['Alternative Text'] = [item for item in vars.actions_metadata[vars.actions.get_next_id()-1]['Alternative Text'] if item['Text'] != vars.lua_koboldbridge.feedback]
vars.actions_metadata[vars.actions.get_next_id()-1 ]['Selected Text'] = vars.lua_koboldbridge.feedback
vars.actions_metadata[vars.actions.get_last_key() ]['Alternative Text'] = [item for item in vars.actions_metadata[vars.actions.get_last_key()]['Alternative Text'] if item['Text'] != vars.lua_koboldbridge.feedback]
vars.actions_metadata[vars.actions.get_last_key() ]['Selected Text'] = vars.lua_koboldbridge.feedback
update_story_chunk('last')
emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() + 1 if len(vars.actions) else 0}, broadcast=True)
emit('from_server', {'cmd': 'hidegenseqs', 'data': ''}, broadcast=True)
@ -4168,15 +4168,15 @@ def ikrequest(txt):
if not vars.quiet:
print("{0}{1}{2}".format(colors.CYAN, genout, colors.END))
vars.actions.append(genout)
if vars.actions.get_next_id()-1 in vars.actions_metadata:
vars.actions_metadata[vars.actions.get_next_id()-1] = {"Selected Text": genout, "Alternative Text": []}
if vars.actions.get_last_key() in vars.actions_metadata:
vars.actions_metadata[vars.actions.get_last_key()] = {"Selected Text": genout, "Alternative Text": []}
else:
# 2. We've selected a chunk of text that is was presented previously
alternatives = [item['Text'] for item in vars.actions_metadata[vars.actions.get_next_id()-1]["Alternative Text"]]
alternatives = [item['Text'] for item in vars.actions_metadata[vars.actions.get_last_key()]["Alternative Text"]]
if genout in alternatives:
alternatives = [item for item in vars.actions_metadata[vars.actions.get_next_id()-1]["Alternative Text"] if item['Text'] != genout]
vars.actions_metadata[vars.actions.get_next_id()-1]["Alternative Text"] = alternatives
vars.actions_metadata[vars.actions.get_next_id()-1]["Selected Text"] = genout
alternatives = [item for item in vars.actions_metadata[vars.actions.get_last_key()]["Alternative Text"] if item['Text'] != genout]
vars.actions_metadata[vars.actions.get_last_key()]["Alternative Text"] = alternatives
vars.actions_metadata[vars.actions.get_last_key()]["Selected Text"] = genout
update_story_chunk('last')
emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() + 1 if len(vars.actions) else 0}, broadcast=True)
send_debug()
@ -4238,15 +4238,15 @@ def oairequest(txt, min, max):
if not vars.quiet:
print("{0}{1}{2}".format(colors.CYAN, genout, colors.END))
vars.actions.append(genout)
if vars.actions.get_next_id()-1 in vars.actions_metadata:
vars.actions_metadata[vars.actions.get_next_id()-1] = {"Selected Text": genout, "Alternative Text": []}
if vars.actions.get_last_key() in vars.actions_metadata:
vars.actions_metadata[vars.actions.get_last_key()] = {"Selected Text": genout, "Alternative Text": []}
else:
# 2. We've selected a chunk of text that is was presented previously
alternatives = [item['Text'] for item in vars.actions_metadata[vars.actions.get_next_id()-1]["Alternative Text"]]
alternatives = [item['Text'] for item in vars.actions_metadata[vars.actions.get_last_key()]["Alternative Text"]]
if genout in alternatives:
alternatives = [item for item in vars.actions_metadata[vars.actions.get_next_id()-1 ]["Alternative Text"] if item['Text'] != genout]
vars.actions_metadata[vars.actions.get_next_id()-1 ]["Alternative Text"] = alternatives
vars.actions_metadata[vars.actions.get_next_id()-1 ]["Selected Text"] = genout
alternatives = [item for item in vars.actions_metadata[vars.actions.get_last_key() ]["Alternative Text"] if item['Text'] != genout]
vars.actions_metadata[vars.actions.get_last_key() ]["Alternative Text"] = alternatives
vars.actions_metadata[vars.actions.get_last_key() ]["Selected Text"] = genout
update_story_chunk('last')
emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() + 1 if len(vars.actions) else 0}, broadcast=True)
send_debug()
@ -4504,6 +4504,7 @@ def loadRequest(loadpath, filename=None):
vars.actions = structures.KoboldStoryRegister()
actions = collections.deque(js["actions"])
if "actions_metadata" in js:
if type(js["actions_metadata"]) == dict:
@ -4512,7 +4513,8 @@ def loadRequest(loadpath, filename=None):
#we need to redo the numbering of the actions_metadata since the actions list doesn't preserve it's number on saving
if len(temp) > 0:
counter = 0
for i in range(max(temp)):
temp = {int(k):v for k,v in temp.items()}
for i in range(max(temp)+1):
if i in temp:
vars.actions_metadata[counter] = temp[i]
counter += 1
@ -4616,6 +4618,10 @@ def loadRequest(loadpath, filename=None):
emit('from_server', {'cmd': 'hidegenseqs', 'data': ''}, broadcast=True)
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()
#==================================================================#
# Import an AIDungon game exported with Mimi's tool
#==================================================================#
@ -5011,8 +5017,35 @@ if(vars.model in ("TPUMeshTransformerGPTJ",)):
def send_debug():
if vars.debug:
debug_info = ""
for variable in [["Newline Mode", vars.newlinemode], ["Action Length", vars.actions.get_last_key()], ["Actions Metadata Length", max(vars.actions_metadata) if len(vars.actions_metadata) > 0 else 0], ["Actions Metadata", vars.actions_metadata]]:
debug_info = "{}{}: {}\n".format(debug_info, variable[0], variable[1])
try:
debug_info = "{}Newline Mode: {}\n".format(debug_info, vars.newlinemode)
except:
pass
try:
debug_info = "{}Action Length: {}\n".format(debug_info, vars.actions.get_last_key())
except:
pass
try:
debug_info = "{}Actions Metadata Length: {}\n".format(debug_info, max(vars.actions_metadata) if len(vars.actions_metadata) > 0 else 0)
except:
pass
try:
debug_info = "{}Actions: {}\n".format(debug_info, vars.actions.get_last_key())
except:
pass
try:
debug_info = "{}Actions Metadata: {}\n".format(debug_info, [k for k in vars.actions_metadata])
except:
pass
try:
debug_info = "{}Last Action: {}\n".format(debug_info, vars.actions[vars.actions.get_last_key()])
except:
pass
try:
debug_info = "{}Last Metadata: {}\n".format(debug_info, vars.actions_metadata[max(vars.actions_metadata)])
except:
pass
emit('from_server', {'cmd': 'debug_info', 'data': debug_info}, broadcast=True)
#==================================================================#