From b05a73a04f4b816c4035fce7a1d7dc5e9ba322e3 Mon Sep 17 00:00:00 2001 From: KoboldAI Dev Date: Sun, 16 May 2021 05:29:39 -0400 Subject: [PATCH] Added ability to import aidg.club scenarios Changed menu bar to bootstrap navbar to allow for dropdown menus --- aiserver.py | 44 +++++++++++++++++ static/application.js | 52 +++++++++++++++++--- static/custom.css | 109 ++++++++++++++++++++++++++++++++++++++++-- templates/index.html | 52 +++++++++++++++++--- 4 files changed, 240 insertions(+), 17 deletions(-) diff --git a/aiserver.py b/aiserver.py index 74d08bb2..86b3434f 100644 --- a/aiserver.py +++ b/aiserver.py @@ -408,6 +408,8 @@ def get_message(msg): deletewi(msg['data']) elif(msg['cmd'] == 'sendwilist'): commitwi(msg['data']) + elif(msg['cmd'] == 'aidgimport'): + importAidgRequest(msg['data']) #==================================================================# # @@ -1280,6 +1282,48 @@ def importgame(): refresh_story() emit('from_server', {'cmd': 'setgamestate', 'data': 'ready'}) +#==================================================================# +# Import an aidg.club prompt and start a new game with it. +#==================================================================# +def importAidgRequest(id): + import html + import re + + exitModes() + + urlformat = "https://prompts.aidg.club/" + req = requests.get(urlformat+id) + + if(req.status_code == 200): + contents = html.unescape(req.text) + title = re.search("

(.*?)

