diff --git a/aiserver.py b/aiserver.py index ba583480..cb282e5b 100644 --- a/aiserver.py +++ b/aiserver.py @@ -6,6 +6,7 @@ # External packages from os import path, getcwd +import re import tkinter as tk from tkinter import messagebox import json @@ -96,6 +97,10 @@ class vars: saveow = False # Whether or not overwrite confirm has been displayed genseqs = [] # Temporary storage for generated sequences useprompt = True # Whether to send the full prompt with every submit action + acregex_ai = re.compile(r'\n* *>(.|\n)*') # Pattern for matching adventure actions from the AI so we can remove them + acregex_ui = re.compile(r'^ *(>.*)$', re.MULTILINE) # Pattern for matching actions in the HTML-escaped story so we can apply colouring, etc (make sure to encase part to format in parentheses) + actionmode = 1 + adventure = False #==================================================================# # Function to get model selection at startup @@ -399,7 +404,7 @@ def get_message(msg): # Submit action if(msg['cmd'] == 'submit'): if(vars.mode == "play"): - actionsubmit(msg['data']) + actionsubmit(msg['data'], actionmode=msg['actionmode']) elif(vars.mode == "edit"): editsubmit(msg['data']) elif(vars.mode == "memory"): @@ -531,6 +536,10 @@ def get_message(msg): elif(msg['cmd'] == 'setuseprompt'): vars.useprompt = msg['data'] settingschanged() + elif(msg['cmd'] == 'setadventure'): + vars.adventure = msg['data'] + settingschanged() + refresh_story() elif(msg['cmd'] == 'importwi'): wiimportrequest() @@ -543,7 +552,7 @@ def setStartState(): txt = txt + "Please load a game or enter a prompt below to begin!" else: txt = txt + "Please load or import a story to read. There is no AI in this mode." - emit('from_server', {'cmd': 'updatescreen', 'data': txt}) + emit('from_server', {'cmd': 'updatescreen', 'gamestarted': vars.gamestarted, 'data': txt}) emit('from_server', {'cmd': 'setgamestate', 'data': 'start'}) #==================================================================# @@ -583,6 +592,7 @@ def savesettings(): js["numseqs"] = vars.numseqs js["widepth"] = vars.widepth js["useprompt"] = vars.useprompt + js["adventure"] = vars.adventure # Write it file = open("client.settings", "w") @@ -625,6 +635,8 @@ def loadsettings(): vars.widepth = js["widepth"] if("useprompt" in js): vars.useprompt = js["useprompt"] + if("adventure" in js): + vars.adventure = js["adventure"] file.close() @@ -639,11 +651,19 @@ def settingschanged(): #==================================================================# # Take input text from SocketIO and decide what to do with it #==================================================================# -def actionsubmit(data): +def actionsubmit(data, actionmode=0): # Ignore new submissions if the AI is currently busy if(vars.aibusy): return set_aibusy(1) + + vars.actionmode = actionmode + + # "Action" mode + if(actionmode == 1): + data = data.strip().lstrip('>') + data = re.sub(r'\n+', ' ', data) + data = f"\n\n> {data}\n" # If we're not continuing, store a copy of the raw input if(data != ""): @@ -656,7 +676,7 @@ def actionsubmit(data): vars.prompt = data if(not vars.noai): # Clear the startup text from game screen - emit('from_server', {'cmd': 'updatescreen', 'data': 'Please wait, generating story...'}) + emit('from_server', {'cmd': 'updatescreen', 'gamestarted': vars.gamestarted, 'data': 'Please wait, generating story...'}) calcsubmit(data) # Run the first action through the generator else: refresh_story() @@ -665,7 +685,8 @@ def actionsubmit(data): # Dont append submission if it's a blank/continue action if(data != ""): # Apply input formatting & scripts before sending to tokenizer - data = applyinputformatting(data) + if(vars.actionmode == 0): + data = applyinputformatting(data) # Store the result in the Action log vars.actions.append(data) @@ -1076,6 +1097,10 @@ def applyinputformatting(txt): def applyoutputformatting(txt): # Use standard quotes and apostrophes txt = utils.fixquotes(txt) + + # Adventure mode clipping of all characters after '>' + if(vars.adventure): + txt = vars.acregex_ai.sub('', txt) # Trim incomplete sentences if(vars.formatoptns["frmttriminc"]): @@ -1085,7 +1110,7 @@ def applyoutputformatting(txt): txt = utils.replaceblanklines(txt) # Remove special characters if(vars.formatoptns["frmtrmspch"]): - txt = utils.removespecialchars(txt) + txt = utils.removespecialchars(txt, vars) return txt @@ -1095,8 +1120,10 @@ def applyoutputformatting(txt): def refresh_story(): text_parts = ['', html.escape(vars.prompt), ''] for idx, item in enumerate(vars.actions, start=1): - text_parts.extend(('', html.escape(item), '')) - emit('from_server', {'cmd': 'updatescreen', 'data': formatforhtml(''.join(text_parts))}) + if vars.adventure: # Add special formatting to adventure actions + item = vars.acregex_ui.sub('\\1', html.escape(item)) + text_parts.extend(('', item, '')) + emit('from_server', {'cmd': 'updatescreen', 'gamestarted': vars.gamestarted, 'data': formatforhtml(''.join(text_parts))}) #==================================================================# # Sends the current generator settings to the Game Menu @@ -1120,6 +1147,7 @@ def refresh_settings(): emit('from_server', {'cmd': 'updateanotedepth', 'data': vars.andepth}) emit('from_server', {'cmd': 'updatewidepth', 'data': vars.widepth}) emit('from_server', {'cmd': 'updateuseprompt', 'data': vars.useprompt}) + emit('from_server', {'cmd': 'updateadventure', 'data': vars.adventure}) emit('from_server', {'cmd': 'updatefrmttriminc', 'data': vars.formatoptns["frmttriminc"]}) emit('from_server', {'cmd': 'updatefrmtrmblln', 'data': vars.formatoptns["frmtrmblln"]}) @@ -1820,5 +1848,5 @@ if __name__ == "__main__": # Start Flask/SocketIO (Blocking, so this must be last method!) print("{0}Server started!\rYou may now connect with a browser at http://127.0.0.1:5000/{1}".format(colors.GREEN, colors.END)) - socketio.run(app, host='0.0.0.0', port=5000) - #socketio.run(app) + #socketio.run(app, host='0.0.0.0', port=5000) + socketio.run(app) diff --git a/gensettings.py b/gensettings.py index eb914139..da3aaa76 100644 --- a/gensettings.py +++ b/gensettings.py @@ -85,6 +85,17 @@ gensettingstf = [{ "step": 1, "default": 1, "tooltip": "Whether the prompt should be sent in the context of every action." + }, + { + "uitype": "toggle", + "unit": "bool", + "label": "Adventure Mode", + "id": "setadventure", + "min": 0, + "max": 1, + "step": 1, + "default": 0, + "tooltip": "Turn this on if you are playing a Choose your Adventure model." }] gensettingsik =[{ @@ -141,6 +152,17 @@ gensettingsik =[{ "step": 1, "default": 1, "tooltip": "Whether the prompt should be sent in the context of every action." + }, + { + "uitype": "toggle", + "unit": "bool", + "label": "Adventure Mode", + "id": "setadventure", + "min": 0, + "max": 1, + "step": 1, + "default": 0, + "tooltip": "Turn this on if you are playing a Choose your Adventure model." }] formatcontrols = [{ diff --git a/readme.txt b/readme.txt index 9ab782bb..7b4d93c4 100644 --- a/readme.txt +++ b/readme.txt @@ -1,6 +1,13 @@ This branch will eventually be used for a community edition of KoboldAI, uniting the different community made editions. -For now it is a WIP branch with Random Story Generation and better default settings. +For now it is a WIP branch as I integrate the community features. +Once done i will be replacing this with a better page describing KoboldAI. --- Looking for ColabKobold? Check the different branches on my account. + +--- +Contains work from : +- All the original KoboldAI creators +- Henky!! (Random Story Generator / Setting Optimizations) +- VE_FORBRYDERNE (Adventure Mode) \ No newline at end of file diff --git a/static/application - Copy.js b/static/application - Copy.js deleted file mode 100644 index 71c066d4..00000000 --- a/static/application - Copy.js +++ /dev/null @@ -1,981 +0,0 @@ -//=================================================================// -// VARIABLES -//=================================================================// - -// Socket IO Object -var socket; - -// UI references for jQuery -var connect_status; -var button_newgame; -var button_rndgame; -var button_save; -var button_saveas; -var button_savetofile; -var button_load; -var button_import; -var button_importwi; -var button_impaidg; -var button_settings; -var button_format; -var button_send; -var button_actedit; -var button_actmem; -var button_actback; -var button_actretry; -var button_delete; -var button_actwi; -var game_text; -var input_text; -var message_text; -var settings_menu; -var format_menu; -var wi_menu; -var anote_menu; -var anote_input; -var anote_labelcur; -var anote_slider; -var popup; -var popup_title; -var popup_content; -var popup_accept; -var popup_close; -var aidgpopup; -var aidgpromptnum; -var aidg_accept; -var aidg_close; -var saveaspopup; -var saveasinput; -var saveas_accept; -var saveas_close; -var saveasoverwrite; -var loadpopup; -var loadcontent; -var load_accept; -var load_close; -var nspopup; -var ns_accept; -var ns_close; -var rspopup; -var rs_accept; -var rs_close; -var seqselmenu; -var seqselcontents; - -// Key states -var shift_down = false; -var do_clear_ent = false; - -// Display vars -var allowtoggle = false; -var formatcount = 0; - -//=================================================================// -// METHODS -//=================================================================// - -function addSetting(ob) { - // Add setting block to Settings Menu - if(ob.uitype == "slider"){ - settings_menu.append("
\ -
\ -
\ - "+ob.label+" ?"+ob.tooltip+"\ -
\ -
\ - "+ob.default+"\ -
\ -
\ -
\ - \ -
\ -
\ -
\ - "+ob.min+"\ -
\ -
\ - "+ob.max+"\ -
\ -
\ -
"); - // Set references to HTML objects - var refin = $("#"+ob.id); - var reflb = $("#"+ob.id+"cur"); - window["setting_"+ob.id] = refin; // Is this still needed? - window["label_"+ob.id] = reflb; // Is this still needed? - // Add event function to input - refin.on("input", function () { - socket.send({'cmd': $(this).attr('id'), 'data': $(this).val()}); - }); - } else if(ob.uitype == "toggle"){ - settings_menu.append("
\ - \ - "+ob.label+" \ - ?"+ob.tooltip+"\ -
"); - // Tell Bootstrap-Toggle to render the new checkbox - $("input[type=checkbox]").bootstrapToggle(); - $("#"+ob.id).on("change", function () { - if(allowtoggle) { - socket.send({'cmd': $(this).attr('id'), 'data': $(this).prop('checked')}); - } - }); - } -} - -function addFormat(ob) { - // Check if we need to make a new column for this button - if(formatcount == 0) { - format_menu.append("
"); - } - // Get reference to the last child column - var ref = $("#formatmenu > div").last(); - // Add format block to Format Menu - ref.append("
\ - \ - "+ob.label+" \ - ?"+ob.tooltip+"\ -
"); - // Tell Bootstrap-Toggle to render the new checkbox - $("input[type=checkbox]").bootstrapToggle(); - // Add event to input - $("#"+ob.id).on("change", function () { - if(allowtoggle) { - socket.send({'cmd': $(this).attr('id'), 'data': $(this).prop('checked')}); - } - }); - // Increment display variable - formatcount++; - if(formatcount == 2) { - formatcount = 0; - } -} - -function addImportLine(ob) { - popup_content.append("
\ -
"+ob.title+"
\ -
"+ob.acts+"
\ -
"+ob.descr+"
\ -
"); - $("#import"+ob.num).on("click", function () { - socket.send({'cmd': 'importselect', 'data': $(this).attr('id')}); - highlightImportLine($(this)); - }); -} - -function addWiLine(ob) { - if(ob.init) { - wi_menu.append("
\ -
\ - \ - \ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
"); - // Send key value to text input - $("#wikey"+ob.num).val(ob.key); - // Assign delete event to button - $("#btn_wi"+ob.num).on("click", function () { - showWiDeleteConfirm(ob.num); - }); - } else { - // Show WI line item with form fields hidden (uninitialized) - wi_menu.append("
\ -
\ - \ - \ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
"); - // Assign function to expand WI item to button - $("#btn_wi"+ob.num).on("click", function () { - expandWiLine(ob.num); - }); - } - // Assign actions to other elements - $("#btn_wican"+ob.num).on("click", function () { - hideWiDeleteConfirm(ob.num); - }); - $("#btn_widel"+ob.num).on("click", function () { - socket.send({'cmd': 'widelete', 'data': ob.num}); - }); -} - -function expandWiLine(num) { - show([$("#wikey"+num), $("#wientry"+num)]); - $("#btn_wi"+num).html("X"); - $("#btn_wi"+num).off(); - // Tell server the WI entry was initialized - socket.send({'cmd': 'wiinit', 'data': num}); - $("#btn_wi"+num).on("click", function () { - showWiDeleteConfirm(num); - }); -} - -function showWiDeleteConfirm(num) { - hide([$("#btn_wi"+num)]); - show([$("#btn_widel"+num), $("#btn_wican"+num)]); -} - -function hideWiDeleteConfirm(num) { - show([$("#btn_wi"+num)]); - hide([$("#btn_widel"+num), $("#btn_wican"+num)]); -} - -function highlightImportLine(ref) { - $("#popupcontent > div").removeClass("popuplistselected"); - ref.addClass("popuplistselected"); - enableButtons([popup_accept]); -} - -function enableButtons(refs) { - for(i=0; i"); -} - -function hideWaitAnimation() { - $('#waitanim').remove(); -} - -function hide(refs) { - for(i=0; i *', function() { - editModeSelect($(this).attr("n")); - }); - disableSendBtn(); - hide([button_actback, button_actmem, button_actretry, button_actwi]); - show([button_delete]); -} - -function exitEditMode() { - // Remove class to each story chunk - hideMessage(); - button_actedit.html("Edit"); - game_text.children('chunk').removeClass("chunkhov"); - game_text.off('click', '> *'); - enableSendBtn(); - show([button_actback, button_actmem, button_actretry, button_actwi]); - hide([button_delete]); - input_text.val(""); -} - -function editModeSelect(n) { - socket.send({'cmd': 'editline', 'data': n}); -} - -function enterMemoryMode() { - showMessage("Edit the memory to be sent with each request to the AI."); - button_actmem.html("Cancel"); - hide([button_actback, button_actretry, button_actedit, button_delete, button_actwi]); - // Display Author's Note field - anote_menu.slideDown("fast"); -} - -function exitMemoryMode() { - hideMessage(); - button_actmem.html("Memory"); - show([button_actback, button_actretry, button_actedit, button_actwi]); - input_text.val(""); - // Hide Author's Note field - anote_menu.slideUp("fast"); -} - -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_actedit, button_actback, button_actmem, button_actretry, game_text]); - show([wi_menu]); - disableSendBtn(); -} - -function exitWiMode() { - hideMessage(); - button_actwi.html("W Info"); - hide([wi_menu]); - show([button_actedit, button_actback, button_actmem, button_actretry, game_text]); - enableSendBtn(); -} - -function returnWiList(ar) { - var list = []; - var i; - for(i=0; i\ -
"+ar[i].name+"
\ -
"+ar[i].actions+"
\ - "); - $("#load"+i).on("click", function () { - enableButtons([load_accept]); - socket.send({'cmd': 'loadselect', 'data': $(this).attr("name")}); - highlightLoadLine($(this)); - }); - } -} - -function highlightLoadLine(ref) { - $("#loadlistcontent > div").removeClass("popuplistselected"); - ref.addClass("popuplistselected"); -} - -function showNewStoryPopup() { - nspopup.removeClass("hidden"); - nspopup.addClass("flex"); -} - -function hideNewStoryPopup() { - nspopup.removeClass("flex"); - nspopup.addClass("hidden"); -} - -function showRandomStoryPopup() { - rspopup.removeClass("hidden"); - rspopup.addClass("flex"); -} - -function hideRandomStoryPopup() { - rspopup.removeClass("flex"); - rspopup.addClass("hidden"); -} - -function setStartState() { - enableSendBtn(); - enableButtons([button_actmem, button_actwi]); - disableButtons([button_actedit, button_actback, button_actretry]); - hide([wi_menu, button_delete]); - show([game_text, button_actedit, button_actmem, button_actwi, button_actback, button_actretry]); - hideMessage(); - hideWaitAnimation(); - button_actedit.html("Edit"); - button_actmem.html("Memory"); - button_actwi.html("W Info"); - hideAidgPopup(); - hideSaveAsPopup(); - hideLoadPopup(); - hideNewStoryPopup(); - hidegenseqs(); -} - -function parsegenseqs(seqs) { - seqselcontents.html(""); - var i; - for(i=0; i"+seqs[i].generated_text+""); - $("#seqsel"+i).on("click", function () { - socket.send({'cmd': 'seqsel', 'data': $(this).attr("n")}); - }); - } - $('#seqselmenu').slideDown("slow"); -} - -function hidegenseqs() { - $('#seqselmenu').slideUp("slow", function() { - seqselcontents.html(""); - }); -} - -//=================================================================// -// READY/RUNTIME -//=================================================================// - -$(document).ready(function(){ - - // Bind UI references - connect_status = $('#connectstatus'); - button_newgame = $('#btn_newgame'); - button_rndgame = $('#btn_rndgame'); - button_save = $('#btn_save'); - button_saveas = $('#btn_saveas'); - button_savetofile = $('#btn_savetofile'); - button_load = $('#btn_load'); - button_loadfrfile = $('#btn_loadfromfile'); - button_import = $("#btn_import"); - button_importwi = $("#btn_importwi"); - button_impaidg = $("#btn_impaidg"); - button_settings = $('#btn_settings'); - button_format = $('#btn_format'); - button_send = $('#btnsend'); - button_actedit = $('#btn_actedit'); - button_actmem = $('#btn_actmem'); - button_actback = $('#btn_actundo'); - button_actretry = $('#btn_actretry'); - button_delete = $('#btn_delete'); - button_actwi = $('#btn_actwi'); - game_text = $('#gametext'); - input_text = $('#input_text'); - message_text = $('#messagefield'); - settings_menu = $("#settingsmenu"); - format_menu = $('#formatmenu'); - anote_menu = $('#anoterowcontainer'); - wi_menu = $('#wimenu'); - anote_input = $('#anoteinput'); - anote_labelcur = $('#anotecur'); - anote_slider = $('#anotedepth'); - popup = $("#popupcontainer"); - popup_title = $("#popuptitletext"); - popup_content = $("#popupcontent"); - popup_accept = $("#btn_popupaccept"); - popup_close = $("#btn_popupclose"); - aidgpopup = $("#aidgpopupcontainer"); - aidgpromptnum = $("#aidgpromptnum"); - aidg_accept = $("#btn_aidgpopupaccept"); - aidg_close = $("#btn_aidgpopupclose"); - saveaspopup = $("#saveascontainer"); - saveasinput = $("#savename"); - saveas_accept = $("#btn_saveasaccept"); - saveas_close = $("#btn_saveasclose"); - saveasoverwrite = $("#saveasoverwrite"); - loadpopup = $("#loadcontainer"); - loadcontent = $("#loadlistcontent"); - load_accept = $("#btn_loadaccept"); - load_close = $("#btn_loadclose"); - nspopup = $("#newgamecontainer"); - ns_accept = $("#btn_nsaccept"); - ns_close = $("#btn_nsclose"); - rspopup = $("#rndgamecontainer"); - rs_accept = $("#btn_rsaccept"); - rs_close = $("#btn_rsclose"); - seqselmenu = $("#seqselmenu"); - seqselcontents = $("#seqselcontents"); - - // Connect to SocketIO server - loc = window.document.location; - socket = io.connect(loc.href); - - socket.on('from_server', function(msg) { - if(msg.cmd == "connected") { - // Connected to Server Actions - connect_status.html("Connected to KoboldAI Process!"); - connect_status.removeClass("color_orange"); - connect_status.addClass("color_green"); - // Reset Menus - settings_menu.html(""); - format_menu.html(""); - wi_menu.html(""); - } else if(msg.cmd == "updatescreen") { - // Send game content to Game Screen - game_text.html(msg.data); - // Scroll to bottom of text - setTimeout(function () { - $('#gamescreen').animate({scrollTop: $('#gamescreen').prop('scrollHeight')}, 1000); - }, 5); - } else if(msg.cmd == "setgamestate") { - // Enable or Disable buttons - if(msg.data == "ready") { - enableSendBtn(); - enableButtons([button_actedit, button_actmem, button_actwi, button_actback, button_actretry]); - hideWaitAnimation(); - } else if(msg.data == "wait") { - disableSendBtn(); - disableButtons([button_actedit, button_actmem, button_actwi, button_actback, button_actretry]); - showWaitAnimation(); - } else if(msg.data == "start") { - setStartState(); - } - } else if(msg.cmd == "editmode") { - // Enable or Disable edit mode - if(msg.data == "true") { - enterEditMode(); - } else { - exitEditMode(); - } - } else if(msg.cmd == "setinputtext") { - // Set input box text for edit mode - input_text.val(msg.data); - } else if(msg.cmd == "enablesubmit") { - // Enables the submit button - enableSendBtn(); - } else if(msg.cmd == "memmode") { - // Enable or Disable memory edit mode - if(msg.data == "true") { - enterMemoryMode(); - } else { - exitMemoryMode(); - } - } else if(msg.cmd == "errmsg") { - // Send error message - errMessage(msg.data); - } else if(msg.cmd == "texteffect") { - // Apply color highlight to line of text - newTextHighlight($("#n"+msg.data)) - } else if(msg.cmd == "updatetemp") { - // Send current temp value to input - $("#settemp").val(parseFloat(msg.data)); - $("#settempcur").html(msg.data); - } else if(msg.cmd == "updatetopp") { - // Send current top p value to input - $("#settopp").val(parseFloat(msg.data)); - $("#settoppcur").html(msg.data); - } else if(msg.cmd == "updatereppen") { - // Send current rep pen value to input - $("#setreppen").val(parseFloat(msg.data)); - $("#setreppencur").html(msg.data); - } else if(msg.cmd == "updateoutlen") { - // Send current output amt value to input - $("#setoutput").val(parseInt(msg.data)); - $("#setoutputcur").html(msg.data); - } else if(msg.cmd == "updatetknmax") { - // Send current max tokens value to input - $("#settknmax").val(parseInt(msg.data)); - $("#settknmaxcur").html(msg.data); - } else if(msg.cmd == "updateikgen") { - // Send current max tokens value to input - $("#setikgen").val(parseInt(msg.data)); - $("#setikgencur").html(msg.data); - } else if(msg.cmd == "setlabeltemp") { - // Update setting label with value from server - $("#settempcur").html(msg.data); - } else if(msg.cmd == "setlabeltopp") { - // Update setting label with value from server - $("#settoppcur").html(msg.data); - } else if(msg.cmd == "setlabelreppen") { - // Update setting label with value from server - $("#setreppencur").html(msg.data); - } else if(msg.cmd == "setlabeloutput") { - // Update setting label with value from server - $("#setoutputcur").html(msg.data); - } else if(msg.cmd == "setlabeltknmax") { - // Update setting label with value from server - $("#settknmaxcur").html(msg.data); - } else if(msg.cmd == "setlabelikgen") { - // Update setting label with value from server - $("#setikgencur").html(msg.data); - } else if(msg.cmd == "updateanotedepth") { - // Send current Author's Note depth value to input - anote_slider.val(parseInt(msg.data)); - anote_labelcur.html(msg.data); - } else if(msg.cmd == "setlabelanotedepth") { - // Update setting label with value from server - anote_labelcur.html(msg.data); - } else if(msg.cmd == "getanote") { - // Request contents of Author's Note field - var txt = anote_input.val(); - socket.send({'cmd': 'anote', 'data': txt}); - } else if(msg.cmd == "setanote") { - // Set contents of Author's Note field - anote_input.val(msg.data); - } else if(msg.cmd == "addsetting") { - // Add setting controls - addSetting(msg.data); - } else if(msg.cmd == "addformat") { - // Add setting controls - addFormat(msg.data); - } else if(msg.cmd == "updatefrmttriminc") { - // Update toggle state - $("#frmttriminc").prop('checked', msg.data).change(); - } else if(msg.cmd == "updatefrmtrmblln") { - // Update toggle state - $("#frmtrmblln").prop('checked', msg.data).change(); - } else if(msg.cmd == "updatefrmtrmspch") { - // Update toggle state - $("#frmtrmspch").prop('checked', msg.data).change(); - } else if(msg.cmd == "updatefrmtadsnsp") { - // Update toggle state - $("#frmtadsnsp").prop('checked', msg.data).change(); - } else if(msg.cmd == "allowtoggle") { - // Allow toggle change states to propagate - allowtoggle = msg.data; - } else if(msg.cmd == "popupshow") { - // Show/Hide Popup - popupShow(msg.data); - } else if(msg.cmd == "addimportline") { - // Add import popup entry - addImportLine(msg.data); - } else if(msg.cmd == "clearpopup") { - // Clear previous contents of popup - popup_content.html(""); - } else if(msg.cmd == "wimode") { - // Enable or Disable WI edit mode - if(msg.data == "true") { - enterWiMode(); - } else { - exitWiMode(); - } - } else if(msg.cmd == "addwiitem") { - // Add WI entry to WI Menu - addWiLine(msg.data); - } else if(msg.cmd == "clearwi") { - // Clear previous contents of WI list - wi_menu.html(""); - } else if(msg.cmd == "requestwiitem") { - // Package WI contents and send back to server - returnWiList(msg.data); - } else if(msg.cmd == "saveas") { - // Show Save As prompt - showSaveAsPopup(); - } else if(msg.cmd == "hidesaveas") { - // Hide Save As prompt - hideSaveAsPopup(); - } else if(msg.cmd == "buildload") { - // Send array of save files to load UI - buildLoadList(msg.data); - } else if(msg.cmd == "askforoverwrite") { - // Show overwrite warning - show([saveasoverwrite]); - } else if(msg.cmd == "genseqs") { - // Parse generator sequences to UI - parsegenseqs(msg.data); - } else if(msg.cmd == "hidegenseqs") { - // Collapse genseqs menu - hidegenseqs(); - } else if(msg.cmd == "setlabelnumseq") { - // Update setting label with value from server - $("#setnumseqcur").html(msg.data); - } else if(msg.cmd == "updatenumseq") { - // Send current max tokens value to input - $("#setnumseq").val(parseInt(msg.data)); - $("#setnumseqcur").html(msg.data); - } else if(msg.cmd == "setlabelwidepth") { - // Update setting label with value from server - $("#setwidepthcur").html(msg.data); - } else if(msg.cmd == "updatewidepth") { - // Send current max tokens value to input - $("#setwidepth").val(parseInt(msg.data)); - $("#setwidepthcur").html(msg.data); - } else if(msg.cmd == "updateuseprompt") { - // Update toggle state - $("#setuseprompt").prop('checked', msg.data).change(); - } - }); - - socket.on('disconnect', function() { - connect_status.html("Lost connection..."); - connect_status.removeClass("color_green"); - connect_status.addClass("color_orange"); - }); - - // Bind actions to UI buttons - button_send.on("click", function(ev) { - dosubmit(); - }); - - button_actretry.on("click", function(ev) { - socket.send({'cmd': 'retry', 'data': ''}); - hidegenseqs(); - }); - - button_actback.on("click", function(ev) { - socket.send({'cmd': 'back', 'data': ''}); - hidegenseqs(); - }); - - button_actedit.on("click", function(ev) { - socket.send({'cmd': 'edit', 'data': ''}); - }); - - button_delete.on("click", function(ev) { - socket.send({'cmd': 'delete', 'data': ''}); - }); - - button_actmem.on("click", function(ev) { - socket.send({'cmd': 'memory', 'data': ''}); - }); - - button_savetofile.on("click", function(ev) { - socket.send({'cmd': 'savetofile', 'data': ''}); - }); - - button_loadfrfile.on("click", function(ev) { - socket.send({'cmd': 'loadfromfile', 'data': ''}); - }); - - button_import.on("click", function(ev) { - socket.send({'cmd': 'import', 'data': ''}); - }); - - button_importwi.on("click", function(ev) { - socket.send({'cmd': 'importwi', 'data': ''}); - }); - - button_settings.on("click", function(ev) { - $('#settingsmenu').slideToggle("slow"); - }); - - button_format.on("click", function(ev) { - $('#formatmenu').slideToggle("slow"); - }); - - popup_close.on("click", function(ev) { - socket.send({'cmd': 'importcancel', 'data': ''}); - }); - - popup_accept.on("click", function(ev) { - socket.send({'cmd': 'importaccept', 'data': ''}); - }); - - button_actwi.on("click", function(ev) { - socket.send({'cmd': 'wi', 'data': ''}); - }); - - button_impaidg.on("click", function(ev) { - showAidgPopup(); - }); - - aidg_close.on("click", function(ev) { - hideAidgPopup(); - }); - - aidg_accept.on("click", function(ev) { - sendAidgImportRequest(); - }); - - button_save.on("click", function(ev) { - socket.send({'cmd': 'saverequest', 'data': ''}); - }); - - button_saveas.on("click", function(ev) { - showSaveAsPopup(); - }); - - saveas_close.on("click", function(ev) { - hideSaveAsPopup(); - socket.send({'cmd': 'clearoverwrite', 'data': ''}); - }); - - saveas_accept.on("click", function(ev) { - sendSaveAsRequest(); - }); - - button_load.on("click", function(ev) { - socket.send({'cmd': 'loadlistrequest', 'data': ''}); - }); - - load_close.on("click", function(ev) { - hideLoadPopup(); - }); - - load_accept.on("click", function(ev) { - socket.send({'cmd': 'loadrequest', 'data': ''}); - hideLoadPopup(); - }); - - button_newgame.on("click", function(ev) { - showNewStoryPopup(); - }); - - ns_accept.on("click", function(ev) { - socket.send({'cmd': 'newgame', 'data': ''}); - hideNewStoryPopup(); - }); - - ns_close.on("click", function(ev) { - hideNewStoryPopup(); - }); - - button_rndgame.on("click", function(ev) { - showRandomStoryPopup(); - }); - - rs_accept.on("click", function(ev) { - socket.send({'cmd': 'rndgame', 'data': ''}); - hideRandomStoryPopup(); - }); - - rs_close.on("click", function(ev) { - hideRandomStoryPopup(); - }); - - anote_slider.on("input", function () { - socket.send({'cmd': 'anotedepth', 'data': $(this).val()}); - }); - - saveasinput.on("input", function () { - if(saveasinput.val() == "") { - disableButtons([saveas_accept]); - } else { - enableButtons([saveas_accept]); - } - hide([saveasoverwrite]); - }); - - // Bind Enter button to submit - input_text.keydown(function (ev) { - if (ev.which == 13 && !shift_down) { - do_clear_ent = true; - dosubmit(); - } else if(ev.which == 16) { - shift_down = true; - } - }); - - // Enter to submit, but not if holding shift - input_text.keyup(function (ev) { - if (ev.which == 13 && do_clear_ent) { - input_text.val(""); - do_clear_ent = false; - } else if(ev.which == 16) { - shift_down = false; - } - }); - - aidgpromptnum.keydown(function (ev) { - if (ev.which == 13) { - sendAidgImportRequest(); - } - }); - - saveasinput.keydown(function (ev) { - if (ev.which == 13 && saveasinput.val() != "") { - sendSaveAsRequest(); - } - }); -}); - diff --git a/static/application.js b/static/application.js index 5a4a0086..5a01f289 100644 --- a/static/application.js +++ b/static/application.js @@ -18,6 +18,8 @@ var button_importwi; var button_impaidg; var button_settings; var button_format; +var button_mode; +var button_mode_label; var button_send; var button_actedit; var button_actmem; @@ -63,6 +65,9 @@ var rs_close; var seqselmenu; var seqselcontents; +var memorymode = false; +var gamestarted = false; + // Key states var shift_down = false; var do_clear_ent = false; @@ -71,6 +76,10 @@ var do_clear_ent = false; var allowtoggle = false; var formatcount = 0; +// Adventure +var action_mode = 0; // 0: story, 1: action +var adventure = false; + //=================================================================// // METHODS //=================================================================// @@ -120,6 +129,9 @@ function addSetting(ob) { if(allowtoggle) { socket.send({'cmd': $(this).attr('id'), 'data': $(this).prop('checked')}); } + if(ob.id == "setadventure"){ + setadventure($(this).prop('checked')); + } }); } } @@ -345,6 +357,8 @@ function editModeSelect(n) { } function enterMemoryMode() { + memorymode = true; + setmodevisibility(false); showMessage("Edit the memory to be sent with each request to the AI."); button_actmem.html("Cancel"); hide([button_actback, button_actretry, button_actedit, button_delete, button_actwi]); @@ -353,6 +367,8 @@ function enterMemoryMode() { } function exitMemoryMode() { + memorymode = false; + setmodevisibility(adventure); hideMessage(); button_actmem.html("Memory"); show([button_actback, button_actretry, button_actedit, button_actwi]); @@ -391,12 +407,26 @@ function returnWiList(ar) { function dosubmit() { var txt = input_text.val(); - socket.send({'cmd': 'submit', 'data': txt}); + socket.send({'cmd': 'submit', 'actionmode': adventure ? action_mode : 0, 'data': txt}); input_text.val(""); hideMessage(); hidegenseqs(); } +function changemode() { + if(gamestarted) { + action_mode += 1; + action_mode %= 2; // Total number of action modes (Story and Action) + } else { + action_mode = 0; // Force "Story" mode if game is not started + } + + switch (action_mode) { + case 0: button_mode_label.html("Story"); break; + case 1: button_mode_label.html("Action"); break; + } +} + function newTextHighlight(ref) { ref.addClass("color_green"); ref.addClass("colorfade"); @@ -533,6 +563,23 @@ function hidegenseqs() { }); } +function setmodevisibility(state) { + if(state){ // Enabling + show([button_mode]); + $("#inputrow").addClass("show_mode"); + } else{ // Disabling + hide([button_mode]); + $("#inputrow").removeClass("show_mode"); + } +} + +function setadventure(state) { + adventure = state; + if(!memorymode){ + setmodevisibility(state); + } +} + //=================================================================// // READY/RUNTIME //=================================================================// @@ -553,6 +600,8 @@ $(document).ready(function(){ button_impaidg = $("#btn_impaidg"); button_settings = $('#btn_settings'); button_format = $('#btn_format'); + button_mode = $('#btnmode') + button_mode_label = $('#btnmode_label') button_send = $('#btnsend'); button_actedit = $('#btn_actedit'); button_actmem = $('#btn_actmem'); @@ -613,6 +662,12 @@ $(document).ready(function(){ format_menu.html(""); wi_menu.html(""); } else if(msg.cmd == "updatescreen") { + _gamestarted = gamestarted + gamestarted = msg.gamestarted; + if(_gamestarted != gamestarted) { + action_mode = 0; + changemode(); + } // Send game content to Game Screen game_text.html(msg.data); // Scroll to bottom of text @@ -795,6 +850,11 @@ $(document).ready(function(){ } else if(msg.cmd == "updateuseprompt") { // Update toggle state $("#setuseprompt").prop('checked', msg.data).change(); + } else if(msg.cmd == "updateadventure") { + // Update toggle state + $("#setadventure").prop('checked', msg.data).change(); + // Update adventure state + setadventure(msg.data); } }); @@ -808,6 +868,10 @@ $(document).ready(function(){ button_send.on("click", function(ev) { dosubmit(); }); + + button_mode.on("click", function(ev) { + changemode(); + }); button_actretry.on("click", function(ev) { socket.send({'cmd': 'retry', 'data': ''}); diff --git a/static/application.js.bak b/static/application.js.bak deleted file mode 100644 index 71c066d4..00000000 --- a/static/application.js.bak +++ /dev/null @@ -1,981 +0,0 @@ -//=================================================================// -// VARIABLES -//=================================================================// - -// Socket IO Object -var socket; - -// UI references for jQuery -var connect_status; -var button_newgame; -var button_rndgame; -var button_save; -var button_saveas; -var button_savetofile; -var button_load; -var button_import; -var button_importwi; -var button_impaidg; -var button_settings; -var button_format; -var button_send; -var button_actedit; -var button_actmem; -var button_actback; -var button_actretry; -var button_delete; -var button_actwi; -var game_text; -var input_text; -var message_text; -var settings_menu; -var format_menu; -var wi_menu; -var anote_menu; -var anote_input; -var anote_labelcur; -var anote_slider; -var popup; -var popup_title; -var popup_content; -var popup_accept; -var popup_close; -var aidgpopup; -var aidgpromptnum; -var aidg_accept; -var aidg_close; -var saveaspopup; -var saveasinput; -var saveas_accept; -var saveas_close; -var saveasoverwrite; -var loadpopup; -var loadcontent; -var load_accept; -var load_close; -var nspopup; -var ns_accept; -var ns_close; -var rspopup; -var rs_accept; -var rs_close; -var seqselmenu; -var seqselcontents; - -// Key states -var shift_down = false; -var do_clear_ent = false; - -// Display vars -var allowtoggle = false; -var formatcount = 0; - -//=================================================================// -// METHODS -//=================================================================// - -function addSetting(ob) { - // Add setting block to Settings Menu - if(ob.uitype == "slider"){ - settings_menu.append("
\ -
\ -
\ - "+ob.label+" ?"+ob.tooltip+"\ -
\ -
\ - "+ob.default+"\ -
\ -
\ -
\ - \ -
\ -
\ -
\ - "+ob.min+"\ -
\ -
\ - "+ob.max+"\ -
\ -
\ -
"); - // Set references to HTML objects - var refin = $("#"+ob.id); - var reflb = $("#"+ob.id+"cur"); - window["setting_"+ob.id] = refin; // Is this still needed? - window["label_"+ob.id] = reflb; // Is this still needed? - // Add event function to input - refin.on("input", function () { - socket.send({'cmd': $(this).attr('id'), 'data': $(this).val()}); - }); - } else if(ob.uitype == "toggle"){ - settings_menu.append("
\ - \ - "+ob.label+" \ - ?"+ob.tooltip+"\ -
"); - // Tell Bootstrap-Toggle to render the new checkbox - $("input[type=checkbox]").bootstrapToggle(); - $("#"+ob.id).on("change", function () { - if(allowtoggle) { - socket.send({'cmd': $(this).attr('id'), 'data': $(this).prop('checked')}); - } - }); - } -} - -function addFormat(ob) { - // Check if we need to make a new column for this button - if(formatcount == 0) { - format_menu.append("
"); - } - // Get reference to the last child column - var ref = $("#formatmenu > div").last(); - // Add format block to Format Menu - ref.append("
\ - \ - "+ob.label+" \ - ?"+ob.tooltip+"\ -
"); - // Tell Bootstrap-Toggle to render the new checkbox - $("input[type=checkbox]").bootstrapToggle(); - // Add event to input - $("#"+ob.id).on("change", function () { - if(allowtoggle) { - socket.send({'cmd': $(this).attr('id'), 'data': $(this).prop('checked')}); - } - }); - // Increment display variable - formatcount++; - if(formatcount == 2) { - formatcount = 0; - } -} - -function addImportLine(ob) { - popup_content.append("
\ -
"+ob.title+"
\ -
"+ob.acts+"
\ -
"+ob.descr+"
\ -
"); - $("#import"+ob.num).on("click", function () { - socket.send({'cmd': 'importselect', 'data': $(this).attr('id')}); - highlightImportLine($(this)); - }); -} - -function addWiLine(ob) { - if(ob.init) { - wi_menu.append("
\ -
\ - \ - \ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
"); - // Send key value to text input - $("#wikey"+ob.num).val(ob.key); - // Assign delete event to button - $("#btn_wi"+ob.num).on("click", function () { - showWiDeleteConfirm(ob.num); - }); - } else { - // Show WI line item with form fields hidden (uninitialized) - wi_menu.append("
\ -
\ - \ - \ - \ -
\ -
\ - \ -
\ -
\ - \ -
\ -
"); - // Assign function to expand WI item to button - $("#btn_wi"+ob.num).on("click", function () { - expandWiLine(ob.num); - }); - } - // Assign actions to other elements - $("#btn_wican"+ob.num).on("click", function () { - hideWiDeleteConfirm(ob.num); - }); - $("#btn_widel"+ob.num).on("click", function () { - socket.send({'cmd': 'widelete', 'data': ob.num}); - }); -} - -function expandWiLine(num) { - show([$("#wikey"+num), $("#wientry"+num)]); - $("#btn_wi"+num).html("X"); - $("#btn_wi"+num).off(); - // Tell server the WI entry was initialized - socket.send({'cmd': 'wiinit', 'data': num}); - $("#btn_wi"+num).on("click", function () { - showWiDeleteConfirm(num); - }); -} - -function showWiDeleteConfirm(num) { - hide([$("#btn_wi"+num)]); - show([$("#btn_widel"+num), $("#btn_wican"+num)]); -} - -function hideWiDeleteConfirm(num) { - show([$("#btn_wi"+num)]); - hide([$("#btn_widel"+num), $("#btn_wican"+num)]); -} - -function highlightImportLine(ref) { - $("#popupcontent > div").removeClass("popuplistselected"); - ref.addClass("popuplistselected"); - enableButtons([popup_accept]); -} - -function enableButtons(refs) { - for(i=0; i"); -} - -function hideWaitAnimation() { - $('#waitanim').remove(); -} - -function hide(refs) { - for(i=0; i *', function() { - editModeSelect($(this).attr("n")); - }); - disableSendBtn(); - hide([button_actback, button_actmem, button_actretry, button_actwi]); - show([button_delete]); -} - -function exitEditMode() { - // Remove class to each story chunk - hideMessage(); - button_actedit.html("Edit"); - game_text.children('chunk').removeClass("chunkhov"); - game_text.off('click', '> *'); - enableSendBtn(); - show([button_actback, button_actmem, button_actretry, button_actwi]); - hide([button_delete]); - input_text.val(""); -} - -function editModeSelect(n) { - socket.send({'cmd': 'editline', 'data': n}); -} - -function enterMemoryMode() { - showMessage("Edit the memory to be sent with each request to the AI."); - button_actmem.html("Cancel"); - hide([button_actback, button_actretry, button_actedit, button_delete, button_actwi]); - // Display Author's Note field - anote_menu.slideDown("fast"); -} - -function exitMemoryMode() { - hideMessage(); - button_actmem.html("Memory"); - show([button_actback, button_actretry, button_actedit, button_actwi]); - input_text.val(""); - // Hide Author's Note field - anote_menu.slideUp("fast"); -} - -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_actedit, button_actback, button_actmem, button_actretry, game_text]); - show([wi_menu]); - disableSendBtn(); -} - -function exitWiMode() { - hideMessage(); - button_actwi.html("W Info"); - hide([wi_menu]); - show([button_actedit, button_actback, button_actmem, button_actretry, game_text]); - enableSendBtn(); -} - -function returnWiList(ar) { - var list = []; - var i; - for(i=0; i\ -
"+ar[i].name+"
\ -
"+ar[i].actions+"
\ - "); - $("#load"+i).on("click", function () { - enableButtons([load_accept]); - socket.send({'cmd': 'loadselect', 'data': $(this).attr("name")}); - highlightLoadLine($(this)); - }); - } -} - -function highlightLoadLine(ref) { - $("#loadlistcontent > div").removeClass("popuplistselected"); - ref.addClass("popuplistselected"); -} - -function showNewStoryPopup() { - nspopup.removeClass("hidden"); - nspopup.addClass("flex"); -} - -function hideNewStoryPopup() { - nspopup.removeClass("flex"); - nspopup.addClass("hidden"); -} - -function showRandomStoryPopup() { - rspopup.removeClass("hidden"); - rspopup.addClass("flex"); -} - -function hideRandomStoryPopup() { - rspopup.removeClass("flex"); - rspopup.addClass("hidden"); -} - -function setStartState() { - enableSendBtn(); - enableButtons([button_actmem, button_actwi]); - disableButtons([button_actedit, button_actback, button_actretry]); - hide([wi_menu, button_delete]); - show([game_text, button_actedit, button_actmem, button_actwi, button_actback, button_actretry]); - hideMessage(); - hideWaitAnimation(); - button_actedit.html("Edit"); - button_actmem.html("Memory"); - button_actwi.html("W Info"); - hideAidgPopup(); - hideSaveAsPopup(); - hideLoadPopup(); - hideNewStoryPopup(); - hidegenseqs(); -} - -function parsegenseqs(seqs) { - seqselcontents.html(""); - var i; - for(i=0; i"+seqs[i].generated_text+""); - $("#seqsel"+i).on("click", function () { - socket.send({'cmd': 'seqsel', 'data': $(this).attr("n")}); - }); - } - $('#seqselmenu').slideDown("slow"); -} - -function hidegenseqs() { - $('#seqselmenu').slideUp("slow", function() { - seqselcontents.html(""); - }); -} - -//=================================================================// -// READY/RUNTIME -//=================================================================// - -$(document).ready(function(){ - - // Bind UI references - connect_status = $('#connectstatus'); - button_newgame = $('#btn_newgame'); - button_rndgame = $('#btn_rndgame'); - button_save = $('#btn_save'); - button_saveas = $('#btn_saveas'); - button_savetofile = $('#btn_savetofile'); - button_load = $('#btn_load'); - button_loadfrfile = $('#btn_loadfromfile'); - button_import = $("#btn_import"); - button_importwi = $("#btn_importwi"); - button_impaidg = $("#btn_impaidg"); - button_settings = $('#btn_settings'); - button_format = $('#btn_format'); - button_send = $('#btnsend'); - button_actedit = $('#btn_actedit'); - button_actmem = $('#btn_actmem'); - button_actback = $('#btn_actundo'); - button_actretry = $('#btn_actretry'); - button_delete = $('#btn_delete'); - button_actwi = $('#btn_actwi'); - game_text = $('#gametext'); - input_text = $('#input_text'); - message_text = $('#messagefield'); - settings_menu = $("#settingsmenu"); - format_menu = $('#formatmenu'); - anote_menu = $('#anoterowcontainer'); - wi_menu = $('#wimenu'); - anote_input = $('#anoteinput'); - anote_labelcur = $('#anotecur'); - anote_slider = $('#anotedepth'); - popup = $("#popupcontainer"); - popup_title = $("#popuptitletext"); - popup_content = $("#popupcontent"); - popup_accept = $("#btn_popupaccept"); - popup_close = $("#btn_popupclose"); - aidgpopup = $("#aidgpopupcontainer"); - aidgpromptnum = $("#aidgpromptnum"); - aidg_accept = $("#btn_aidgpopupaccept"); - aidg_close = $("#btn_aidgpopupclose"); - saveaspopup = $("#saveascontainer"); - saveasinput = $("#savename"); - saveas_accept = $("#btn_saveasaccept"); - saveas_close = $("#btn_saveasclose"); - saveasoverwrite = $("#saveasoverwrite"); - loadpopup = $("#loadcontainer"); - loadcontent = $("#loadlistcontent"); - load_accept = $("#btn_loadaccept"); - load_close = $("#btn_loadclose"); - nspopup = $("#newgamecontainer"); - ns_accept = $("#btn_nsaccept"); - ns_close = $("#btn_nsclose"); - rspopup = $("#rndgamecontainer"); - rs_accept = $("#btn_rsaccept"); - rs_close = $("#btn_rsclose"); - seqselmenu = $("#seqselmenu"); - seqselcontents = $("#seqselcontents"); - - // Connect to SocketIO server - loc = window.document.location; - socket = io.connect(loc.href); - - socket.on('from_server', function(msg) { - if(msg.cmd == "connected") { - // Connected to Server Actions - connect_status.html("Connected to KoboldAI Process!"); - connect_status.removeClass("color_orange"); - connect_status.addClass("color_green"); - // Reset Menus - settings_menu.html(""); - format_menu.html(""); - wi_menu.html(""); - } else if(msg.cmd == "updatescreen") { - // Send game content to Game Screen - game_text.html(msg.data); - // Scroll to bottom of text - setTimeout(function () { - $('#gamescreen').animate({scrollTop: $('#gamescreen').prop('scrollHeight')}, 1000); - }, 5); - } else if(msg.cmd == "setgamestate") { - // Enable or Disable buttons - if(msg.data == "ready") { - enableSendBtn(); - enableButtons([button_actedit, button_actmem, button_actwi, button_actback, button_actretry]); - hideWaitAnimation(); - } else if(msg.data == "wait") { - disableSendBtn(); - disableButtons([button_actedit, button_actmem, button_actwi, button_actback, button_actretry]); - showWaitAnimation(); - } else if(msg.data == "start") { - setStartState(); - } - } else if(msg.cmd == "editmode") { - // Enable or Disable edit mode - if(msg.data == "true") { - enterEditMode(); - } else { - exitEditMode(); - } - } else if(msg.cmd == "setinputtext") { - // Set input box text for edit mode - input_text.val(msg.data); - } else if(msg.cmd == "enablesubmit") { - // Enables the submit button - enableSendBtn(); - } else if(msg.cmd == "memmode") { - // Enable or Disable memory edit mode - if(msg.data == "true") { - enterMemoryMode(); - } else { - exitMemoryMode(); - } - } else if(msg.cmd == "errmsg") { - // Send error message - errMessage(msg.data); - } else if(msg.cmd == "texteffect") { - // Apply color highlight to line of text - newTextHighlight($("#n"+msg.data)) - } else if(msg.cmd == "updatetemp") { - // Send current temp value to input - $("#settemp").val(parseFloat(msg.data)); - $("#settempcur").html(msg.data); - } else if(msg.cmd == "updatetopp") { - // Send current top p value to input - $("#settopp").val(parseFloat(msg.data)); - $("#settoppcur").html(msg.data); - } else if(msg.cmd == "updatereppen") { - // Send current rep pen value to input - $("#setreppen").val(parseFloat(msg.data)); - $("#setreppencur").html(msg.data); - } else if(msg.cmd == "updateoutlen") { - // Send current output amt value to input - $("#setoutput").val(parseInt(msg.data)); - $("#setoutputcur").html(msg.data); - } else if(msg.cmd == "updatetknmax") { - // Send current max tokens value to input - $("#settknmax").val(parseInt(msg.data)); - $("#settknmaxcur").html(msg.data); - } else if(msg.cmd == "updateikgen") { - // Send current max tokens value to input - $("#setikgen").val(parseInt(msg.data)); - $("#setikgencur").html(msg.data); - } else if(msg.cmd == "setlabeltemp") { - // Update setting label with value from server - $("#settempcur").html(msg.data); - } else if(msg.cmd == "setlabeltopp") { - // Update setting label with value from server - $("#settoppcur").html(msg.data); - } else if(msg.cmd == "setlabelreppen") { - // Update setting label with value from server - $("#setreppencur").html(msg.data); - } else if(msg.cmd == "setlabeloutput") { - // Update setting label with value from server - $("#setoutputcur").html(msg.data); - } else if(msg.cmd == "setlabeltknmax") { - // Update setting label with value from server - $("#settknmaxcur").html(msg.data); - } else if(msg.cmd == "setlabelikgen") { - // Update setting label with value from server - $("#setikgencur").html(msg.data); - } else if(msg.cmd == "updateanotedepth") { - // Send current Author's Note depth value to input - anote_slider.val(parseInt(msg.data)); - anote_labelcur.html(msg.data); - } else if(msg.cmd == "setlabelanotedepth") { - // Update setting label with value from server - anote_labelcur.html(msg.data); - } else if(msg.cmd == "getanote") { - // Request contents of Author's Note field - var txt = anote_input.val(); - socket.send({'cmd': 'anote', 'data': txt}); - } else if(msg.cmd == "setanote") { - // Set contents of Author's Note field - anote_input.val(msg.data); - } else if(msg.cmd == "addsetting") { - // Add setting controls - addSetting(msg.data); - } else if(msg.cmd == "addformat") { - // Add setting controls - addFormat(msg.data); - } else if(msg.cmd == "updatefrmttriminc") { - // Update toggle state - $("#frmttriminc").prop('checked', msg.data).change(); - } else if(msg.cmd == "updatefrmtrmblln") { - // Update toggle state - $("#frmtrmblln").prop('checked', msg.data).change(); - } else if(msg.cmd == "updatefrmtrmspch") { - // Update toggle state - $("#frmtrmspch").prop('checked', msg.data).change(); - } else if(msg.cmd == "updatefrmtadsnsp") { - // Update toggle state - $("#frmtadsnsp").prop('checked', msg.data).change(); - } else if(msg.cmd == "allowtoggle") { - // Allow toggle change states to propagate - allowtoggle = msg.data; - } else if(msg.cmd == "popupshow") { - // Show/Hide Popup - popupShow(msg.data); - } else if(msg.cmd == "addimportline") { - // Add import popup entry - addImportLine(msg.data); - } else if(msg.cmd == "clearpopup") { - // Clear previous contents of popup - popup_content.html(""); - } else if(msg.cmd == "wimode") { - // Enable or Disable WI edit mode - if(msg.data == "true") { - enterWiMode(); - } else { - exitWiMode(); - } - } else if(msg.cmd == "addwiitem") { - // Add WI entry to WI Menu - addWiLine(msg.data); - } else if(msg.cmd == "clearwi") { - // Clear previous contents of WI list - wi_menu.html(""); - } else if(msg.cmd == "requestwiitem") { - // Package WI contents and send back to server - returnWiList(msg.data); - } else if(msg.cmd == "saveas") { - // Show Save As prompt - showSaveAsPopup(); - } else if(msg.cmd == "hidesaveas") { - // Hide Save As prompt - hideSaveAsPopup(); - } else if(msg.cmd == "buildload") { - // Send array of save files to load UI - buildLoadList(msg.data); - } else if(msg.cmd == "askforoverwrite") { - // Show overwrite warning - show([saveasoverwrite]); - } else if(msg.cmd == "genseqs") { - // Parse generator sequences to UI - parsegenseqs(msg.data); - } else if(msg.cmd == "hidegenseqs") { - // Collapse genseqs menu - hidegenseqs(); - } else if(msg.cmd == "setlabelnumseq") { - // Update setting label with value from server - $("#setnumseqcur").html(msg.data); - } else if(msg.cmd == "updatenumseq") { - // Send current max tokens value to input - $("#setnumseq").val(parseInt(msg.data)); - $("#setnumseqcur").html(msg.data); - } else if(msg.cmd == "setlabelwidepth") { - // Update setting label with value from server - $("#setwidepthcur").html(msg.data); - } else if(msg.cmd == "updatewidepth") { - // Send current max tokens value to input - $("#setwidepth").val(parseInt(msg.data)); - $("#setwidepthcur").html(msg.data); - } else if(msg.cmd == "updateuseprompt") { - // Update toggle state - $("#setuseprompt").prop('checked', msg.data).change(); - } - }); - - socket.on('disconnect', function() { - connect_status.html("Lost connection..."); - connect_status.removeClass("color_green"); - connect_status.addClass("color_orange"); - }); - - // Bind actions to UI buttons - button_send.on("click", function(ev) { - dosubmit(); - }); - - button_actretry.on("click", function(ev) { - socket.send({'cmd': 'retry', 'data': ''}); - hidegenseqs(); - }); - - button_actback.on("click", function(ev) { - socket.send({'cmd': 'back', 'data': ''}); - hidegenseqs(); - }); - - button_actedit.on("click", function(ev) { - socket.send({'cmd': 'edit', 'data': ''}); - }); - - button_delete.on("click", function(ev) { - socket.send({'cmd': 'delete', 'data': ''}); - }); - - button_actmem.on("click", function(ev) { - socket.send({'cmd': 'memory', 'data': ''}); - }); - - button_savetofile.on("click", function(ev) { - socket.send({'cmd': 'savetofile', 'data': ''}); - }); - - button_loadfrfile.on("click", function(ev) { - socket.send({'cmd': 'loadfromfile', 'data': ''}); - }); - - button_import.on("click", function(ev) { - socket.send({'cmd': 'import', 'data': ''}); - }); - - button_importwi.on("click", function(ev) { - socket.send({'cmd': 'importwi', 'data': ''}); - }); - - button_settings.on("click", function(ev) { - $('#settingsmenu').slideToggle("slow"); - }); - - button_format.on("click", function(ev) { - $('#formatmenu').slideToggle("slow"); - }); - - popup_close.on("click", function(ev) { - socket.send({'cmd': 'importcancel', 'data': ''}); - }); - - popup_accept.on("click", function(ev) { - socket.send({'cmd': 'importaccept', 'data': ''}); - }); - - button_actwi.on("click", function(ev) { - socket.send({'cmd': 'wi', 'data': ''}); - }); - - button_impaidg.on("click", function(ev) { - showAidgPopup(); - }); - - aidg_close.on("click", function(ev) { - hideAidgPopup(); - }); - - aidg_accept.on("click", function(ev) { - sendAidgImportRequest(); - }); - - button_save.on("click", function(ev) { - socket.send({'cmd': 'saverequest', 'data': ''}); - }); - - button_saveas.on("click", function(ev) { - showSaveAsPopup(); - }); - - saveas_close.on("click", function(ev) { - hideSaveAsPopup(); - socket.send({'cmd': 'clearoverwrite', 'data': ''}); - }); - - saveas_accept.on("click", function(ev) { - sendSaveAsRequest(); - }); - - button_load.on("click", function(ev) { - socket.send({'cmd': 'loadlistrequest', 'data': ''}); - }); - - load_close.on("click", function(ev) { - hideLoadPopup(); - }); - - load_accept.on("click", function(ev) { - socket.send({'cmd': 'loadrequest', 'data': ''}); - hideLoadPopup(); - }); - - button_newgame.on("click", function(ev) { - showNewStoryPopup(); - }); - - ns_accept.on("click", function(ev) { - socket.send({'cmd': 'newgame', 'data': ''}); - hideNewStoryPopup(); - }); - - ns_close.on("click", function(ev) { - hideNewStoryPopup(); - }); - - button_rndgame.on("click", function(ev) { - showRandomStoryPopup(); - }); - - rs_accept.on("click", function(ev) { - socket.send({'cmd': 'rndgame', 'data': ''}); - hideRandomStoryPopup(); - }); - - rs_close.on("click", function(ev) { - hideRandomStoryPopup(); - }); - - anote_slider.on("input", function () { - socket.send({'cmd': 'anotedepth', 'data': $(this).val()}); - }); - - saveasinput.on("input", function () { - if(saveasinput.val() == "") { - disableButtons([saveas_accept]); - } else { - enableButtons([saveas_accept]); - } - hide([saveasoverwrite]); - }); - - // Bind Enter button to submit - input_text.keydown(function (ev) { - if (ev.which == 13 && !shift_down) { - do_clear_ent = true; - dosubmit(); - } else if(ev.which == 16) { - shift_down = true; - } - }); - - // Enter to submit, but not if holding shift - input_text.keyup(function (ev) { - if (ev.which == 13 && do_clear_ent) { - input_text.val(""); - do_clear_ent = false; - } else if(ev.which == 16) { - shift_down = false; - } - }); - - aidgpromptnum.keydown(function (ev) { - if (ev.which == 13) { - sendAidgImportRequest(); - } - }); - - saveasinput.keydown(function (ev) { - if (ev.which == 13 && saveasinput.val() != "") { - sendSaveAsRequest(); - } - }); -}); - diff --git a/static/custom.css b/static/custom.css index f27bce24..cf21ed06 100644 --- a/static/custom.css +++ b/static/custom.css @@ -6,6 +6,11 @@ chunk { color: #ffffff; } +action { + color: #9ff7fa; + font-weight: bold; +} + #topmenu { background-color: #337ab7; padding: 10px; @@ -97,12 +102,21 @@ chunk { margin-left: 20px; } +#inputrow.show_mode { + grid-template-columns: 7% 83% 10%; +} + #inputrow { margin-top: 10px; padding: 0px; width: 100%; display: grid; - grid-template-columns: 90% 10%; + grid-template-columns: 0% 90% 10%; +} + +#inputrowmode { + position: relative; + padding-right: 0px; } #inputrowleft { @@ -121,6 +135,13 @@ chunk { color: #ffffff; } +#btnmode { + width: 100%; + height: 100%; + overflow: auto; + overflow-x: hidden; +} + #btnsend { width: 100%; height: 100%; @@ -302,10 +323,15 @@ chunk { cursor: pointer; } +.chunkhov:hover > action { + color: #00fa00; +} + .colorfade { -moz-transition:color 1s ease-in; -o-transition:color 1s ease-in; -webkit-transition:color 1s ease-in; + transition:color 1s ease-in; } .color_orange { @@ -448,6 +474,7 @@ chunk { -moz-transition: background-color 0.25s ease-in; -o-transition: background-color 0.25s ease-in; -webkit-transition: background-color 0.25s ease-in; + transition: background-color 0.25s ease-in; } .loadlistitem:hover { @@ -525,6 +552,7 @@ chunk { -moz-transition: background-color 0.25s ease-in; -o-transition: background-color 0.25s ease-in; -webkit-transition: background-color 0.25s ease-in; + transition: background-color 0.25s ease-in; } .popuplistitem:hover { @@ -575,6 +603,7 @@ chunk { -moz-transition: all 0.15s ease-in; -o-transition: all 0.15s ease-in; -webkit-transition: all 0.15s ease-in; + transition: all 0.15s ease-in; } .seqselitem:hover { diff --git a/templates/index.html b/templates/index.html index a334f905..4b9ac8f7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -101,6 +101,9 @@
+
+ +
diff --git a/utils.py b/utils.py index fd46b8db..afdf29bc 100644 --- a/utils.py +++ b/utils.py @@ -59,8 +59,11 @@ def replaceblanklines(txt): #==================================================================# # #==================================================================# -def removespecialchars(txt): - txt = re.sub(r"[#/@%<>{}+=~|\^]", "", txt) +def removespecialchars(txt, vars=None): + if vars is None or vars.actionmode == 0: + txt = re.sub(r"[#/@%<>{}+=~|\^]", "", txt) + else: + txt = re.sub(r"[#/@%{}+=~|\^]", "", txt) return txt #==================================================================#