diff --git a/aiserver.py b/aiserver.py index 41277ee5..ac78f7d7 100644 --- a/aiserver.py +++ b/aiserver.py @@ -1,6 +1,6 @@ #==================================================================# # KoboldAI -# Version: 1.16.1 +# Version: 1.16.2 # By: KoboldAIDev and the KoboldAI Community #==================================================================# @@ -936,7 +936,7 @@ def settingschanged(): #==================================================================# # Take input text from SocketIO and decide what to do with it #==================================================================# -def actionsubmit(data, actionmode=0): +def actionsubmit(data, actionmode=0, force_submit=False): # Ignore new submissions if the AI is currently busy if(vars.aibusy): return @@ -950,13 +950,17 @@ def actionsubmit(data, actionmode=0): if(actionmode == 1): data = data.strip().lstrip('>') data = re.sub(r'\n+', ' ', data) - data = f"\n\n> {data}\n" + if(len(data)): + data = f"\n\n> {data}\n" # If we're not continuing, store a copy of the raw input if(data != ""): vars.lastact = data if(not vars.gamestarted): + if(not force_submit and len(data.strip()) == 0): + set_aibusy(0) + return # Start the game vars.gamestarted = True # Save this first action as the prompt @@ -977,7 +981,10 @@ def actionsubmit(data, actionmode=0): if(vars.actionmode == 0): data = applyinputformatting(data) # Store the result in the Action log - vars.actions.append(data) + if(len(vars.prompt.strip()) == 0): + vars.prompt = data + else: + vars.actions.append(data) update_story_chunk('last') if(not vars.noai): @@ -1000,12 +1007,13 @@ def actionretry(data): # Remove last action if possible and resubmit if(vars.gamestarted if vars.useprompt else len(vars.actions) > 0): set_aibusy(1) - if(not vars.recentback and not vars.recentedit 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 + 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 last_key = vars.actions.get_last_key() vars.actions.pop() remove_story_chunk(last_key + 1) vars.genseqs = [] calcsubmit('') + emit('from_server', {'cmd': 'scrolldown', 'data': ''}, broadcast=True) vars.recentback = False vars.recentedit = False elif(not vars.useprompt): @@ -1290,7 +1298,10 @@ def genresult(genout): genout = applyoutputformatting(genout) # Add formatted text to Actions array and refresh the game screen - vars.actions.append(genout) + if(len(vars.prompt.strip()) == 0): + vars.prompt = genout + else: + vars.actions.append(genout) update_story_chunk('last') emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() if len(vars.actions) else 0}, broadcast=True) @@ -2108,8 +2119,19 @@ def loadRequest(loadpath): del vars.actions vars.actions = structures.KoboldStoryRegister() - for s in js["actions"]: - vars.actions.append(s) + actions = collections.deque(js["actions"]) + + if(len(vars.prompt.strip()) == 0): + while(len(actions)): + action = actions.popleft() + if(len(action.strip()) != 0): + vars.prompt = action + break + else: + vars.gamestarted = False + if(vars.gamestarted): + for s in actions: + vars.actions.append(s) # Try not to break older save files if("authorsnote" in js): @@ -2383,7 +2405,7 @@ def newGameRequest(): def randomGameRequest(topic): newGameRequest() vars.memory = "You generate the following " + topic + " story concept :" - actionsubmit("") + actionsubmit("", force_submit=True) vars.memory = "" #==================================================================# diff --git a/static/application.js b/static/application.js index f8692b7e..17076459 100644 --- a/static/application.js +++ b/static/application.js @@ -466,6 +466,7 @@ function enterWiMode() { hide([button_actback, button_actmem, button_actretry, game_text]); show([wi_menu]); disableSendBtn(); + $("#gamescreen").addClass("wigamescreen"); } function exitWiMode() { @@ -474,7 +475,7 @@ function exitWiMode() { hide([wi_menu]); show([button_actback, button_actmem, button_actretry, game_text]); enableSendBtn(); - scrollToBottom(); + $("#gamescreen").removeClass("wigamescreen"); } function returnWiList(ar) { @@ -493,7 +494,11 @@ function returnWiList(ar) { } function dosubmit() { - var txt = input_text.val(); + var txt = input_text.val().replace(/\u00a0/g, " "); + console.log(gamestarted) + if(!gamestarted && ((!adventure || !action_mode) && txt.trim().length == 0)) { + return; + } socket.send({'cmd': 'submit', 'actionmode': adventure ? action_mode : 0, 'data': txt}); if(memorymode) { memorytext = input_text.val(); @@ -881,7 +886,7 @@ function syncAllModifiedChunks(including_selected_chunks=false) { } function restorePrompt() { - if(game_text[0].firstChild.nodeType === 3) { + if(game_text[0].firstChild && game_text[0].firstChild.nodeType === 3) { saved_prompt = game_text[0].firstChild.textContent.replace(/\u00a0/g, " "); unbindGametext(); game_text[0].innerText = ""; diff --git a/static/custom.css b/static/custom.css index fa9be0b4..2d12c00c 100644 --- a/static/custom.css +++ b/static/custom.css @@ -77,6 +77,11 @@ chunk.editing, chunk.editing * { font-family: "Helvetica"; } +#gamescreen.wigamescreen { + padding: 10px; + overflow-y: scroll; +} + #gamescreen span { align-self: flex-end; } diff --git a/templates/index.html b/templates/index.html index fbb90294..8e3558b9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,14 +6,14 @@ - + - +