Added saveas option for saving without metadata information

Fixed redo on an empty story erroring
Fixed redo when you're at the current end of a chain causing an error
This commit is contained in:
ebolam 2022-01-21 19:02:56 -05:00
parent d31fb278ce
commit 2010e7b9bc
3 changed files with 36 additions and 25 deletions

View File

@ -2555,16 +2555,19 @@ def actionback():
def actionredo():
i = 0
genout = [{"generated_text": item['Text']} for item in vars.actions_metadata[len(vars.actions)]['Alternative Text'] if (item["Previous Selection"]==True)]
# Store sequences in memory until selection is made
vars.genseqs = genout
# Send sequences to UI for selection
genout = [[item['Text'], True] for item in vars.actions_metadata[len(vars.actions)]['Alternative Text'] if (item["Previous Selection"]==True)]
emit('from_server', {'cmd': 'genseqs', 'data': genout}, broadcast=True)
if len(vars.actions) < len(vars.actions_metadata):
genout = [{"generated_text": item['Text']} for item in vars.actions_metadata[len(vars.actions)]['Alternative Text'] if (item["Previous Selection"]==True)]
genout = genout + [{"generated_text": item['Text']} for item in vars.actions_metadata[len(vars.actions)]['Alternative Text'] if (item["Pinned"]==True) and (item["Previous Selection"]==False)]
# Store sequences in memory until selection is made
vars.genseqs = genout
# Send sequences to UI for selection
genout = [[item['Text'], True] for item in vars.actions_metadata[len(vars.actions)]['Alternative Text'] if (item["Previous Selection"]==True)]
emit('from_server', {'cmd': 'genseqs', 'data': genout}, broadcast=True)
else:
emit('from_server', {'cmd': 'popuperror', 'data': "There's nothing to undo"}, broadcast=True)
#==================================================================#
#
@ -2996,7 +2999,7 @@ def genselect(genout):
vars.genseqs = genout
genout = [[item['Text'], item['Pinned']] for item in vars.actions_metadata[len(vars.actions)]['Alternative Text'] if (item["Previous Selection"]==False) and (item["Edited"]==False)]
print(genout)
# Send sequences to UI for selection
emit('from_server', {'cmd': 'genseqs', 'data': genout}, broadcast=True)
@ -3995,12 +3998,15 @@ def exitModes():
#==================================================================#
# Launch in-browser save prompt
#==================================================================#
def saveas(name):
def saveas(data):
name = data['name']
savepins = data['pins']
# Check if filename exists already
name = utils.cleanfilename(name)
if(not fileops.saveexists(name) or (vars.saveow and vars.svowname == name)):
# All clear to save
e = saveRequest(fileops.storypath(name))
e = saveRequest(fileops.storypath(name), savepins=savepins)
vars.saveow = False
vars.svowname = ""
if(e is None):
@ -4076,7 +4082,7 @@ def savetofile():
#==================================================================#
# Save the story to specified path
#==================================================================#
def saveRequest(savpath):
def saveRequest(savpath, savepins=True):
if(savpath):
# Leave Edit/Memory mode before continuing
exitModes()
@ -4092,7 +4098,8 @@ def saveRequest(savpath):
js["authorsnote"] = vars.authornote
js["anotetemplate"] = vars.authornotetemplate
js["actions"] = tuple(vars.actions.values())
js["actions_metadata"] = vars.actions_metadata
if savepins:
js["actions_metadata"] = vars.actions_metadata
js["worldinfo"] = []
js["wifolders_d"] = vars.wifolders_d
js["wifolders_l"] = vars.wifolders_l

View File

@ -50,6 +50,7 @@ var aidg_accept;
var aidg_close;
var saveaspopup;
var saveasinput;
var savepins;
var topic;
var saveas_accept;
var saveas_close;
@ -749,7 +750,7 @@ function enterMemoryMode() {
setchatnamevisibility(false);
showMessage("Edit the memory to be sent with each request to the AI.");
button_actmem.html("Cancel");
hide([button_actback, button_actretry, button_actwi]);
hide([button_actback, button_actfwd, button_actretry, button_actwi]);
// Display Author's Note field
anote_menu.slideDown("fast");
}
@ -760,7 +761,7 @@ function exitMemoryMode() {
setchatnamevisibility(chatmode);
hideMessage();
button_actmem.html("Memory");
show([button_actback, button_actretry, button_actwi]);
show([button_actback, button_actfwd, button_actretry, button_actwi]);
input_text.val("");
// Hide Author's Note field
anote_menu.slideUp("fast");
@ -769,7 +770,7 @@ function exitMemoryMode() {
function enterWiMode() {
showMessage("World Info will be added to memory only when the key appears in submitted text or the last action.");
button_actwi.html("Accept");
hide([button_actback, button_actmem, button_actretry, game_text]);
hide([button_actback, button_actfwd, button_actmem, button_actretry, game_text]);
setchatnamevisibility(false);
show([wi_menu]);
disableSendBtn();
@ -781,7 +782,7 @@ function exitWiMode() {
button_actwi.html("W Info");
hide([wi_menu]);
setchatnamevisibility(chatmode);
show([button_actback, button_actmem, button_actretry, game_text]);
show([button_actback, button_actfwd, button_actmem, button_actretry, game_text]);
enableSendBtn();
$("#gamescreen").removeClass("wigamescreen");
}
@ -885,7 +886,7 @@ function hideSaveAsPopup() {
}
function sendSaveAsRequest() {
socket.send({'cmd': 'saveasrequest', 'data': saveasinput.val()});
socket.send({'cmd': 'saveasrequest', 'data': {"name": saveasinput.val(), "pins": savepins.val()});
}
function showLoadPopup() {
@ -1143,9 +1144,9 @@ function updateSPStatItems(items) {
function setStartState() {
enableSendBtn();
enableButtons([button_actmem, button_actwi]);
disableButtons([button_actback, button_actretry]);
disableButtons([button_actback, button_actfwd, button_actretry]);
hide([wi_menu]);
show([game_text, button_actmem, button_actwi, button_actback, button_actretry]);
show([game_text, button_actmem, button_actwi, button_actback, button_actfwd, button_actretry]);
hideMessage();
hideWaitAnimation();
button_actmem.html("Memory");
@ -1784,6 +1785,7 @@ $(document).ready(function(){
aidg_close = $("#btn_aidgpopupclose");
saveaspopup = $("#saveascontainer");
saveasinput = $("#savename");
savepins = $("#savepins");
topic = $("#topic");
saveas_accept = $("#btn_saveasaccept");
saveas_close = $("#btn_saveasclose");
@ -1932,13 +1934,13 @@ $(document).ready(function(){
// Enable or Disable buttons
if(msg.data == "ready") {
enableSendBtn();
enableButtons([button_actmem, button_actwi, button_actback, button_actretry]);
enableButtons([button_actmem, button_actwi, button_actback, button_actfwd, button_actretry]);
hideWaitAnimation();
gamestate = "ready";
} else if(msg.data == "wait") {
gamestate = "wait";
disableSendBtn();
disableButtons([button_actmem, button_actwi, button_actback, button_actretry]);
disableButtons([button_actmem, button_actwi, button_actback, button_actfwd, button_actretry]);
showWaitAnimation();
} else if(msg.data == "start") {
setStartState();

View File

@ -229,7 +229,9 @@
<div class="popuptitletext">Enter Name For Save</div>
</div>
<div class="aidgpopupcontent">
<input class="form-control" type="text" placeholder="Save Name" id="savename">
<input class="form-control" type="text" placeholder="Save Name" id="savename"><br>
<input type="checkbox" data-toggle="toggle" data-onstyle="success" id="savepins" checked>
<div class="box-label">Save Pin Information</div>
</div>
<div class="popuperror hidden">
<span></span>