Added ability to import AIDungeon games from AIDCAT

This commit is contained in:
KoboldAI Dev 2021-05-11 00:27:34 -04:00
parent b55266a7c8
commit 1cc069a779
4 changed files with 248 additions and 2 deletions

View File

@ -73,6 +73,8 @@ class vars:
usegpu = False # Whether to launch pipeline with GPU support usegpu = False # Whether to launch pipeline with GPU support
custmodpth = "" # Filesystem location of custom model to run custmodpth = "" # Filesystem location of custom model to run
formatoptns = {} # Container for state of formatting options formatoptns = {} # Container for state of formatting options
importnum = -1 # Selection on import popup list
importjs = {} # Temporary storage for import data
#==================================================================# #==================================================================#
# Function to get model selection at startup # Function to get model selection at startup
@ -319,6 +321,8 @@ def get_message(msg):
saveRequest() saveRequest()
elif(msg['cmd'] == 'load'): elif(msg['cmd'] == 'load'):
loadRequest() loadRequest()
elif(msg['cmd'] == 'import'):
importRequest()
elif(msg['cmd'] == 'newgame'): elif(msg['cmd'] == 'newgame'):
newGameRequest() newGameRequest()
elif(msg['cmd'] == 'settemp'): elif(msg['cmd'] == 'settemp'):
@ -370,6 +374,14 @@ def get_message(msg):
if('frmtadsnsp' in vars.formatoptns): if('frmtadsnsp' in vars.formatoptns):
vars.formatoptns["frmtadsnsp"] = msg['data'] vars.formatoptns["frmtadsnsp"] = msg['data']
settingschanged() settingschanged()
elif(msg['cmd'] == 'importselect'):
vars.importnum = int(msg["data"][-1])
elif(msg['cmd'] == 'importcancel'):
emit('from_server', {'cmd': 'popupshow', 'data': False})
vars.importjs = {}
elif(msg['cmd'] == 'importaccept'):
emit('from_server', {'cmd': 'popupshow', 'data': False})
importgame()
#==================================================================# #==================================================================#
# #
@ -941,6 +953,73 @@ def loadRequest():
refresh_story() refresh_story()
emit('from_server', {'cmd': 'setgamestate', 'data': 'ready'}) emit('from_server', {'cmd': 'setgamestate', 'data': 'ready'})
#==================================================================#
# Import an AIDungon game exported with Mimi's tool
#==================================================================#
def importRequest():
importpath = fileops.getloadpath(vars.savedir, "Select AID CAT File", [("Json", "*.json")])
if(importpath):
# Leave Edit/Memory mode before continuing
exitModes()
# Read file contents into JSON object
file = open(importpath, "r")
vars.importjs = json.load(file)
# Clear Popup Contents
emit('from_server', {'cmd': 'clearpopup', 'data': ''})
# Initialize vars
num = 0
vars.importnum = -1
# Get list of stories
for story in vars.importjs:
ob = {}
ob["num"] = num
ob["title"] = story["title"]
if(story["description"] != ""):
ob["descr"] = story["description"]
else:
ob["descr"] = "(No Description)"
ob["acts"] = len(story["actions"])
emit('from_server', {'cmd': 'addimportline', 'data': ob})
num += 1
# Show Popup
emit('from_server', {'cmd': 'popupshow', 'data': True})
#==================================================================#
# Import an AIDungon game selected in popup
#==================================================================#
def importgame():
if(vars.importnum >= 0):
# Cache reference to selected game
ref = vars.importjs[vars.importnum]
# Copy game contents to vars
vars.gamestarted = True
if(len(ref["actions"]) > 0):
vars.prompt = ref["actions"][0]["text"]
else:
vars.prompt = ""
vars.memory = ref["memory"]
vars.authornote = ref["authorsNote"]
vars.actions = []
# Get all actions except for prompt
if(len(ref["actions"]) > 1):
for act in ref["actions"][1:]:
vars.actions.append(act["text"])
# Clear import data
vars.importjs = {}
# Refresh game screen
refresh_story()
emit('from_server', {'cmd': 'setgamestate', 'data': 'ready'})
#==================================================================# #==================================================================#
# Starts a new story # Starts a new story
#==================================================================# #==================================================================#

