diff --git a/aiserver.py b/aiserver.py index 765727f4..f8f5648a 100644 --- a/aiserver.py +++ b/aiserver.py @@ -951,6 +951,9 @@ def actionsubmit(data, actionmode=0): vars.lastact = data if(not vars.gamestarted): + if(len(data.strip()) == 0): + set_aibusy(0) + return # Start the game vars.gamestarted = True # Save this first action as the prompt @@ -971,7 +974,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): @@ -1284,7 +1290,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) @@ -2102,8 +2111,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): diff --git a/static/application.js b/static/application.js index 04ca8cb9..17076459 100644 --- a/static/application.js +++ b/static/application.js @@ -494,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(); @@ -882,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/templates/index.html b/templates/index.html index e8bfdb7a..95f3c31f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,7 +6,7 @@ - +