commit
bbd5bd0cd7
22
aiserver.py
22
aiserver.py
|
@ -102,6 +102,7 @@ class vars:
|
||||||
svowname = "" # Filename that was flagged for overwrite confirm
|
svowname = "" # Filename that was flagged for overwrite confirm
|
||||||
saveow = False # Whether or not overwrite confirm has been displayed
|
saveow = False # Whether or not overwrite confirm has been displayed
|
||||||
genseqs = [] # Temporary storage for generated sequences
|
genseqs = [] # Temporary storage for generated sequences
|
||||||
|
recentback = False # Whether Back button was recently used without Submitting or Retrying after
|
||||||
useprompt = True # Whether to send the full prompt with every submit action
|
useprompt = True # Whether to send the full prompt with every submit action
|
||||||
breakmodel = False # For GPU users, whether to use both system RAM and VRAM to conserve VRAM while offering speedup compared to CPU-only
|
breakmodel = False # For GPU users, whether to use both system RAM and VRAM to conserve VRAM while offering speedup compared to CPU-only
|
||||||
bmsupported = False # Whether the breakmodel option is supported (GPT-Neo/GPT-J only, currently)
|
bmsupported = False # Whether the breakmodel option is supported (GPT-Neo/GPT-J only, currently)
|
||||||
|
@ -528,7 +529,7 @@ def do_connect():
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
@socketio.on('message')
|
@socketio.on('message')
|
||||||
def get_message(msg):
|
def get_message(msg):
|
||||||
print("{0}Data recieved:{1}{2}".format(colors.GREEN, msg, colors.END))
|
print("{0}Data received:{1}{2}".format(colors.GREEN, msg, colors.END))
|
||||||
# Submit action
|
# Submit action
|
||||||
if(msg['cmd'] == 'submit'):
|
if(msg['cmd'] == 'submit'):
|
||||||
if(vars.mode == "play"):
|
if(vars.mode == "play"):
|
||||||
|
@ -829,6 +830,7 @@ def actionsubmit(data, actionmode=0):
|
||||||
return
|
return
|
||||||
set_aibusy(1)
|
set_aibusy(1)
|
||||||
|
|
||||||
|
vars.recentback = False
|
||||||
vars.actionmode = actionmode
|
vars.actionmode = actionmode
|
||||||
|
|
||||||
# "Action" mode
|
# "Action" mode
|
||||||
|
@ -882,12 +884,17 @@ def actionretry(data):
|
||||||
return
|
return
|
||||||
if(vars.aibusy):
|
if(vars.aibusy):
|
||||||
return
|
return
|
||||||
set_aibusy(1)
|
|
||||||
# Remove last action if possible and resubmit
|
# Remove last action if possible and resubmit
|
||||||
if(len(vars.actions) > 0):
|
if(vars.gamestarted if vars.useprompt else len(vars.actions) > 0):
|
||||||
vars.actions.pop()
|
set_aibusy(1)
|
||||||
|
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
|
||||||
|
vars.actions.pop()
|
||||||
|
vars.genseqs = []
|
||||||
refresh_story()
|
refresh_story()
|
||||||
calcsubmit('')
|
calcsubmit('')
|
||||||
|
vars.recentback = False
|
||||||
|
elif(not vars.useprompt):
|
||||||
|
emit('from_server', {'cmd': 'errmsg', 'data': "Please enable \"Always Add Prompt\" to retry with your prompt."})
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
#
|
#
|
||||||
|
@ -896,9 +903,14 @@ def actionback():
|
||||||
if(vars.aibusy):
|
if(vars.aibusy):
|
||||||
return
|
return
|
||||||
# Remove last index of actions and refresh game screen
|
# Remove last index of actions and refresh game screen
|
||||||
if(len(vars.actions) > 0):
|
if(len(vars.genseqs) == 0 and len(vars.actions) > 0):
|
||||||
vars.actions.pop()
|
vars.actions.pop()
|
||||||
|
vars.recentback = True
|
||||||
refresh_story()
|
refresh_story()
|
||||||
|
elif(len(vars.genseqs) == 0):
|
||||||
|
emit('from_server', {'cmd': 'errmsg', 'data': "Cannot delete the prompt."})
|
||||||
|
else:
|
||||||
|
vars.genseqs = []
|
||||||
|
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
# Take submitted text and build the text to be given to generator
|
# Take submitted text and build the text to be given to generator
|
||||||
|
|
19
fileops.py
19
fileops.py
|
@ -59,14 +59,23 @@ def getdirpath(dir, title):
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
def getstoryfiles():
|
def getstoryfiles():
|
||||||
list = []
|
list = []
|
||||||
for file in listdir(getcwd()+"/stories"):
|
for file in listdir(path.dirname(path.realpath(__file__))+"/stories"):
|
||||||
if file.endswith(".json"):
|
if file.endswith(".json"):
|
||||||
ob = {}
|
ob = {}
|
||||||
ob["name"] = file.replace(".json", "")
|
ob["name"] = file.replace(".json", "")
|
||||||
f = open(getcwd()+"/stories/"+file, "r")
|
f = open(path.dirname(path.realpath(__file__))+"/stories/"+file, "r")
|
||||||
js = json.load(f)
|
try:
|
||||||
|
js = json.load(f)
|
||||||
|
except:
|
||||||
|
print(f"Browser loading error: {file} is malformed or not a JSON file.")
|
||||||
|
f.close()
|
||||||
|
continue
|
||||||
f.close()
|
f.close()
|
||||||
ob["actions"] = len(js["actions"])
|
try:
|
||||||
|
ob["actions"] = len(js["actions"])
|
||||||
|
except TypeError:
|
||||||
|
print(f"Browser loading error: {file} has incorrect format.")
|
||||||
|
continue
|
||||||
list.append(ob)
|
list.append(ob)
|
||||||
return list
|
return list
|
||||||
|
|
||||||
|
@ -74,4 +83,4 @@ def getstoryfiles():
|
||||||
# Returns True if json file exists with requested save name
|
# Returns True if json file exists with requested save name
|
||||||
#==================================================================#
|
#==================================================================#
|
||||||
def saveexists(name):
|
def saveexists(name):
|
||||||
return path.exists(getcwd()+"/stories/"+name+".json")
|
return path.exists(path.dirname(path.realpath(__file__))+"/stories/"+name+".json")
|
||||||
|
|
|
@ -1107,11 +1107,13 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
button_actretry.on("click", function(ev) {
|
button_actretry.on("click", function(ev) {
|
||||||
|
hideMessage();
|
||||||
socket.send({'cmd': 'retry', 'data': ''});
|
socket.send({'cmd': 'retry', 'data': ''});
|
||||||
hidegenseqs();
|
hidegenseqs();
|
||||||
});
|
});
|
||||||
|
|
||||||
button_actback.on("click", function(ev) {
|
button_actback.on("click", function(ev) {
|
||||||
|
hideMessage();
|
||||||
socket.send({'cmd': 'back', 'data': ''});
|
socket.send({'cmd': 'back', 'data': ''});
|
||||||
hidegenseqs();
|
hidegenseqs();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue