mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-02-17 12:10:49 +01:00
Integrate inline chunk editor and Adventure mode with Javalar's branch
This commit is contained in:
parent
735fc9431b
commit
b1c6aee8d3
16
aiserver.py
16
aiserver.py
@ -1314,12 +1314,12 @@ def applyoutputformatting(txt):
|
||||
# Sends the current story content to the Game Screen
|
||||
#==================================================================#
|
||||
def refresh_story():
|
||||
text_parts = ['<chunk n="0" id="n0">', html.escape(vars.prompt), '</chunk>']
|
||||
text_parts = ['<chunk n="0" id="n0" tabindex="-1">', html.escape(vars.prompt), '</chunk>']
|
||||
for idx, item in enumerate(vars.actions, start=1):
|
||||
item = html.escape(item)
|
||||
if vars.adventure: # Add special formatting to adventure actions
|
||||
item = vars.acregex_ui.sub('<action>\\1</action>', item)
|
||||
text_parts.extend(('<chunk n="', str(idx), '" id="n', str(idx), '">', item, '</chunk>'))
|
||||
text_parts.extend(('<chunk n="', str(idx), '" id="n', str(idx), '" tabindex="-1">', item, '</chunk>'))
|
||||
emit('from_server', {'cmd': 'updatescreen', 'gamestarted': vars.gamestarted, 'data': formatforhtml(''.join(text_parts))}, broadcast=True)
|
||||
|
||||
|
||||
@ -1344,7 +1344,11 @@ def update_story_chunk(idx: Union[int, Literal['last']]):
|
||||
# So the chunk index is one more than the corresponding action index.
|
||||
text = vars.actions[idx - 1]
|
||||
|
||||
chunk_text = f'<chunk n="{idx}" id="n{idx}">{formatforhtml(html.escape(text))}</chunk>'
|
||||
item = html.escape(text)
|
||||
if vars.adventure: # Add special formatting to adventure actions
|
||||
item = vars.acregex_ui.sub('<action>\\1</action>', item)
|
||||
|
||||
chunk_text = f'<chunk n="{idx}" id="n{idx}" tabindex="-1">{formatforhtml(item)}</chunk>'
|
||||
emit('from_server', {'cmd': 'updatechunk', 'data': {'index': idx, 'html': chunk_text, 'last': (idx == len(vars.actions))}}, broadcast=True)
|
||||
|
||||
|
||||
@ -1451,7 +1455,7 @@ def inlineedit(chunk, data):
|
||||
else:
|
||||
vars.actions[chunk-1] = data
|
||||
|
||||
refresh_story()
|
||||
update_story_chunk(chunk)
|
||||
emit('from_server', {'cmd': 'texteffect', 'data': chunk}, broadcast=True)
|
||||
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
|
||||
|
||||
@ -1463,12 +1467,12 @@ def inlinedelete(chunk):
|
||||
# Don't delete prompt
|
||||
if(chunk == 0):
|
||||
# Send error message
|
||||
refresh_story()
|
||||
update_story_chunk(chunk)
|
||||
emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."})
|
||||
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
|
||||
else:
|
||||
del vars.actions[chunk-1]
|
||||
refresh_story()
|
||||
remove_story_chunk(chunk)
|
||||
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
|
||||
|
||||
#==================================================================#
|
||||
|
@ -848,7 +848,6 @@ $(document).ready(function(){
|
||||
}
|
||||
game_text.html(msg.data);
|
||||
// Make content editable if need be
|
||||
$("chunk").attr('tabindex', -1)
|
||||
$('chunk').attr('contenteditable', allowedit);
|
||||
hide([$('#curtain')]);
|
||||
// Scroll to bottom of text
|
||||
@ -875,6 +874,8 @@ $(document).ready(function(){
|
||||
// Append at the end
|
||||
game_text.append(newChunk);
|
||||
}
|
||||
newChunk.attr('contenteditable', allowedit);
|
||||
hide([$('#curtain')]);
|
||||
if(last) {
|
||||
// Scroll to bottom of text if it's the last element
|
||||
setTimeout(function () {
|
||||
@ -896,6 +897,7 @@ $(document).ready(function(){
|
||||
chunk.attr('n', newIndex.toString()).attr('id', `n${newIndex}`);
|
||||
index++;
|
||||
}
|
||||
hide([$('#curtain')]);
|
||||
} else if(msg.cmd == "setgamestate") {
|
||||
// Enable or Disable buttons
|
||||
if(msg.data == "ready") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user