Guard against empty prompts
This commit is contained in:
parent
4961273a26
commit
9ab1d182ac
22
aiserver.py
22
aiserver.py
|
@ -951,6 +951,9 @@ def actionsubmit(data, actionmode=0):
|
||||||
vars.lastact = data
|
vars.lastact = data
|
||||||
|
|
||||||
if(not vars.gamestarted):
|
if(not vars.gamestarted):
|
||||||
|
if(len(data.strip()) == 0):
|
||||||
|
set_aibusy(0)
|
||||||
|
return
|
||||||
# Start the game
|
# Start the game
|
||||||
vars.gamestarted = True
|
vars.gamestarted = True
|
||||||
# Save this first action as the prompt
|
# Save this first action as the prompt
|
||||||
|
@ -971,6 +974,9 @@ def actionsubmit(data, actionmode=0):
|
||||||
if(vars.actionmode == 0):
|
if(vars.actionmode == 0):
|
||||||
data = applyinputformatting(data)
|
data = applyinputformatting(data)
|
||||||
# Store the result in the Action log
|
# Store the result in the Action log
|
||||||
|
if(len(vars.prompt.strip()) == 0):
|
||||||
|
vars.prompt = data
|
||||||
|
else:
|
||||||
vars.actions.append(data)
|
vars.actions.append(data)
|
||||||
update_story_chunk('last')
|
update_story_chunk('last')
|
||||||
|
|
||||||
|
@ -1284,6 +1290,9 @@ def genresult(genout):
|
||||||
genout = applyoutputformatting(genout)
|
genout = applyoutputformatting(genout)
|
||||||
|
|
||||||
# Add formatted text to Actions array and refresh the game screen
|
# Add formatted text to Actions array and refresh the game screen
|
||||||
|
if(len(vars.prompt.strip()) == 0):
|
||||||
|
vars.prompt = genout
|
||||||
|
else:
|
||||||
vars.actions.append(genout)
|
vars.actions.append(genout)
|
||||||
update_story_chunk('last')
|
update_story_chunk('last')
|
||||||
emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() if len(vars.actions) else 0}, broadcast=True)
|
emit('from_server', {'cmd': 'texteffect', 'data': vars.actions.get_last_key() if len(vars.actions) else 0}, broadcast=True)
|
||||||
|
@ -2102,7 +2111,18 @@ def loadRequest(loadpath):
|
||||||
|
|
||||||
del vars.actions
|
del vars.actions
|
||||||
vars.actions = structures.KoboldStoryRegister()
|
vars.actions = structures.KoboldStoryRegister()
|
||||||
for s in js["actions"]:
|
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)
|
vars.actions.append(s)
|
||||||
|
|
||||||
# Try not to break older save files
|
# Try not to break older save files
|
||||||
|
|
|
@ -494,7 +494,11 @@ function returnWiList(ar) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function dosubmit() {
|
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});
|
socket.send({'cmd': 'submit', 'actionmode': adventure ? action_mode : 0, 'data': txt});
|
||||||
if(memorymode) {
|
if(memorymode) {
|
||||||
memorytext = input_text.val();
|
memorytext = input_text.val();
|
||||||
|
@ -882,7 +886,7 @@ function syncAllModifiedChunks(including_selected_chunks=false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function restorePrompt() {
|
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, " ");
|
saved_prompt = game_text[0].firstChild.textContent.replace(/\u00a0/g, " ");
|
||||||
unbindGametext();
|
unbindGametext();
|
||||||
game_text[0].innerText = "";
|
game_text[0].innerText = "";
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<script src="static/jquery-3.6.0.min.js"></script>
|
<script src="static/jquery-3.6.0.min.js"></script>
|
||||||
<script src="static/socket.io.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.min.js"></script>
|
||||||
<script src="static/bootstrap-toggle.min.js"></script>
|
<script src="static/bootstrap-toggle.min.js"></script>
|
||||||
<script src="static/rangy-core.min.js"></script>
|
<script src="static/rangy-core.min.js"></script>
|
||||||
|
|
Loading…
Reference in New Issue