Lua API fixes for deleting/editing story chunks

This commit is contained in:
Gnome Ann 2021-12-31 18:28:03 -05:00
parent 7241188408
commit ccfafe4f0a
2 changed files with 12 additions and 10 deletions

View File

@ -1249,7 +1249,7 @@ def lua_get_numseqs():
def lua_set_numseqs(numseqs): def lua_set_numseqs(numseqs):
assert type(numseqs) in (int, float) and numseqs >= 1 assert type(numseqs) in (int, float) and numseqs >= 1
print(colors.GREEN + f"{lua_log_format_name(vars.lua_koboldbridge.logging_name)} set numseqs to {int(numseqs)}" + colors.END) print(colors.GREEN + f"{lua_log_format_name(vars.lua_koboldbridge.logging_name)} set numseqs to {int(numseqs)}" + colors.END)
vars.genamt = int(numseqs) vars.numseqs = int(numseqs)
#==================================================================# #==================================================================#
# Check if a setting exists with the given name # Check if a setting exists with the given name
@ -1410,8 +1410,8 @@ def lua_set_chunk(k, v):
chunk = int(k) chunk = int(k)
if(vars.lua_koboldbridge.userstate == "genmod"): if(vars.lua_koboldbridge.userstate == "genmod"):
del vars._actions[chunk-1] del vars._actions[chunk-1]
vars.lua_deleted.add(chunk) vars.lua_deleted.add(chunk)
if(vars._actions is not vars.actions): if(not hasattr(vars, "_actions") or vars._actions is not vars.actions):
del vars.actions[chunk-1] del vars.actions[chunk-1]
else: else:
if(k == 0): if(k == 0):
@ -1422,12 +1422,12 @@ def lua_set_chunk(k, v):
if(chunk == 0): if(chunk == 0):
if(vars.lua_koboldbridge.userstate == "genmod"): if(vars.lua_koboldbridge.userstate == "genmod"):
vars._prompt = v vars._prompt = v
vars.lua_edited.add(chunk) vars.lua_edited.add(chunk)
vars.prompt = v vars.prompt = v
else: else:
if(vars.lua_koboldbridge.userstate == "genmod"): if(vars.lua_koboldbridge.userstate == "genmod"):
vars._actions[chunk-1] = v vars._actions[chunk-1] = v
vars.lua_edited.add(chunk) vars.lua_edited.add(chunk)
vars.actions[chunk-1] = v vars.actions[chunk-1] = v
#==================================================================# #==================================================================#
@ -3118,7 +3118,8 @@ def inlineedit(chunk, data):
return return
vars.prompt = data vars.prompt = data
else: else:
vars.actions[chunk-1] = data if(chunk-1 in vars.actions):
vars.actions[chunk-1] = data
update_story_chunk(chunk) update_story_chunk(chunk)
emit('from_server', {'cmd': 'texteffect', 'data': chunk}, broadcast=True) emit('from_server', {'cmd': 'texteffect', 'data': chunk}, broadcast=True)
@ -3137,7 +3138,8 @@ def inlinedelete(chunk):
emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."}) emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."})
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True) emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
else: else:
del vars.actions[chunk-1] if(chunk-1 in vars.actions):
del vars.actions[chunk-1]
remove_story_chunk(chunk) remove_story_chunk(chunk)
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True) emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)

View File

@ -1916,6 +1916,9 @@ return function(_python, _bridged)
koboldbridge.generating = true koboldbridge.generating = true
koboldbridge.generated_cols = 0 koboldbridge.generated_cols = 0
koboldbridge.generated = {} koboldbridge.generated = {}
if koboldbridge.inmod ~= nil then
r = koboldbridge.inmod()
end
for i = 1, kobold.settings.numseqs do for i = 1, kobold.settings.numseqs do
koboldbridge.generated[i] = {} koboldbridge.generated[i] = {}
end end
@ -1923,9 +1926,6 @@ return function(_python, _bridged)
for i = 1, kobold.num_outputs do for i = 1, kobold.num_outputs do
koboldbridge.outputs[i] = {} koboldbridge.outputs[i] = {}
end end
if koboldbridge.inmod ~= nil then
r = koboldbridge.inmod()
end
return r return r
end end