", contents, re.IGNORECASE | re.MULTILINE | re.DOTALL).group(1).strip() + + keys = re.findall("
(.*?)
", contents, re.IGNORECASE | re.MULTILINE | re.DOTALL) + contents = re.findall("(.*?)", contents, re.IGNORECASE | re.MULTILINE | re.DOTALL) + + # Initialize game state + vars.gamestarted = True + vars.prompt = "" + vars.memory = "" + vars.authornote = "" + vars.actions = [] + vars.worldinfo = [] + + for i in range(len(keys)): + if(keys[i] == "Description"): + pass + elif(keys[i] == "Prompt"): + vars.prompt = contents[i] + elif(keys[i] == "Memory"): + vars.memory = contents[i] + elif(keys[i] == "Author's Note"): + vars.authornote = contents[i] + + # Refresh game screen + sendwi() + refresh_story() + emit('from_server', {'cmd': 'setgamestate', 'data': 'ready'}) + #==================================================================# # Starts a new story #==================================================================# diff --git a/static/application.js b/static/application.js index fdcaf7e7..8ac1ef61 100644 --- a/static/application.js +++ b/static/application.js @@ -11,6 +11,7 @@ var button_newgame; var button_save; var button_load; var button_import; +var button_impaidg; var button_settings; var button_format; var button_send; @@ -35,6 +36,10 @@ var popup_title; var popup_content; var popup_accept; var popup_close; +var aidgpopup; +var aidgpromptnum; +var aidg_accept; +var aidg_close; // Key states var shift_down = false; @@ -356,13 +361,30 @@ function newTextHighlight(ref) { ref.addClass("color_green"); ref.addClass("colorfade"); setTimeout(function () { - ref.removeClass("color_green") + ref.removeClass("color_green"); setTimeout(function () { - ref.removeClass("colorfade") + ref.removeClass("colorfade"); }, 1000); }, 10); } +function showAidgPopup() { + aidgpopup.removeClass("hidden"); + aidgpopup.addClass("flex"); + aidgpromptnum.focus(); +} + +function hideAidgPopup() { + aidgpopup.removeClass("flex"); + aidgpopup.addClass("hidden"); +} + +function sendAidgImportRequest() { + socket.send({'cmd': 'aidgimport', 'data': aidgpromptnum.val()}); + hideAidgPopup(); + aidgpromptnum.val(""); +} + //=================================================================// // READY/RUNTIME //=================================================================// @@ -375,6 +397,7 @@ $(document).ready(function(){ button_save = $('#btn_save'); button_load = $('#btn_load'); button_import = $("#btn_import"); + button_impaidg = $("#btn_impaidg"); button_settings = $('#btn_settings'); button_format = $('#btn_format'); button_send = $('#btnsend'); @@ -399,6 +422,10 @@ $(document).ready(function(){ popup_content = $("#popupcontent"); popup_accept = $("#btn_popupaccept"); popup_close = $("#btn_popupclose"); + aidgpopup = $("#aidgpopupcontainer"); + aidgpromptnum = $("#aidgpromptnum"); + aidg_accept = $("#btn_aidgpopupaccept"); + aidg_close = $("#btn_aidgpopupclose"); // Connect to SocketIO server loc = window.document.location; @@ -441,6 +468,7 @@ $(document).ready(function(){ button_actedit.html("Edit"); button_actmem.html("Memory"); button_actwi.html("W Info"); + hideAidgPopup(); } } else if(msg.cmd == "editmode") { // Enable or Disable edit mode @@ -640,10 +668,17 @@ $(document).ready(function(){ socket.send({'cmd': 'wi', 'data': ''}); }); - // I think this was removed? - //$("#btn_savesettings").on("click", function(ev) { - // socket.send({'cmd': 'savesettings', 'data': ''}); - //}); + button_impaidg.on("click", function(ev) { + showAidgPopup(); + }); + + aidg_close.on("click", function(ev) { + hideAidgPopup(); + }); + + aidg_accept.on("click", function(ev) { + sendAidgImportRequest(); + }); // Bind Enter button to submit input_text.keydown(function (ev) { @@ -665,5 +700,10 @@ $(document).ready(function(){ } }); + aidgpromptnum.keydown(function (ev) { + if (ev.which == 13) { + sendAidgImportRequest(); + } + }); }); diff --git a/static/custom.css b/static/custom.css index 567522b4..60db0f3b 100644 --- a/static/custom.css +++ b/static/custom.css @@ -16,6 +16,21 @@ chunk { grid-template-columns: 80% 20%; } +#navbar { + margin: 0px; +} + +#navbar li { + margin-right: 5px; + background-color: #4787be; + border-radius: 5px; +} + +#navbar li > a { + color: #ffffff; + font-weight: bold; +} + #settingsmenu { display:none; background-color: #295071; @@ -195,17 +210,33 @@ chunk { margin-right: 10px; } -#popuptitleclose { - -} - #wimenu { max-height: 100%; width: 100%; } +#aidgpopup { + width: 350px; + background-color: #262626; + margin-top: 100px; +} + +#aidgpromptnum { + background-color: #404040; + color: #ffffff; +} + /*================= Classes =================*/ +.aidgpopupcontent { + padding: 10px 40px 10px 40px; +} + +.aidgpopuplistheader { + color: #737373; + text-align: center; +} + .anotelabel { font-size: 10pt; color: #ffffff; @@ -242,6 +273,27 @@ chunk { color: #ff0000; } +.dropdown-menu { + background-color: #337ab7; + width: 200px; +} + +.dropdown-item { + display: block; + padding: 10px; + color: #ffffff; + border-bottom: 1px solid #295071; +} + +.dropdown-item:first-child { + border-top: 1px solid #295071; +} + +.dropdown-item:hover { + background-color: #98bcdb; + text-decoration: none; +} + .flex { display: flex; } @@ -329,6 +381,28 @@ chunk { text-align: right; } +.navbar .navbar-nav .nav-link:hover { + border-radius: 5px; + background-color: #98bcdb; +} + +.navbar .navbar-nav .nav-link:focus { + border-radius: 5px; + background-color: #98bcdb; +} + +.popupcontainer { + position: absolute; + top: 0px; + left: 0px; + z-index: 1; + width: 100%; + height: 100%; + background-color: rgba(0,0,0,0.5); + flex-direction: column; + align-items: center; +} + .popuplistitem { padding: 5px 10px 5px 10px; display: grid; @@ -349,6 +423,33 @@ chunk { background-color: #688f1f; } +.popuptitlebar { + padding: 10px; + background-color: #337ab7; +} + +.popuptitletext { + height: 100%; + display: flex; + align-items:center; + color: #ffffff; + font-size: 12pt; +} + +.popupfooter { + width: 100%; + padding: 10px; + display: flex; + justify-content: center; + background-color: #295071; +} + +.popupfooter button { + width: 100px; + margin-left: 10px; + margin-right: 10px; +} + .settingitem { width: 18%; padding-left: 10px; diff --git a/templates/index.html b/templates/index.html index 4c4bc1a8..3764e8db 100644 --- a/templates/index.html +++ b/templates/index.html @@ -19,13 +19,34 @@
+ \ No newline at end of file