Guard against empty prompts

This commit is contained in:
Gnome Ann 2021-09-28 19:48:43 -04:00
parent 4961273a26
commit 9ab1d182ac
3 changed files with 31 additions and 7 deletions

View File

@ -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):

View File

@ -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 = "";

View File

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="static/jquery-3.6.0.min.js"></script>
<script src="static/socket.io.min.js"></script>
<script src="static/application.js?ver=1.16.1b"></script>
<script src="static/application.js?ver=1.16.1d"></script>
<script src="static/bootstrap.min.js"></script>
<script src="static/bootstrap-toggle.min.js"></script>
<script src="static/rangy-core.min.js"></script>