View File

@ -10,6 +10,7 @@ var connect_status;
var button_newgame; var button_newgame;
var button_save; var button_save;
var button_load; var button_load;
var button_import;
var button_settings; var button_settings;
var button_format; var button_format;
var button_send; var button_send;
@ -27,6 +28,11 @@ var anote_menu;
var anote_input; var anote_input;
var anote_labelcur; var anote_labelcur;
var anote_slider; var anote_slider;
var popup;
var popup_title;
var popup_content;
var popup_accept;
var popup_close;
// Key states // Key states
var shift_down = false; var shift_down = false;
@ -102,6 +108,23 @@ function addFormat(ob) {
} }
} }
function addImportLine(ob) {
popup_content.append("<div class=\"popuplistitem\" id=\"import"+ob.num+"\">\
<div>"+ob.title+"</div>\
<div>"+ob.acts+"</div>\
<div>"+ob.descr+"</div>\
</div>");
$("#import"+ob.num).on("click", function () {
socket.send({'cmd': 'importselect', 'data': $(this).attr('id')});
highlightImportLine($(this));
});
}
function highlightImportLine(ref) {
$("#popupcontent > div").removeClass("popuplistselected");
ref.addClass("popuplistselected");
}
function enableButtons(refs) { function enableButtons(refs) {
for(i=0; i<refs.length; i++) { for(i=0; i<refs.length; i++) {
refs[i].prop("disabled",false); refs[i].prop("disabled",false);
@ -165,6 +188,16 @@ function show(refs) {
} }
} }
function popupShow(state) {
if(state) {
popup.removeClass("hidden");
popup.addClass("flex");
} else {
popup.removeClass("flex");
popup.addClass("hidden");
}
}
function enterEditMode() { function enterEditMode() {
// Add class to each story chunk // Add class to each story chunk
showMessage("Please select a story chunk to edit above."); showMessage("Please select a story chunk to edit above.");
@ -240,6 +273,7 @@ $(document).ready(function(){
button_newgame = $('#btn_newgame'); button_newgame = $('#btn_newgame');
button_save = $('#btn_save'); button_save = $('#btn_save');
button_load = $('#btn_load'); button_load = $('#btn_load');
button_import = $("#btn_import");
button_settings = $('#btn_settings'); button_settings = $('#btn_settings');
button_format = $('#btn_format'); button_format = $('#btn_format');
button_send = $('#btnsend'); button_send = $('#btnsend');
@ -257,6 +291,11 @@ $(document).ready(function(){
anote_input = $('#anoteinput'); anote_input = $('#anoteinput');
anote_labelcur = $('#anotecur'); anote_labelcur = $('#anotecur');
anote_slider = $('#anotedepth'); anote_slider = $('#anotedepth');
popup = $("#popupcontainer");
popup_title = $("#popuptitletext");
popup_content = $("#popupcontent");
popup_accept = $("#btn_popupaccept");
popup_close = $("#btn_popupclose");
// Connect to SocketIO server // Connect to SocketIO server
socket = io.connect('http://127.0.0.1:5000'); socket = io.connect('http://127.0.0.1:5000');
@ -395,6 +434,15 @@ $(document).ready(function(){
} else if(msg.cmd == "allowtoggle") { } else if(msg.cmd == "allowtoggle") {
// Allow toggle change states to propagate // Allow toggle change states to propagate
allowtoggle = msg.data; 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("");
} }
}); });
@ -437,6 +485,10 @@ $(document).ready(function(){
socket.send({'cmd': 'load', 'data': ''}); socket.send({'cmd': 'load', 'data': ''});
}); });
button_import.on("click", function(ev) {
socket.send({'cmd': 'import', 'data': ''});
});
button_newgame.on("click", function(ev) { button_newgame.on("click", function(ev) {
socket.send({'cmd': 'newgame', 'data': ''}); socket.send({'cmd': 'newgame', 'data': ''});
}); });
@ -449,10 +501,19 @@ $(document).ready(function(){
$('#formatmenu').slideToggle("slow"); $('#formatmenu').slideToggle("slow");
}); });
$("#btn_savesettings").on("click", function(ev) { popup_close.on("click", function(ev) {
socket.send({'cmd': 'savesettings', 'data': ''}); socket.send({'cmd': 'importcancel', 'data': ''});
}); });
popup_accept.on("click", function(ev) {
socket.send({'cmd': 'importaccept', 'data': ''});
});
// I think this was removed?
//$("#btn_savesettings").on("click", function(ev) {
// socket.send({'cmd': 'savesettings', 'data': ''});
//});
// Bind Enter button to submit // Bind Enter button to submit
input_text.keydown(function (ev) { input_text.keydown(function (ev) {
if (ev.which == 13 && !shift_down) { if (ev.which == 13 && !shift_down) {

View File

@ -136,6 +136,69 @@ chunk {
grid-template-columns: 80% 20%; grid-template-columns: 80% 20%;
} }
#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;
}
#popup {
width: 75%;
min-width: 500px;
max-width: 1000px;
background-color: #262626;
margin-top: 100px;
}
#popuptitlebar {
padding: 10px;
background-color: #337ab7;
}
#popuptitletext {
height: 100%;
display: flex;
align-items:center;
color: #ffffff;
font-size: 12pt;
}
#popuplistheader {
padding-left: 10px;
display: grid;
grid-template-columns: 28% 10% 60%;
color: #737373;
}
#popupcontent {
min-height: 300px;
overflow-y: scroll;
}
#popupfooter {
width: 100%;
padding: 10px;
display: flex;
justify-content: center;
background-color: #295071;
}
#popupfooter button {
width: 100px;
margin-left: 10px;
margin-right: 10px;
}
#popuptitleclose {
}
.anotelabel { .anotelabel {
font-size: 10pt; font-size: 10pt;
color: #ffffff; color: #ffffff;
@ -172,6 +235,10 @@ chunk {
color: #ff0000; color: #ff0000;
} }
.flex {
display: flex;
}
.formatcolumn { .formatcolumn {
width: 25%; width: 25%;
padding-left: 10px; padding-left: 10px;
@ -247,6 +314,26 @@ chunk {
text-align: right; text-align: right;
} }
.popuplistitem {
padding: 5px 10px 5px 10px;
display: grid;
grid-template-columns: 30% 10% 60%;
color: #ffffff;
-moz-transition: background-color 0.25s ease-in;
-o-transition: background-color 0.25s ease-in;
-webkit-transition: background-color 0.25s ease-in;
}
.popuplistitem:hover {
cursor: pointer;
background-color: #688f1f;
}
.popuplistselected {
background-color: #688f1f;
}
.settingitem { .settingitem {
width: 18%; width: 18%;
padding-left: 10px; padding-left: 10px;

View File

@ -22,6 +22,7 @@
<button type="button" class="btn btn-primary" id="btn_newgame">New Story</button> <button type="button" class="btn btn-primary" id="btn_newgame">New Story</button>
<button type="button" class="btn btn-primary" id="btn_save">Save</button> <button type="button" class="btn btn-primary" id="btn_save">Save</button>
<button type="button" class="btn btn-primary" id="btn_load">Load</button> <button type="button" class="btn btn-primary" id="btn_load">Load</button>
<button type="button" class="btn btn-primary" id="btn_import">Import</button>
<div class="spacer"></div> <div class="spacer"></div>
<button type="button" class="btn btn-primary" id="btn_settings">Settings</button> <button type="button" class="btn btn-primary" id="btn_settings">Settings</button>
<button type="button" class="btn btn-primary" id="btn_format">Formatting</button> <button type="button" class="btn btn-primary" id="btn_format">Formatting</button>
@ -94,5 +95,23 @@
</div> </div>
</div> </div>
</div> </div>
<div class="hidden" id="popupcontainer">
<div id="popup">
<div id="popuptitlebar">
<div id="popuptitletext">Select an Adventure to Import</div>
</div>
<div id="popuplistheader">
<div>Title</div>
<div># Actions</div>
<div>Description</div>
</div>
<div id="popupcontent">
</div>
<div id="popupfooter">
<button type="button" class="btn btn-primary" id="btn_popupaccept">Accept</button>
<button type="button" class="btn btn-primary" id="btn_popupclose">Cancel</button>
</div>
</div>
</div>
</body> </body>
</html> </html>