Added dedicated inline editing commands to aiserver.py

It's a lot faster now.
This commit is contained in:
Gnome Ann 2021-08-23 18:52:45 -04:00
parent a907c0a554
commit 3bf467e63c
2 changed files with 41 additions and 14 deletions

View File

@ -543,7 +543,7 @@ def get_message(msg):
# Back/Undo Action # Back/Undo Action
elif(msg['cmd'] == 'back'): elif(msg['cmd'] == 'back'):
actionback() actionback()
# EditMode Action # EditMode Action (old)
elif(msg['cmd'] == 'edit'): elif(msg['cmd'] == 'edit'):
if(vars.mode == "play"): if(vars.mode == "play"):
vars.mode = "edit" vars.mode = "edit"
@ -551,10 +551,15 @@ def get_message(msg):
elif(vars.mode == "edit"): elif(vars.mode == "edit"):
vars.mode = "play" vars.mode = "play"
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True) emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
# EditLine Action # EditLine Action (old)
elif(msg['cmd'] == 'editline'): elif(msg['cmd'] == 'editline'):
editrequest(int(msg['data'])) editrequest(int(msg['data']))
# DeleteLine Action # Inline edit
elif(msg['cmd'] == 'inlineedit'):
inlineedit(msg['chunk'], msg['data'])
elif(msg['cmd'] == 'inlinedelete'):
inlinedelete(msg['data'])
# DeleteLine Action (old)
elif(msg['cmd'] == 'delete'): elif(msg['cmd'] == 'delete'):
deleterequest() deleterequest()
elif(msg['cmd'] == 'memory'): elif(msg['cmd'] == 'memory'):
@ -1382,7 +1387,7 @@ def editsubmit(data):
vars.mode = "play" vars.mode = "play"
refresh_story() refresh_story()
emit('from_server', {'cmd': 'texteffect', 'data': vars.editln}, broadcast=True) emit('from_server', {'cmd': 'texteffect', 'data': vars.editln}, broadcast=True)
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True) emit('from_server', {'cmd': 'editmode', 'data': 'false'})
#==================================================================# #==================================================================#
# #
@ -1396,6 +1401,34 @@ def deleterequest():
del vars.actions[vars.editln-1] del vars.actions[vars.editln-1]
vars.mode = "play" vars.mode = "play"
refresh_story() refresh_story()
emit('from_server', {'cmd': 'editmode', 'data': 'false'})
#==================================================================#
#
#==================================================================#
def inlineedit(chunk, data):
chunk = int(chunk)
if(chunk == 0):
vars.prompt = data
else:
vars.actions[chunk-1] = data
refresh_story()
emit('from_server', {'cmd': 'texteffect', 'data': chunk}, broadcast=True)
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
#==================================================================#
#
#==================================================================#
def inlinedelete(chunk):
chunk = int(chunk)
# Don't delete prompt
if(chunk == 0):
# Send error message
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
else:
del vars.actions[chunk-1]
refresh_story()
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True) emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)
#==================================================================# #==================================================================#

View File

@ -476,7 +476,7 @@ function newTextHighlight(ref) {
setTimeout(function () { setTimeout(function () {
ref.removeClass("colorfade"); ref.removeClass("colorfade");
}, 1000); }, 1000);
}, 10); }, 50);
} }
function showAidgPopup() { function showAidgPopup() {
@ -732,17 +732,11 @@ function submitEditedChunk(event) {
chunk = current_editing_chunk; chunk = current_editing_chunk;
current_editing_chunk = null; current_editing_chunk = null;
// Enter edit mode if we aren't already in edit mode
if(!editmode) {
socket.send({'cmd': 'edit', 'data': ''});
}
// Submit the edited chunk if it's not empty, otherwise delete it // Submit the edited chunk if it's not empty, otherwise delete it
socket.send({'cmd': 'editline', 'data': chunk.getAttribute("n")});
if(chunk.innerText.length) { if(chunk.innerText.length) {
socket.send({'cmd': 'submit', 'data': chunk.innerText}); socket.send({'cmd': 'inlineedit', 'chunk': chunk.getAttribute("n"), 'data': chunk.innerText});
} else { } else {
socket.send({'cmd': 'delete', 'data': ''}); socket.send({'cmd': 'inlinedelete', 'data': chunk.getAttribute("n")});
} }
} }
@ -834,7 +828,7 @@ $(document).ready(function(){
} }
}); });
} else if(msg.cmd == "updatescreen") { } else if(msg.cmd == "updatescreen") {
_gamestarted = gamestarted _gamestarted = gamestarted;
gamestarted = msg.gamestarted; gamestarted = msg.gamestarted;
if(_gamestarted != gamestarted) { if(_gamestarted != gamestarted) {
action_mode = 0; action_mode = 0;