2021-05-03 00:48:47 +02:00
//=================================================================//
// VARIABLES
//=================================================================//
2021-05-05 09:04:06 +02:00
// Socket IO Object
2021-05-03 00:48:47 +02:00
var socket ;
2021-05-05 09:04:06 +02:00
// UI references for jQuery
2021-05-07 20:32:10 +02:00
var connect _status ;
2021-05-04 15:56:48 +02:00
var button _newgame ;
2021-08-19 12:54:44 +02:00
var button _rndgame ;
2021-05-04 15:56:48 +02:00
var button _save ;
2021-05-22 11:28:40 +02:00
var button _saveas ;
var button _savetofile ;
2021-05-04 15:56:48 +02:00
var button _load ;
2021-05-11 06:27:34 +02:00
var button _import ;
2021-05-29 11:46:03 +02:00
var button _importwi ;
2021-05-16 11:29:39 +02:00
var button _impaidg ;
2021-05-04 15:56:48 +02:00
var button _settings ;
2021-05-11 01:17:10 +02:00
var button _format ;
2021-10-22 20:18:10 +02:00
var button _softprompt ;
2021-08-19 13:18:01 +02:00
var button _mode ;
var button _mode _label ;
2021-05-03 00:48:47 +02:00
var button _send ;
var button _actmem ;
var button _actback ;
var button _actretry ;
2021-05-13 07:26:42 +02:00
var button _actwi ;
2021-05-03 00:48:47 +02:00
var game _text ;
var input _text ;
var message _text ;
2021-05-07 20:32:10 +02:00
var settings _menu ;
2021-05-11 01:17:10 +02:00
var format _menu ;
2021-05-13 07:26:42 +02:00
var wi _menu ;
2021-05-05 09:04:06 +02:00
var anote _menu ;
var anote _input ;
var anote _labelcur ;
var anote _slider ;
2021-05-11 06:27:34 +02:00
var popup ;
var popup _title ;
var popup _content ;
var popup _accept ;
var popup _close ;
2021-05-16 11:29:39 +02:00
var aidgpopup ;
var aidgpromptnum ;
var aidg _accept ;
var aidg _close ;
2021-05-22 11:28:40 +02:00
var saveaspopup ;
var saveasinput ;
2021-08-19 12:54:44 +02:00
var topic ;
2021-05-22 11:28:40 +02:00
var saveas _accept ;
var saveas _close ;
var loadpopup ;
var loadcontent ;
var load _accept ;
var load _close ;
2021-10-22 20:18:10 +02:00
var sppopup ;
var spcontent ;
var sp _accept ;
var sp _close ;
2021-05-22 11:28:40 +02:00
var nspopup ;
var ns _accept ;
var ns _close ;
2021-08-19 12:54:44 +02:00
var rspopup ;
var rs _accept ;
var rs _close ;
2021-05-29 11:46:03 +02:00
var seqselmenu ;
var seqselcontents ;
2021-05-03 00:48:47 +02:00
2021-09-19 17:41:37 +02:00
var storyname = null ;
2021-08-19 13:18:01 +02:00
var memorymode = false ;
2021-09-19 17:41:37 +02:00
var memorytext = "" ;
2021-08-19 13:18:01 +02:00
var gamestarted = false ;
2021-08-23 08:34:27 +02:00
var editmode = false ;
var connected = false ;
var newly _loaded = true ;
2021-09-27 19:11:15 +02:00
var modified _chunks = new Set ( ) ;
var empty _chunks = new Set ( ) ;
var gametext _bound = false ;
2021-09-28 04:21:14 +02:00
var saved _prompt = "..." ;
2021-09-28 04:56:12 +02:00
var override _focusout = false ;
2021-09-01 00:22:30 +02:00
var sman _allow _delete = false ;
var sman _allow _rename = false ;
2021-10-22 20:18:10 +02:00
var allowsp = false ;
2021-11-05 00:33:17 +01:00
var remote = false ;
2021-08-19 13:18:01 +02:00
2021-09-30 20:13:54 +02:00
// This is true iff [we're in macOS and the browser is Safari] or [we're in iOS]
2021-10-01 04:58:54 +02:00
var using _webkit _patch = true ;
2021-09-30 20:13:54 +02:00
2021-05-05 09:04:06 +02:00
// Key states
var shift _down = false ;
2021-05-03 00:48:47 +02:00
var do _clear _ent = false ;
2021-05-11 01:17:10 +02:00
// Display vars
var allowtoggle = false ;
var formatcount = 0 ;
2021-08-23 08:34:27 +02:00
var allowedit = true ; // Whether clicking on chunks will edit them
2021-05-11 01:17:10 +02:00
2021-08-19 13:18:01 +02:00
// Adventure
var action _mode = 0 ; // 0: story, 1: action
var adventure = false ;
2021-05-03 00:48:47 +02:00
//=================================================================//
// METHODS
//=================================================================//
2021-05-07 20:32:10 +02:00
function addSetting ( ob ) {
// Add setting block to Settings Menu
2021-05-29 11:46:03 +02:00
if ( ob . uitype == "slider" ) {
settings _menu . append ( "<div class=\"settingitem\" > \
< div class = \ "settinglabel\" > \
< div class = \ "justifyleft\" > \
"+ob.label+" < span class = \ "helpicon\">?<span class=\"helptext\">" + ob . tooltip + " < / s p a n > < / s p a n > \
< / d i v > \
< div class = \ "justifyright\" id=\"" + ob . id + "cur\" > \
"+ob.default+" \
< / d i v > \
2021-05-07 20:32:10 +02:00
< / d i v > \
2021-05-29 11:46:03 +02:00
< div > \
< input type = \ "range\" class=\"form-range airange\" min=\"" + ob . min + "\" max=\"" + ob . max + "\" step=\"" + ob . step + "\" id=\"" + ob . id + "\" > \
2021-05-07 20:32:10 +02:00
< / d i v > \
2021-05-29 11:46:03 +02:00
< div class = \ "settingminmax\" > \
< div class = \ "justifyleft\" > \
"+ob.min+" \
< / d i v > \
< div class = \ "justifyright\" > \
"+ob.max+" \
< / d i v > \
2021-05-07 20:32:10 +02:00
< / d i v > \
2021-05-29 11:46:03 +02:00
< / d i v > " ) ;
// 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 ( "<div class=\"settingitem\" > \
< input type = \ "checkbox\" data-toggle=\"toggle\" data-onstyle=\"success\" id=\"" + ob . id + "\" > \
< span class = \ "formatlabel\">" + ob . label + " < / s p a n > \
< span class = \ "helpicon\">?<span class=\"helptext\">" + ob . tooltip + " < / s p a n > < / s p a n > \
< / d i v > " ) ;
// 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' ) } ) ;
}
2021-08-19 13:18:01 +02:00
if ( ob . id == "setadventure" ) {
setadventure ( $ ( this ) . prop ( 'checked' ) ) ;
}
2021-05-29 11:46:03 +02:00
} ) ;
}
2021-05-07 20:32:10 +02:00
}
2021-05-11 01:17:10 +02:00
function addFormat ( ob ) {
// Check if we need to make a new column for this button
if ( formatcount == 0 ) {
format _menu . append ( "<div class=\"formatcolumn\"></div>" ) ;
}
// Get reference to the last child column
var ref = $ ( "#formatmenu > div" ) . last ( ) ;
// Add format block to Format Menu
ref . append ( "<div class=\"formatrow\" > \
< input type = \ "checkbox\" data-toggle=\"toggle\" data-onstyle=\"success\" id=\"" + ob . id + "\" > \
< span class = \ "formatlabel\">" + ob . label + " < / s p a n > \
< span class = \ "helpicon\">?<span class=\"helptext\">" + ob . tooltip + " < / s p a n > < / s p a n > \
< / d i v > " ) ;
// 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 ;
}
}
2021-05-11 06:27:34 +02:00
function addImportLine ( ob ) {
popup _content . append ( "<div class=\"popuplistitem\" id=\"import" + ob . num + "\" > \
< div > "+ob.title+" < / d i v > \
< div > "+ob.acts+" < / d i v > \
< div > "+ob.descr+" < / d i v > \
< / d i v > " ) ;
$ ( "#import" + ob . num ) . on ( "click" , function ( ) {
socket . send ( { 'cmd' : 'importselect' , 'data' : $ ( this ) . attr ( 'id' ) } ) ;
highlightImportLine ( $ ( this ) ) ;
} ) ;
}
2021-05-13 07:26:42 +02:00
function addWiLine ( ob ) {
if ( ob . init ) {
2021-08-19 13:48:33 +02:00
if ( ob . selective ) {
2021-09-19 17:41:37 +02:00
wi _menu . append ( "<div class=\"wilistitem wilistitem-selective " + ( ob . constant ? "wilistitem-constant" : "" ) + "\" > \
2021-08-19 13:48:33 +02:00
< div class = \ "wiremove\" > \
< button type = \ "button\" class=\"btn btn-primary heightfull\" id=\"btn_wi" + ob . num + "\" > X < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-success heighthalf hidden\" id=\"btn_widel" + ob . num + "\" > ✓ < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican" + ob . num + "\" > ⮌ < / b u t t o n > \
< / d i v > \
2021-08-24 19:45:20 +02:00
< div class = \ "icon-container wikey\" > \
2021-08-19 13:48:33 +02:00
< input class = \ "form-control heightfull hidden\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey" + ob . num + "\" > \
< input class = \ "form-control heighthalf\" type=\"text\" placeholder=\"Primary Key(s)\" id=\"wikeyprimary" + ob . num + "\" > \
< input class = \ "form-control heighthalf\" type=\"text\" placeholder=\"Secondary Key(s)\" id=\"wikeysecondary" + ob . num + "\" > \
2021-08-24 19:45:20 +02:00
< span class = \ "constant-key-icon " + ( ob . constant ? "constant-key-icon-enabled" : "" ) + " oi oi-pin\" id=\"constant-key-" + ob . num + "\" title=\"Toggle Constant Key mode (if enabled, this world info entry will always be included in memory)\" aria-hidden=\"true\" > < / s p a n > \
2021-08-19 13:48:33 +02:00
< / d i v > \
< div class = \ "wientry\" > \
2021-08-24 19:45:20 +02:00
< textarea class = \ "layer-bottom form-control\" id=\"wientry" + ob . num + "\" placeholder=\"What To Remember\">" + ob . content + " < / t e x t a r e a > \
2021-08-19 13:48:33 +02:00
< / d i v > \
< div class = \ "wiselective\" > \
< button type = \ "button\" class=\"btn btn-success heightfull hidden\" id=\"btn_wiselon" + ob . num + "\" > Enable Selective Mode < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-danger heightfull\" id=\"btn_wiseloff" + ob . num + "\" > Disable Selective Mode < / b u t t o n > \
< / d i v > \
< / d i v > " ) ;
} else {
2021-09-19 17:41:37 +02:00
wi _menu . append ( "<div class=\"wilistitem " + ( ob . constant ? "wilistitem-constant" : "" ) + "\" > \
2021-08-19 13:48:33 +02:00
< div class = \ "wiremove\" > \
< button type = \ "button\" class=\"btn btn-primary heightfull\" id=\"btn_wi" + ob . num + "\" > X < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-success heighthalf hidden\" id=\"btn_widel" + ob . num + "\" > ✓ < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican" + ob . num + "\" > ⮌ < / b u t t o n > \
< / d i v > \
2021-08-24 19:45:20 +02:00
< div class = \ "icon-container wikey\" > \
2021-08-19 13:48:33 +02:00
< input class = \ "form-control heightfull\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey" + ob . num + "\" > \
< input class = \ "form-control heighthalf hidden\" type=\"text\" placeholder=\"Primary Key(s)\" id=\"wikeyprimary" + ob . num + "\" > \
< input class = \ "form-control heighthalf hidden\" type=\"text\" placeholder=\"Secondary Key(s)\" id=\"wikeysecondary" + ob . num + "\" > \
2021-08-24 19:45:20 +02:00
< span class = \ "constant-key-icon " + ( ob . constant ? "constant-key-icon-enabled" : "" ) + " oi oi-pin\" id=\"constant-key-" + ob . num + "\" title=\"Toggle Constant Key mode (if enabled, this world info entry will always be included in memory)\" aria-hidden=\"true\" > < / s p a n > \
2021-08-19 13:48:33 +02:00
< / d i v > \
< div class = \ "wientry\" > \
< textarea class = \ "form-control\" id=\"wientry" + ob . num + "\" placeholder=\"What To Remember\">" + ob . content + " < / t e x t a r e a > \
< / d i v > \
< div class = \ "wiselective\" > \
< button type = \ "button\" class=\"btn btn-success heightfull\" id=\"btn_wiselon" + ob . num + "\" > Enable Selective Mode < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-danger heightfull hidden\" id=\"btn_wiseloff" + ob . num + "\" > Disable Selective Mode < / b u t t o n > \
< / d i v > \
< / d i v > " ) ;
}
2021-05-13 07:26:42 +02:00
// Send key value to text input
$ ( "#wikey" + ob . num ) . val ( ob . key ) ;
2021-08-19 13:48:33 +02:00
$ ( "#wikeyprimary" + ob . num ) . val ( ob . key ) ;
$ ( "#wikeysecondary" + ob . num ) . val ( ob . keysecondary ) ;
2021-05-13 07:26:42 +02:00
// 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 ( "<div class=\"wilistitem\" > \
< div class = \ "wiremove\" > \
< button type = \ "button\" class=\"btn btn-primary heightfull\" id=\"btn_wi" + ob . num + "\" > + < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-success heighthalf hidden\" id=\"btn_widel" + ob . num + "\" > ✓ < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-danger heighthalf hidden\" id=\"btn_wican" + ob . num + "\" > X < / b u t t o n > \
< / d i v > \
2021-08-24 19:45:20 +02:00
< div class = \ "icon-container wikey\" > \
2021-08-19 13:48:33 +02:00
< input class = \ "form-control heightfull hidden\" type=\"text\" placeholder=\"Key(s)\" id=\"wikey" + ob . num + "\" > \
< input class = \ "form-control heighthalf hidden\" type=\"text\" placeholder=\"Primary Key(s)\" id=\"wikeyprimary" + ob . num + "\" > \
< input class = \ "form-control heighthalf hidden\" type=\"text\" placeholder=\"Secondary Key(s)\" id=\"wikeysecondary" + ob . num + "\" > \
2021-08-24 19:45:20 +02:00
< span class = \ "constant-key-icon oi oi-pin hidden\" id=\"constant-key-" + ob . num + "\" title=\"Toggle Constant Key mode (if enabled, this world info entry will always be included in memory)\" aria-hidden=\"true\" > < / s p a n > \
2021-05-13 07:26:42 +02:00
< / d i v > \
< div class = \ "wientry\" > \
2021-08-24 19:45:20 +02:00
< textarea class = \ "layer-bottom form-control hidden\" id=\"wientry" + ob . num + "\" placeholder=\"What To Remember\">" + ob . content + " < / t e x t a r e a > \
2021-05-13 07:26:42 +02:00
< / d i v > \
2021-08-19 13:48:33 +02:00
< div class = \ "wiselective\" > \
< button type = \ "button\" class=\"btn btn-success heightfull hidden\" id=\"btn_wiselon" + ob . num + "\" > Enable Selective Mode < / b u t t o n > \
< button type = \ "button\" class=\"btn btn-danger heightfull hidden\" id=\"btn_wiseloff" + ob . num + "\" > Disable Selective Mode < / b u t t o n > \
< / d i v > \
2021-05-13 07:26:42 +02:00
< / d i v > " ) ;
// Assign function to expand WI item to button
$ ( "#btn_wi" + ob . num ) . on ( "click" , function ( ) {
expandWiLine ( ob . num ) ;
} ) ;
}
// Assign actions to other elements
2021-08-24 19:45:20 +02:00
wientry _onfocus = function ( ) {
$ ( "#constant-key-" + ob . num ) . addClass ( "constant-key-icon-clickthrough" ) ;
}
wientry _onfocusout = function ( ) {
$ ( "#constant-key-" + ob . num ) . removeClass ( "constant-key-icon-clickthrough" ) ;
}
$ ( "#wikey" + ob . num ) . on ( "focus" , wientry _onfocus ) ;
$ ( "#wikeyprimary" + ob . num ) . on ( "focus" , wientry _onfocus ) ;
$ ( "#wikeysecondary" + ob . num ) . on ( "focus" , wientry _onfocus ) ;
$ ( "#wikey" + ob . num ) . on ( "focusout" , wientry _onfocusout ) ;
$ ( "#wikeyprimary" + ob . num ) . on ( "focusout" , wientry _onfocusout ) ;
$ ( "#wikeysecondary" + ob . num ) . on ( "focusout" , wientry _onfocusout ) ;
2021-05-13 07:26:42 +02:00
$ ( "#btn_wican" + ob . num ) . on ( "click" , function ( ) {
hideWiDeleteConfirm ( ob . num ) ;
} ) ;
$ ( "#btn_widel" + ob . num ) . on ( "click" , function ( ) {
socket . send ( { 'cmd' : 'widelete' , 'data' : ob . num } ) ;
} ) ;
2021-08-19 13:48:33 +02:00
$ ( "#btn_wiselon" + ob . num ) . on ( "click" , function ( ) {
enableWiSelective ( ob . num ) ;
2021-09-19 17:41:37 +02:00
$ ( "#wikey" + ob . num ) . addClass ( "wilistitem-selective" ) ;
2021-08-19 13:48:33 +02:00
} ) ;
$ ( "#btn_wiseloff" + ob . num ) . on ( "click" , function ( ) {
disableWiSelective ( ob . num ) ;
2021-09-19 17:41:37 +02:00
$ ( "#wikey" + ob . num ) . removeClass ( "wilistitem-selective" ) ;
2021-08-19 13:48:33 +02:00
} ) ;
2021-08-24 19:45:20 +02:00
$ ( "#constant-key-" + ob . num ) . on ( "click" , function ( ) {
2021-09-01 20:01:04 +02:00
var element = $ ( "#constant-key-" + ob . num ) ;
2021-08-24 19:45:20 +02:00
if ( element . hasClass ( "constant-key-icon-enabled" ) ) {
socket . send ( { 'cmd' : 'wiconstantoff' , 'data' : ob . num } ) ;
2021-09-19 17:41:37 +02:00
element . removeClass ( "constant-key-icon-enabled" ) ;
$ ( "#wikey" + ob . num ) . removeClass ( "wilistitem-constant" ) ;
2021-08-24 19:45:20 +02:00
} else {
socket . send ( { 'cmd' : 'wiconstanton' , 'data' : ob . num } ) ;
element . addClass ( "constant-key-icon-enabled" ) ;
2021-09-19 17:41:37 +02:00
$ ( "#wikey" + ob . num ) . addClass ( "wilistitem-constant" ) ;
2021-08-24 19:45:20 +02:00
}
} ) ;
2021-05-13 07:26:42 +02:00
}
function expandWiLine ( num ) {
2021-08-24 19:45:20 +02:00
show ( [ $ ( "#wikey" + num ) , $ ( "#wientry" + num ) , $ ( "#constant-key-" + num ) , $ ( "#btn_wiselon" + num ) ] ) ;
2021-05-13 07:26:42 +02:00
$ ( "#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 ) ] ) ;
}
2021-08-19 13:48:33 +02:00
function enableWiSelective ( num ) {
hide ( [ $ ( "#btn_wiselon" + num ) , $ ( "#wikey" + num ) ] ) ;
// Tell server the WI entry is now selective
socket . send ( { 'cmd' : 'wiselon' , 'data' : num } ) ;
2021-08-24 19:45:20 +02:00
$ ( "#wikeyprimary" + num ) . val ( $ ( "#wikey" + num ) . val ( ) ) ;
2021-08-19 13:48:33 +02:00
show ( [ $ ( "#wikeyprimary" + num ) , $ ( "#wikeysecondary" + num ) , $ ( "#btn_wiseloff" + num ) ] ) ;
}
function disableWiSelective ( num ) {
hide ( [ $ ( "#btn_wiseloff" + num ) , $ ( "#wikeyprimary" + num ) , $ ( "#wikeysecondary" + num ) ] ) ;
// Tell server the WI entry is now non-selective
socket . send ( { 'cmd' : 'wiseloff' , 'data' : num } ) ;
2021-08-24 19:45:20 +02:00
$ ( "#wikey" + num ) . val ( $ ( "#wikeyprimary" + num ) . val ( ) ) ;
2021-08-19 13:48:33 +02:00
show ( [ $ ( "#btn_wiselon" + num ) , $ ( "#wikey" + num ) ] ) ;
}
2021-05-11 06:27:34 +02:00
function highlightImportLine ( ref ) {
$ ( "#popupcontent > div" ) . removeClass ( "popuplistselected" ) ;
ref . addClass ( "popuplistselected" ) ;
2021-05-22 11:28:40 +02:00
enableButtons ( [ popup _accept ] ) ;
2021-05-11 06:27:34 +02:00
}
2021-05-05 09:04:06 +02:00
function enableButtons ( refs ) {
for ( i = 0 ; i < refs . length ; i ++ ) {
refs [ i ] . prop ( "disabled" , false ) ;
refs [ i ] . removeClass ( "btn-secondary" ) ;
refs [ i ] . addClass ( "btn-primary" ) ;
}
2021-05-03 00:48:47 +02:00
}
2021-05-05 09:04:06 +02:00
function disableButtons ( refs ) {
for ( i = 0 ; i < refs . length ; i ++ ) {
refs [ i ] . prop ( "disabled" , true ) ;
refs [ i ] . removeClass ( "btn-primary" ) ;
refs [ i ] . addClass ( "btn-secondary" ) ;
}
2021-05-03 00:48:47 +02:00
}
function enableSendBtn ( ) {
2021-05-05 09:04:06 +02:00
enableButtons ( [ button _send ] )
2021-05-03 00:48:47 +02:00
button _send . html ( "Submit" ) ;
}
function disableSendBtn ( ) {
2021-05-05 09:04:06 +02:00
disableButtons ( [ button _send ] )
2021-05-03 00:48:47 +02:00
button _send . html ( "" ) ;
}
function showMessage ( msg ) {
message _text . removeClass ( ) ;
message _text . addClass ( "color_green" ) ;
message _text . html ( msg ) ;
}
function errMessage ( msg ) {
message _text . removeClass ( ) ;
message _text . addClass ( "color_red" ) ;
message _text . html ( msg ) ;
}
function hideMessage ( ) {
message _text . html ( "" ) ;
message _text . removeClass ( ) ;
}
function showWaitAnimation ( ) {
$ ( "#inputrowright" ) . append ( "<img id=\"waitanim\" src=\"static/thinking.gif\"/>" ) ;
}
function hideWaitAnimation ( ) {
$ ( '#waitanim' ) . remove ( ) ;
}
2021-08-26 21:15:42 +02:00
function scrollToBottom ( ) {
setTimeout ( function ( ) {
2021-09-28 00:10:33 +02:00
game _text . stop ( true ) . animate ( { scrollTop : game _text . prop ( 'scrollHeight' ) } , 500 ) ;
2021-08-26 21:15:42 +02:00
} , 5 ) ;
}
2021-05-05 09:04:06 +02:00
function hide ( refs ) {
for ( i = 0 ; i < refs . length ; i ++ ) {
refs [ i ] . addClass ( "hidden" ) ;
}
2021-05-03 00:48:47 +02:00
}
2021-05-05 09:04:06 +02:00
function show ( refs ) {
for ( i = 0 ; i < refs . length ; i ++ ) {
refs [ i ] . removeClass ( "hidden" ) ;
}
2021-05-03 00:48:47 +02:00
}
2021-05-11 06:27:34 +02:00
function popupShow ( state ) {
if ( state ) {
popup . removeClass ( "hidden" ) ;
popup . addClass ( "flex" ) ;
2021-05-22 11:28:40 +02:00
disableButtons ( [ popup _accept ] ) ;
2021-05-11 06:27:34 +02:00
} else {
popup . removeClass ( "flex" ) ;
popup . addClass ( "hidden" ) ;
}
}
2021-05-03 00:48:47 +02:00
function enterEditMode ( ) {
2021-08-23 08:34:27 +02:00
editmode = true ;
2021-05-03 00:48:47 +02:00
}
function exitEditMode ( ) {
2021-08-23 08:34:27 +02:00
editmode = false ;
2021-05-03 00:48:47 +02:00
}
function enterMemoryMode ( ) {
2021-08-19 13:18:01 +02:00
memorymode = true ;
setmodevisibility ( false ) ;
2021-05-03 00:48:47 +02:00
showMessage ( "Edit the memory to be sent with each request to the AI." ) ;
button _actmem . html ( "Cancel" ) ;
2021-08-23 19:22:50 +02:00
hide ( [ button _actback , button _actretry , button _actwi ] ) ;
2021-05-05 09:04:06 +02:00
// Display Author's Note field
anote _menu . slideDown ( "fast" ) ;
2021-05-03 00:48:47 +02:00
}
function exitMemoryMode ( ) {
2021-08-19 13:18:01 +02:00
memorymode = false ;
setmodevisibility ( adventure ) ;
2021-05-03 00:48:47 +02:00
hideMessage ( ) ;
button _actmem . html ( "Memory" ) ;
2021-08-23 08:34:27 +02:00
show ( [ button _actback , button _actretry , button _actwi ] ) ;
2021-05-03 00:48:47 +02:00
input _text . val ( "" ) ;
2021-05-05 09:04:06 +02:00
// Hide Author's Note field
anote _menu . slideUp ( "fast" ) ;
2021-05-03 00:48:47 +02:00
}
2021-05-13 07:26:42 +02:00
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" ) ;
2021-08-23 08:34:27 +02:00
hide ( [ button _actback , button _actmem , button _actretry , game _text ] ) ;
2021-05-13 07:26:42 +02:00
show ( [ wi _menu ] ) ;
disableSendBtn ( ) ;
2021-09-29 01:00:23 +02:00
$ ( "#gamescreen" ) . addClass ( "wigamescreen" ) ;
2021-05-13 07:26:42 +02:00
}
function exitWiMode ( ) {
hideMessage ( ) ;
button _actwi . html ( "W Info" ) ;
hide ( [ wi _menu ] ) ;
2021-08-23 08:34:27 +02:00
show ( [ button _actback , button _actmem , button _actretry , game _text ] ) ;
2021-05-13 07:26:42 +02:00
enableSendBtn ( ) ;
2021-09-29 01:00:23 +02:00
$ ( "#gamescreen" ) . removeClass ( "wigamescreen" ) ;
2021-05-13 07:26:42 +02:00
}
function returnWiList ( ar ) {
var list = [ ] ;
var i ;
for ( i = 0 ; i < ar . length ; i ++ ) {
2021-08-24 19:45:20 +02:00
var ob = { "key" : "" , "keysecondary" : "" , "content" : "" , "num" : ar [ i ] , "selective" : false , "constant" : false } ;
2021-08-19 13:48:33 +02:00
ob . selective = $ ( "#wikeyprimary" + ar [ i ] ) . css ( "display" ) != "none"
ob . key = ob . selective ? $ ( "#wikeyprimary" + ar [ i ] ) . val ( ) : $ ( "#wikey" + ar [ i ] ) . val ( ) ;
ob . keysecondary = $ ( "#wikeysecondary" + ar [ i ] ) . val ( )
ob . content = $ ( "#wientry" + ar [ i ] ) . val ( ) ;
2021-08-24 19:45:20 +02:00
ob . constant = $ ( "#constant-key-" + ar [ i ] ) . hasClass ( "constant-key-icon-enabled" ) ;
2021-05-13 07:26:42 +02:00
list . push ( ob ) ;
}
socket . send ( { 'cmd' : 'sendwilist' , 'data' : list } ) ;
}
2021-10-13 06:42:03 +02:00
function formatChunkInnerText ( chunk ) {
var text = chunk . innerText . replace ( /\u00a0/g , " " ) ;
if ( ( chunk . nextSibling === null || chunk . nextSibling . nodeType !== 1 || chunk . nextSibling . tagName !== "CHUNK" ) && text . slice ( - 1 ) === '\n' ) {
return text . slice ( 0 , - 1 ) ;
}
return text ;
}
2021-05-03 00:48:47 +02:00
function dosubmit ( ) {
2021-09-29 01:48:43 +02:00
var txt = input _text . val ( ) . replace ( /\u00a0/g , " " ) ;
2021-09-30 16:57:29 +02:00
if ( ! memorymode && ! gamestarted && ( ( ! adventure || ! action _mode ) && txt . trim ( ) . length == 0 ) ) {
2021-09-29 01:48:43 +02:00
return ;
}
2021-08-19 13:18:01 +02:00
socket . send ( { 'cmd' : 'submit' , 'actionmode' : adventure ? action _mode : 0 , 'data' : txt } ) ;
2021-09-19 17:41:37 +02:00
if ( memorymode ) {
memorytext = input _text . val ( ) ;
}
2021-05-03 00:48:47 +02:00
input _text . val ( "" ) ;
hideMessage ( ) ;
2021-05-29 11:46:03 +02:00
hidegenseqs ( ) ;
2021-05-03 00:48:47 +02:00
}
2021-08-19 13:18:01 +02:00
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 ;
}
}
2021-05-03 00:48:47 +02:00
function newTextHighlight ( ref ) {
2021-08-23 08:34:27 +02:00
ref . addClass ( "edit-flash" ) ;
2021-05-03 00:48:47 +02:00
setTimeout ( function ( ) {
2021-08-23 08:34:27 +02:00
ref . addClass ( "colorfade" ) ;
ref . removeClass ( "edit-flash" ) ;
2021-05-03 00:48:47 +02:00
setTimeout ( function ( ) {
2021-05-16 11:29:39 +02:00
ref . removeClass ( "colorfade" ) ;
2021-05-03 00:48:47 +02:00
} , 1000 ) ;
2021-08-24 00:52:45 +02:00
} , 50 ) ;
2021-05-03 00:48:47 +02:00
}
2021-05-16 11:29:39 +02:00
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 ( "" ) ;
}
2021-05-22 11:28:40 +02:00
function showSaveAsPopup ( ) {
disableButtons ( [ saveas _accept ] ) ;
saveaspopup . removeClass ( "hidden" ) ;
saveaspopup . addClass ( "flex" ) ;
saveasinput . focus ( ) ;
}
function hideSaveAsPopup ( ) {
saveaspopup . removeClass ( "flex" ) ;
saveaspopup . addClass ( "hidden" ) ;
saveasinput . val ( "" ) ;
2021-09-01 00:22:30 +02:00
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
2021-05-22 11:28:40 +02:00
}
function sendSaveAsRequest ( ) {
socket . send ( { 'cmd' : 'saveasrequest' , 'data' : saveasinput . val ( ) } ) ;
}
function showLoadPopup ( ) {
loadpopup . removeClass ( "hidden" ) ;
loadpopup . addClass ( "flex" ) ;
}
function hideLoadPopup ( ) {
loadpopup . removeClass ( "flex" ) ;
loadpopup . addClass ( "hidden" ) ;
loadcontent . html ( "" ) ;
}
2021-10-22 20:18:10 +02:00
function showSPPopup ( ) {
sppopup . removeClass ( "hidden" ) ;
sppopup . addClass ( "flex" ) ;
}
function hideSPPopup ( ) {
sppopup . removeClass ( "flex" ) ;
sppopup . addClass ( "hidden" ) ;
spcontent . html ( "" ) ;
}
2021-05-22 11:28:40 +02:00
function buildLoadList ( ar ) {
disableButtons ( [ load _accept ] ) ;
loadcontent . html ( "" ) ;
showLoadPopup ( ) ;
var i ;
for ( i = 0 ; i < ar . length ; i ++ ) {
2021-09-01 00:22:30 +02:00
loadcontent . append ( "<div class=\"flex\" > \
< div class = \ "loadlistpadding\" > < / d i v > \
< span class = \ "loadlisticon loadlisticon-delete oi oi-x " + ( sman _allow _delete ? "allowed" : "" ) + "\" id=\"loaddelete" + i + "\" " + ( sman _allow _delete ? "title=\"Delete story\"" : "" ) + " aria-hidden=\"true\" > < / s p a n > \
< div class = \ "loadlistpadding\" > < / d i v > \
< span class = \ "loadlisticon loadlisticon-rename oi oi-pencil " + ( sman _allow _rename ? "allowed" : "" ) + "\" id=\"loadrename" + i + "\" " + ( sman _allow _rename ? "title=\"Rename story\"" : "" ) + " aria-hidden=\"true\" > < / s p a n > \
< div class = \ "loadlistpadding\" > < / d i v > \
< div class = \ "loadlistitem\" id=\"load" + i + "\" name=\"" + ar [ i ] . name + "\" > \
< div > "+ar[i].name+" < / d i v > \
< div class = \ "flex-push-right\">" + ar [ i ] . actions + " < / d i v > \
< / d i v > \
2021-05-22 11:28:40 +02:00
< / d i v > " ) ;
$ ( "#load" + i ) . on ( "click" , function ( ) {
enableButtons ( [ load _accept ] ) ;
socket . send ( { 'cmd' : 'loadselect' , 'data' : $ ( this ) . attr ( "name" ) } ) ;
highlightLoadLine ( $ ( this ) ) ;
} ) ;
2021-09-01 00:22:30 +02:00
$ ( "#loaddelete" + i ) . off ( "click" ) . on ( "click" , ( function ( name ) {
return function ( ) {
if ( ! sman _allow _delete ) {
return ;
}
$ ( "#loadcontainerdelete-storyname" ) . text ( name ) ;
$ ( "#btn_dsaccept" ) . off ( "click" ) . on ( "click" , ( function ( name ) {
return function ( ) {
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
socket . send ( { 'cmd' : 'deletestory' , 'data' : name } ) ;
}
} ) ( name ) ) ;
$ ( "#loadcontainerdelete" ) . removeClass ( "hidden" ) . addClass ( "flex" ) ;
}
} ) ( ar [ i ] . name ) ) ;
$ ( "#loadrename" + i ) . off ( "click" ) . on ( "click" , ( function ( name ) {
return function ( ) {
if ( ! sman _allow _rename ) {
return ;
}
$ ( "#newsavename" ) . val ( "" )
$ ( "#loadcontainerrename-storyname" ) . text ( name ) ;
2021-09-01 20:01:04 +02:00
var submit = ( function ( name ) {
2021-09-01 00:22:30 +02:00
return function ( ) {
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
socket . send ( { 'cmd' : 'renamestory' , 'data' : name , 'newname' : $ ( "#newsavename" ) . val ( ) } ) ;
}
} ) ( name ) ;
$ ( "#btn_rensaccept" ) . off ( "click" ) . on ( "click" , submit ) ;
2021-09-01 20:12:12 +02:00
$ ( "#newsavename" ) . off ( "keydown" ) . on ( "keydown" , function ( ev ) {
if ( ev . which == 13 && $ ( this ) . val ( ) != "" ) {
submit ( ) ;
}
} ) ;
2021-09-01 00:22:30 +02:00
$ ( "#loadcontainerrename" ) . removeClass ( "hidden" ) . addClass ( "flex" ) ;
$ ( "#newsavename" ) . val ( name ) . select ( ) ;
}
} ) ( ar [ i ] . name ) ) ;
2021-05-22 11:28:40 +02:00
}
}
2021-10-22 20:18:10 +02:00
function buildSPList ( ar ) {
disableButtons ( [ sp _accept ] ) ;
spcontent . html ( "" ) ;
showSPPopup ( ) ;
ar . push ( { filename : '' , name : "[None]" } )
for ( var i = 0 ; i < ar . length ; i ++ ) {
var supported = ! ar [ i ] . supported
? ''
: Object . prototype . toString . call ( ar [ i ] . supported ) === "[object Array]"
? "[" + ar [ i ] . supported . join ( ', ' ) + "]"
: "[" + ar [ i ] . supported . toString ( ) + "]" ;
2021-10-22 20:25:25 +02:00
var filename = ar [ i ] . filename . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /"/g , '"' ) . replace ( /'/g , ''' ) . replace ( /(?=\r|\n)\r?\n?/g , '<br/>' ) ;
2021-10-22 20:18:10 +02:00
var name = ar [ i ] . name || ar [ i ] . filename ;
name = name . length > 120 ? name . slice ( 0 , 117 ) + '...' : name ;
2021-10-22 20:25:25 +02:00
name = name . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /"/g , '"' ) . replace ( /'/g , ''' ) . replace ( /(?=\r|\n)\r?\n?/g , '<br/>' ) ;
2021-10-22 20:18:10 +02:00
var desc = ar [ i ] . description || '' ;
desc = desc . length > 500 ? desc . slice ( 0 , 497 ) + '...' : desc ;
2021-10-22 20:25:25 +02:00
desc = desc . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /"/g , '"' ) . replace ( /'/g , ''' ) . replace ( /(?=\r|\n)\r?\n?/g , '<br/>' ) ;
2021-10-22 20:18:10 +02:00
spcontent . append ( "<div class=\"flex\" > \
< div class = \ "splistitem flex-row-container\" id=\"sp" + i + "\" name=\"" + ar [ i ] . filename + "\" > \
< div class = \ "flex-row\" > \
< div > "+name+" < / d i v > \
2021-10-22 20:25:25 +02:00
< div class = \ "flex-push-right splistitemsub\">" + filename + " < / d i v > \
2021-10-22 20:18:10 +02:00
< / d i v > \
< div class = \ "flex-row\" > \
< div > "+desc+" < / d i v > \
< div class = \ "flex-push-right splistitemsub\">" + supported + " < / d i v > \
< / d i v > \
< / d i v > \
< / d i v > " ) ;
$ ( "#sp" + i ) . on ( "click" , function ( ) {
enableButtons ( [ sp _accept ] ) ;
socket . send ( { 'cmd' : 'spselect' , 'data' : $ ( this ) . attr ( "name" ) } ) ;
highlightSPLine ( $ ( this ) ) ;
} ) ;
}
}
2021-05-22 11:28:40 +02:00
function highlightLoadLine ( ref ) {
2021-09-01 20:21:07 +02:00
$ ( "#loadlistcontent > div > div.popuplistselected" ) . removeClass ( "popuplistselected" ) ;
2021-05-22 11:28:40 +02:00
ref . addClass ( "popuplistselected" ) ;
}
2021-10-22 20:18:10 +02:00
function highlightSPLine ( ref ) {
$ ( "#splistcontent > div > div.popuplistselected" ) . removeClass ( "popuplistselected" ) ;
ref . addClass ( "popuplistselected" ) ;
}
2021-05-22 11:28:40 +02:00
function showNewStoryPopup ( ) {
nspopup . removeClass ( "hidden" ) ;
nspopup . addClass ( "flex" ) ;
}
function hideNewStoryPopup ( ) {
nspopup . removeClass ( "flex" ) ;
nspopup . addClass ( "hidden" ) ;
}
2021-08-19 12:54:44 +02:00
function showRandomStoryPopup ( ) {
rspopup . removeClass ( "hidden" ) ;
rspopup . addClass ( "flex" ) ;
}
function hideRandomStoryPopup ( ) {
rspopup . removeClass ( "flex" ) ;
rspopup . addClass ( "hidden" ) ;
}
2021-05-29 11:46:03 +02:00
function setStartState ( ) {
enableSendBtn ( ) ;
enableButtons ( [ button _actmem , button _actwi ] ) ;
2021-08-23 08:34:27 +02:00
disableButtons ( [ button _actback , button _actretry ] ) ;
2021-08-23 19:22:50 +02:00
hide ( [ wi _menu ] ) ;
2021-08-23 08:34:27 +02:00
show ( [ game _text , button _actmem , button _actwi , button _actback , button _actretry ] ) ;
2021-05-29 11:46:03 +02:00
hideMessage ( ) ;
hideWaitAnimation ( ) ;
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 . length ; i ++ ) {
seqselcontents . append ( "<div class=\"seqselitem\" id=\"seqsel" + i + "\" n=\"" + i + "\">" + seqs [ i ] . generated _text + "</div>" ) ;
$ ( "#seqsel" + i ) . on ( "click" , function ( ) {
socket . send ( { 'cmd' : 'seqsel' , 'data' : $ ( this ) . attr ( "n" ) } ) ;
} ) ;
}
$ ( '#seqselmenu' ) . slideDown ( "slow" ) ;
}
function hidegenseqs ( ) {
$ ( '#seqselmenu' ) . slideUp ( "slow" , function ( ) {
seqselcontents . html ( "" ) ;
} ) ;
2021-08-26 21:15:42 +02:00
scrollToBottom ( ) ;
2021-05-29 11:46:03 +02:00
}
2021-08-19 13:18:01 +02:00
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 ;
2021-08-26 07:06:57 +02:00
if ( state ) {
game _text . addClass ( "adventure" ) ;
} else {
game _text . removeClass ( "adventure" ) ;
}
2021-08-19 13:18:01 +02:00
if ( ! memorymode ) {
setmodevisibility ( state ) ;
}
}
2021-08-23 08:34:27 +02:00
function autofocus ( event ) {
if ( connected ) {
event . target . focus ( ) ;
} else {
event . preventDefault ( ) ;
}
}
2021-10-12 06:09:02 +02:00
function chunkOnTextInput ( event ) {
// The enter key does not behave correctly in almost all non-Firefox
// browsers, so we (attempt to) shim all enter keystrokes here to behave the
// same as in Firefox
if ( event . originalEvent . data . slice ( - 1 ) === '\n' ) {
event . preventDefault ( ) ;
var s = getSelection ( ) ; // WARNING: Do not use rangy.getSelection() instead of getSelection()
var r = s . getRangeAt ( 0 ) ;
// We prefer using document.execCommand here because it works best on
// mobile devices, but the other method is also here as
// a fallback
if ( document . queryCommandSupported && document . execCommand && document . queryCommandSupported ( 'insertHTML' ) ) {
2021-10-13 18:43:45 +02:00
document . execCommand ( 'insertHTML' , false , event . originalEvent . data . slice ( 0 , - 1 ) . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /"/g , '"' ) . replace ( /'/g , ''' ) . replace ( /(?=\r|\n)\r?\n?/g , '<br/>' ) + '<br id="_EDITOR_LINEBREAK_"/><span id="_EDITOR_SENTINEL_">|</span>' ) ;
2021-10-12 06:09:02 +02:00
var t = $ ( '#_EDITOR_SENTINEL_' ) . contents ( ) . filter ( function ( ) { return this . nodeType === 3 ; } ) [ 0 ] ;
} else {
var t = document . createTextNode ( '|' ) ;
2021-10-13 06:42:03 +02:00
var b = document . createElement ( 'br' ) ;
b . id = "_EDITOR_LINEBREAK_" ;
r . insertNode ( b ) ;
2021-10-12 06:09:02 +02:00
r . collapse ( false ) ;
r . insertNode ( t ) ;
}
r . selectNodeContents ( t ) ;
s . removeAllRanges ( ) ;
s . addRange ( r ) ;
if ( document . queryCommandSupported && document . execCommand && document . queryCommandSupported ( 'forwardDelete' ) ) {
r . collapse ( true ) ;
document . execCommand ( 'forwardDelete' ) ;
} else {
// deleteContents() sometimes breaks using the left
// arrow key in some browsers so we prefer the
// document.execCommand method
r . deleteContents ( ) ;
}
2021-10-13 06:42:03 +02:00
// In Chrome the added <br/> will go outside of the chunks if we press
// enter at the end of the story in the editor, so this is here
// to put the <br/> back in the right place
var br = $ ( "#_EDITOR_LINEBREAK_" ) [ 0 ] ;
if ( br . parentNode === game _text [ 0 ] ) {
if ( br . previousSibling . nodeType !== 1 ) {
br . previousSibling . previousSibling . appendChild ( br . previousSibling ) ;
}
br . previousSibling . appendChild ( br ) ;
r . selectNodeContents ( br . parentNode ) ;
s . removeAllRanges ( ) ;
s . addRange ( r ) ;
r . collapse ( false ) ;
}
br . id = "" ;
if ( game _text [ 0 ] . lastChild . tagName === "BR" ) {
br . parentNode . appendChild ( game _text [ 0 ] . lastChild ) ;
}
2021-10-12 06:09:02 +02:00
return ;
}
}
2021-11-18 19:18:18 +01:00
// This gets run when one or more chunks are edited. The event occurs before
// the actual edits are made by the browser, so we are free to check which
// nodes are selected or stop the event from occurring.
function chunkOnBeforeInput ( event ) {
// Register all selected chunks as having been modified
applyChunkDeltas ( getSelectedNodes ( ) ) ;
// Fix editing across chunks and paragraphs in Firefox 93.0 and higher
if ( event . originalEvent . inputType === "deleteContentBackward" && document . queryCommandSupported && document . execCommand && document . queryCommandSupported ( 'delete' ) ) {
event . preventDefault ( ) ;
document . execCommand ( 'delete' ) ;
}
var s = rangy . getSelection ( ) ;
if ( ! s . isCollapsed ) {
s . deleteFromDocument ( ) ;
}
if ( buildChunkSetFromNodeArray ( getSelectedNodes ( ) ) . size === 0 ) {
var s = rangy . getSelection ( ) ;
var r = s . getRangeAt ( 0 ) ;
if ( document . queryCommandSupported && document . execCommand && document . queryCommandSupported ( 'insertHTML' ) ) {
document . execCommand ( 'insertHTML' , false , '<span id="_EDITOR_SENTINEL_">|</span>' ) ;
} else {
var t = document . createTextNode ( '|' ) ;
var b = document . createElement ( 'span' ) ;
b . id = "_EDITOR_SENTINEL_" ;
b . insertNode ( t ) ;
r . insertNode ( b ) ;
}
var sentinel = document . getElementById ( "_EDITOR_SENTINEL_" ) ;
if ( sentinel . nextSibling && sentinel . nextSibling . tagName === "CHUNK" ) {
r . selectNodeContents ( sentinel . nextSibling ) ;
r . collapse ( true ) ;
} else if ( sentinel . previousSibling && sentinel . previousSibling . tagName === "CHUNK" ) {
r . selectNodeContents ( sentinel . previousSibling ) ;
r . collapse ( false ) ;
}
s . removeAllRanges ( ) ;
s . addRange ( r ) ;
sentinel . parentNode . removeChild ( sentinel ) ;
}
}
2021-08-23 08:34:27 +02:00
function chunkOnKeyDown ( event ) {
2021-08-24 01:18:09 +02:00
// Make escape commit the changes (Originally we had Enter here to but its not required and nicer for users if we let them type freely
// You can add the following after 27 if you want it back to committing on enter : || (!event.shiftKey && event.keyCode == 13)
if ( event . keyCode == 27 ) {
2021-09-28 04:56:12 +02:00
override _focusout = true ;
game _text . blur ( ) ;
2021-08-23 08:34:27 +02:00
event . preventDefault ( ) ;
return ;
}
// Don't allow any edits if not connected to server
if ( ! connected ) {
event . preventDefault ( ) ;
return ;
}
// Prevent CTRL+B, CTRL+I and CTRL+U when editing chunks
if ( event . ctrlKey || event . metaKey ) { // metaKey is macOS's command key
switch ( event . keyCode ) {
case 66 :
case 98 :
case 73 :
case 105 :
case 85 :
case 117 :
event . preventDefault ( ) ;
return ;
}
}
}
2021-09-19 17:41:37 +02:00
function downloadStory ( format ) {
2021-09-19 17:59:31 +02:00
var filename _without _extension = storyname !== null ? storyname : "untitled" ;
2021-09-19 17:41:37 +02:00
var anchor = document . createElement ( 'a' ) ;
var actionlist = $ ( "chunk" ) ;
var actionlist _compiled = [ ] ;
for ( var i = 0 ; i < actionlist . length ; i ++ ) {
actionlist _compiled . push ( actionlist [ i ] . innerText . replace ( /\u00a0/g , " " ) ) ;
}
2021-10-13 06:42:03 +02:00
var last = actionlist _compiled [ actionlist _compiled . length - 1 ] ;
if ( last . slice ( - 1 ) === '\n' ) {
actionlist _compiled [ actionlist _compiled . length - 1 ] = last . slice ( 0 , - 1 ) ;
}
2021-09-19 17:41:37 +02:00
if ( format == "plaintext" ) {
var objectURL = URL . createObjectURL ( new Blob ( actionlist _compiled ) ) ;
anchor . setAttribute ( 'href' , objectURL ) ;
anchor . setAttribute ( 'download' , filename _without _extension + ".txt" ) ;
anchor . click ( ) ;
URL . revokeObjectURL ( objectURL ) ;
return ;
}
var wilist = $ ( ".wilistitem" ) ;
var wilist _compiled = [ ] ;
for ( var i = 0 ; i < wilist . length - 1 ; i ++ ) {
var selective = wilist [ i ] . classList . contains ( "wilistitem-selective" ) ;
wilist _compiled . push ( {
key : selective ? $ ( "#wikeyprimary" + i ) . val ( ) : $ ( "#wikey" + i ) . val ( ) ,
keysecondary : $ ( "#wikeysecondary" + i ) . val ( ) ,
content : $ ( "#wientry" + i ) . val ( ) ,
selective : selective ,
constant : wilist [ i ] . classList . contains ( "wilistitem-constant" ) ,
} ) ;
}
var prompt = actionlist _compiled . shift ( ) ;
if ( prompt === undefined ) {
prompt = "" ;
}
var objectURL = URL . createObjectURL ( new Blob ( [ JSON . stringify ( {
gamestarted : gamestarted ,
prompt : prompt ,
memory : memorytext ,
authorsnote : $ ( "#anoteinput" ) . val ( ) ,
actions : actionlist _compiled ,
worldinfo : wilist _compiled ,
2021-09-20 05:48:04 +02:00
} , null , 3 ) ] ) ) ;
2021-09-19 17:41:37 +02:00
anchor . setAttribute ( 'href' , objectURL ) ;
anchor . setAttribute ( 'download' , filename _without _extension + ".json" ) ;
anchor . click ( ) ;
URL . revokeObjectURL ( objectURL ) ;
}
2021-09-27 19:11:15 +02:00
function buildChunkSetFromNodeArray ( nodes ) {
var set = new Set ( ) ;
for ( var i = 0 ; i < nodes . length ; i ++ ) {
node = nodes [ i ] ;
while ( node !== null && node . tagName !== "CHUNK" ) {
node = node . parentNode ;
}
if ( node === null ) {
continue ;
}
set . add ( node . getAttribute ( "n" ) ) ;
}
return set ;
}
function getSelectedNodes ( ) {
var range = rangy . getSelection ( ) . getRangeAt ( 0 ) ; // rangy is not a typo
var nodes = range . getNodes ( [ 1 , 3 ] ) ;
nodes . push ( range . startContainer ) ;
nodes . push ( range . endContainer ) ;
return nodes
}
function applyChunkDeltas ( nodes ) {
var chunks = Array . from ( buildChunkSetFromNodeArray ( nodes ) ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
modified _chunks . add ( chunks [ i ] ) ;
}
setTimeout ( function ( ) {
var chunks = Array . from ( modified _chunks ) ;
var selected _chunks = buildChunkSetFromNodeArray ( getSelectedNodes ( ) ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
var chunk = document . getElementById ( "n" + chunks [ i ] ) ;
2021-10-13 06:42:03 +02:00
if ( chunk && formatChunkInnerText ( chunk ) . length != 0 && chunks [ i ] != '0' ) {
2021-09-27 19:11:15 +02:00
if ( ! selected _chunks . has ( chunks [ i ] ) ) {
modified _chunks . delete ( chunks [ i ] ) ;
2021-10-13 06:42:03 +02:00
socket . send ( { 'cmd' : 'inlineedit' , 'chunk' : chunks [ i ] , 'data' : formatChunkInnerText ( chunk ) } ) ;
2021-09-27 19:11:15 +02:00
}
empty _chunks . delete ( chunks [ i ] ) ;
} else {
if ( ! selected _chunks . has ( chunks [ i ] ) ) {
modified _chunks . delete ( chunks [ i ] ) ;
socket . send ( { 'cmd' : 'inlineedit' , 'chunk' : chunks [ i ] , 'data' : '' } ) ;
}
empty _chunks . add ( chunks [ i ] ) ;
}
}
} , 2 ) ;
}
function syncAllModifiedChunks ( including _selected _chunks = false ) {
var chunks = Array . from ( modified _chunks ) ;
var selected _chunks = buildChunkSetFromNodeArray ( getSelectedNodes ( ) ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
if ( including _selected _chunks || ! selected _chunks . has ( chunks [ i ] ) ) {
modified _chunks . delete ( chunks [ i ] ) ;
var chunk = document . getElementById ( "n" + chunks [ i ] ) ;
2021-10-13 06:42:03 +02:00
var data = chunk ? formatChunkInnerText ( document . getElementById ( "n" + chunks [ i ] ) ) : "" ;
2021-09-27 19:11:15 +02:00
if ( data . length == 0 ) {
empty _chunks . add ( chunks [ i ] ) ;
} else {
empty _chunks . delete ( chunks [ i ] ) ;
}
socket . send ( { 'cmd' : 'inlineedit' , 'chunk' : chunks [ i ] , 'data' : data } ) ;
}
}
}
2021-09-28 04:21:14 +02:00
function restorePrompt ( ) {
2021-09-29 01:48:43 +02:00
if ( game _text [ 0 ] . firstChild && game _text [ 0 ] . firstChild . nodeType === 3 ) {
2021-10-13 06:42:03 +02:00
saved _prompt = formatChunkInnerText ( game _text [ 0 ] . firstChild ) ;
2021-09-28 04:21:14 +02:00
unbindGametext ( ) ;
game _text [ 0 ] . innerText = "" ;
bindGametext ( ) ;
}
if ( $ ( "#n0" ) . length ) {
$ ( "#n0" ) . remove ( ) ;
}
var prompt _chunk = document . createElement ( "chunk" ) ;
prompt _chunk . setAttribute ( "n" , "0" ) ;
prompt _chunk . setAttribute ( "id" , "n0" ) ;
prompt _chunk . setAttribute ( "tabindex" , "-1" ) ;
prompt _chunk . innerText = saved _prompt ;
unbindGametext ( ) ;
game _text [ 0 ] . prepend ( prompt _chunk ) ;
bindGametext ( ) ;
modified _chunks . delete ( '0' ) ;
empty _chunks . delete ( '0' ) ;
socket . send ( { 'cmd' : 'inlineedit' , 'chunk' : '0' , 'data' : saved _prompt } ) ;
}
2021-09-27 19:11:15 +02:00
function deleteEmptyChunks ( ) {
var chunks = Array . from ( empty _chunks ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
empty _chunks . delete ( chunks [ i ] ) ;
2021-09-28 04:21:14 +02:00
if ( chunks [ i ] === "0" ) {
// Don't delete the prompt
restorePrompt ( ) ;
} else {
socket . send ( { 'cmd' : 'inlinedelete' , 'data' : chunks [ i ] } ) ;
}
2021-09-27 19:11:15 +02:00
}
2021-09-28 04:21:14 +02:00
if ( modified _chunks . has ( '0' ) ) {
modified _chunks . delete ( chunks [ i ] ) ;
2021-10-13 06:42:03 +02:00
socket . send ( { 'cmd' : 'inlineedit' , 'chunk' : chunks [ i ] , 'data' : formatChunkInnerText ( document . getElementById ( "n0" ) ) } ) ;
2021-09-28 04:21:14 +02:00
}
2021-10-13 06:42:03 +02:00
saved _prompt = formatChunkInnerText ( $ ( "#n0" ) [ 0 ] ) ;
2021-09-27 19:11:15 +02:00
}
function highlightEditingChunks ( ) {
var chunks = $ ( 'chunk.editing' ) . toArray ( ) ;
var selected _chunks = buildChunkSetFromNodeArray ( getSelectedNodes ( ) ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
var chunk = chunks [ i ] ;
if ( ! selected _chunks . has ( chunks [ i ] . getAttribute ( "n" ) ) ) {
unbindGametext ( ) ;
$ ( chunk ) . removeClass ( 'editing' ) ;
bindGametext ( ) ;
}
}
chunks = Array . from ( selected _chunks ) ;
for ( var i = 0 ; i < chunks . length ; i ++ ) {
var chunk = $ ( "#n" + chunks [ i ] ) ;
unbindGametext ( ) ;
chunk . addClass ( 'editing' ) ;
bindGametext ( ) ;
}
}
// This gets run every time you try to paste text into the editor
function chunkOnPaste ( event ) {
2021-11-18 19:18:18 +01:00
// Register the chunk we're pasting in as having been modified
applyChunkDeltas ( getSelectedNodes ( ) ) ;
2021-09-27 19:11:15 +02:00
// If possible, intercept paste events into the editor in order to always
// paste as plaintext
2021-10-13 18:51:31 +02:00
if ( event . originalEvent . clipboardData && document . queryCommandSupported && document . execCommand && document . queryCommandSupported ( 'insertHTML' ) ) {
2021-09-27 19:11:15 +02:00
event . preventDefault ( ) ;
2021-10-13 18:43:45 +02:00
document . execCommand ( 'insertHTML' , false , event . originalEvent . clipboardData . getData ( 'text/plain' ) . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /"/g , '"' ) . replace ( /'/g , ''' ) . replace ( /(?=\r|\n)\r?\n?/g , '<br/>' ) ) ;
2021-10-13 18:41:43 +02:00
} else if ( event . originalEvent . clipboardData ) {
event . preventDefault ( ) ;
var s = getSelection ( ) ; // WARNING: Do not use rangy.getSelection() instead of getSelection()
var r = s . getRangeAt ( 0 ) ;
r . deleteContents ( ) ;
2021-10-13 18:43:45 +02:00
var nodes = Array . from ( $ ( '<span>' + event . originalEvent . clipboardData . getData ( 'text/plain' ) . replace ( /&/g , '&' ) . replace ( /</g , '<' ) . replace ( />/g , '>' ) . replace ( /"/g , '"' ) . replace ( /'/g , ''' ) . replace ( /(?=\r|\n)\r?\n?/g , '<br/>' ) + '</span>' ) [ 0 ] . childNodes ) ;
2021-10-13 18:41:43 +02:00
for ( var i = 0 ; i < nodes . length ; i ++ ) {
r . insertNode ( nodes [ i ] ) ;
r . collapse ( false ) ;
}
}
2021-09-27 19:11:15 +02:00
}
2021-09-27 21:57:07 +02:00
// This gets run every time the caret moves in the editor
2021-09-30 23:52:35 +02:00
function _chunkOnSelectionChange ( event , do _blur _focus ) {
2021-09-28 06:48:37 +02:00
if ( ! gametext _bound || ! allowedit || override _focusout ) {
2021-09-28 04:56:12 +02:00
override _focusout = false ;
2021-09-27 19:11:15 +02:00
return ;
}
setTimeout ( function ( ) {
syncAllModifiedChunks ( ) ;
setTimeout ( function ( ) {
highlightEditingChunks ( ) ;
2021-09-27 23:44:22 +02:00
// Attempt to prevent Chromium-based browsers on Android from
// scrolling away from the current selection
2021-09-30 23:52:35 +02:00
if ( do _blur _focus && ! using _webkit _patch ) {
2021-09-30 20:13:54 +02:00
setTimeout ( function ( ) {
game _text . blur ( ) ;
game _text . focus ( ) ;
} , 144 ) ;
}
2021-09-27 19:11:15 +02:00
} , 2 ) ;
} , 2 ) ;
}
2021-09-30 23:52:35 +02:00
function chunkOnSelectionChange ( event ) {
return _chunkOnSelectionChange ( event , true ) ;
}
function chunkOnKeyDownSelectionChange ( event ) {
return _chunkOnSelectionChange ( event , false ) ;
}
2021-09-27 21:57:07 +02:00
// This gets run when you defocus the editor by clicking
2021-09-27 19:11:15 +02:00
// outside of the editor or by pressing escape or tab
function chunkOnFocusOut ( event ) {
2021-09-28 06:48:37 +02:00
if ( ! gametext _bound || ! allowedit || event . target !== game _text [ 0 ] ) {
2021-09-27 19:11:15 +02:00
return ;
}
setTimeout ( function ( ) {
2021-09-27 22:04:42 +02:00
if ( document . activeElement === game _text [ 0 ] || game _text [ 0 ] . contains ( document . activeElement ) ) {
2021-09-27 19:11:15 +02:00
return ;
}
syncAllModifiedChunks ( true ) ;
setTimeout ( function ( ) {
2021-09-27 22:04:42 +02:00
var blurred = game _text [ 0 ] !== document . activeElement ;
2021-09-27 19:11:15 +02:00
if ( blurred ) {
deleteEmptyChunks ( ) ;
}
setTimeout ( function ( ) {
$ ( "chunk" ) . removeClass ( 'editing' ) ;
} , 2 ) ;
} , 2 ) ;
} , 2 ) ;
}
function bindGametext ( ) {
gametext _bound = true ;
}
function unbindGametext ( ) {
gametext _bound = false ;
}
2021-05-03 00:48:47 +02:00
//=================================================================//
// READY/RUNTIME
//=================================================================//
$ ( document ) . ready ( function ( ) {
2021-05-05 09:04:06 +02:00
// Bind UI references
2021-05-22 11:28:40 +02:00
connect _status = $ ( '#connectstatus' ) ;
button _newgame = $ ( '#btn_newgame' ) ;
2021-08-19 12:54:44 +02:00
button _rndgame = $ ( '#btn_rndgame' ) ;
2021-05-22 11:28:40 +02:00
button _save = $ ( '#btn_save' ) ;
button _saveas = $ ( '#btn_saveas' ) ;
button _savetofile = $ ( '#btn_savetofile' ) ;
2021-09-01 19:32:11 +02:00
button _download = $ ( '#btn_download' ) ;
2021-09-01 19:46:37 +02:00
button _downloadtxt = $ ( '#btn_downloadtxt' ) ;
2021-05-22 11:28:40 +02:00
button _load = $ ( '#btn_load' ) ;
button _loadfrfile = $ ( '#btn_loadfromfile' ) ;
button _import = $ ( "#btn_import" ) ;
2021-05-29 11:46:03 +02:00
button _importwi = $ ( "#btn_importwi" ) ;
2021-05-22 11:28:40 +02:00
button _impaidg = $ ( "#btn_impaidg" ) ;
button _settings = $ ( '#btn_settings' ) ;
button _format = $ ( '#btn_format' ) ;
2021-10-22 20:18:10 +02:00
button _softprompt = $ ( "#btn_softprompt" ) ;
2021-08-19 13:18:01 +02:00
button _mode = $ ( '#btnmode' )
button _mode _label = $ ( '#btnmode_label' )
2021-05-22 11:28:40 +02:00
button _send = $ ( '#btnsend' ) ;
button _actmem = $ ( '#btn_actmem' ) ;
button _actback = $ ( '#btn_actundo' ) ;
button _actretry = $ ( '#btn_actretry' ) ;
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" ) ;
2021-08-19 12:54:44 +02:00
topic = $ ( "#topic" ) ;
2021-05-22 11:28:40 +02:00
saveas _accept = $ ( "#btn_saveasaccept" ) ;
saveas _close = $ ( "#btn_saveasclose" ) ;
loadpopup = $ ( "#loadcontainer" ) ;
loadcontent = $ ( "#loadlistcontent" ) ;
load _accept = $ ( "#btn_loadaccept" ) ;
load _close = $ ( "#btn_loadclose" ) ;
2021-10-22 20:18:10 +02:00
sppopup = $ ( "#spcontainer" ) ;
spcontent = $ ( "#splistcontent" ) ;
sp _accept = $ ( "#btn_spaccept" ) ;
sp _close = $ ( "#btn_spclose" ) ;
2021-05-22 11:28:40 +02:00
nspopup = $ ( "#newgamecontainer" ) ;
ns _accept = $ ( "#btn_nsaccept" ) ;
ns _close = $ ( "#btn_nsclose" ) ;
2021-08-19 12:54:44 +02:00
rspopup = $ ( "#rndgamecontainer" ) ;
rs _accept = $ ( "#btn_rsaccept" ) ;
rs _close = $ ( "#btn_rsclose" ) ;
2021-05-29 11:46:03 +02:00
seqselmenu = $ ( "#seqselmenu" ) ;
seqselcontents = $ ( "#seqselcontents" ) ;
2021-09-30 20:13:54 +02:00
2021-08-25 00:32:48 +02:00
// Connect to SocketIO server
socket = io . connect ( window . document . origin ) ;
2021-05-03 00:48:47 +02:00
socket . on ( 'from_server' , function ( msg ) {
2021-08-25 00:32:48 +02:00
if ( msg . cmd == "connected" ) {
2021-05-03 00:48:47 +02:00
// Connected to Server Actions
2021-09-01 00:22:30 +02:00
sman _allow _delete = msg . hasOwnProperty ( "smandelete" ) && msg . smandelete ;
sman _allow _rename = msg . hasOwnProperty ( "smanrename" ) && msg . smanrename ;
2021-08-23 08:34:27 +02:00
connected = true ;
2021-05-07 20:32:10 +02:00
connect _status . html ( "<b>Connected to KoboldAI Process!</b>" ) ;
connect _status . removeClass ( "color_orange" ) ;
connect _status . addClass ( "color_green" ) ;
2021-05-13 07:26:42 +02:00
// Reset Menus
2021-05-07 20:32:10 +02:00
settings _menu . html ( "" ) ;
2021-05-11 01:17:10 +02:00
format _menu . html ( "" ) ;
2021-05-13 07:26:42 +02:00
wi _menu . html ( "" ) ;
2021-08-23 08:34:27 +02:00
// Set up "Allow Editing"
2021-09-27 19:11:15 +02:00
$ ( 'body' ) . on ( 'input' , autofocus ) ;
$ ( '#allowediting' ) . prop ( 'checked' , allowedit ) . prop ( 'disabled' , false ) . change ( ) . off ( 'change' ) . on ( 'change' , function ( ) {
2021-08-23 08:34:27 +02:00
if ( allowtoggle ) {
2021-09-28 06:48:37 +02:00
allowedit = gamestarted && $ ( this ) . prop ( 'checked' ) ;
2021-09-27 22:04:42 +02:00
game _text . attr ( 'contenteditable' , allowedit ) ;
2021-08-23 08:34:27 +02:00
}
} ) ;
2021-10-01 01:00:15 +02:00
// A simple feature detection test to determine whether the user interface
// is using WebKit (Safari browser's rendering engine) because WebKit
// requires special treatment to work correctly with the KoboldAI editor
2021-10-01 04:58:54 +02:00
( function ( ) {
var active _element = document . activeElement ;
var c = document . createElement ( "chunk" ) ;
var t = document . createTextNode ( "KoboldAI" ) ;
c . appendChild ( t ) ;
game _text [ 0 ] . appendChild ( c ) ;
var r = rangy . createRange ( ) ;
r . setStart ( t , 6 ) ;
r . collapse ( true ) ;
var s = rangy . getSelection ( ) ;
s . removeAllRanges ( ) ;
s . addRange ( r ) ;
game _text . blur ( ) ;
game _text . focus ( ) ;
using _webkit _patch = rangy . getSelection ( ) . focusOffset !== 6 ;
c . removeChild ( t ) ;
game _text [ 0 ] . removeChild ( c ) ;
document . activeElement . blur ( ) ;
active _element . focus ( ) ;
} ) ( ) ;
2021-05-03 00:48:47 +02:00
} else if ( msg . cmd == "updatescreen" ) {
2021-09-01 20:01:04 +02:00
var _gamestarted = gamestarted ;
2021-08-19 13:18:01 +02:00
gamestarted = msg . gamestarted ;
if ( _gamestarted != gamestarted ) {
action _mode = 0 ;
changemode ( ) ;
}
2021-09-27 19:11:15 +02:00
unbindGametext ( ) ;
2021-09-27 23:55:54 +02:00
allowedit = gamestarted && $ ( "#allowediting" ) . prop ( 'checked' ) ;
game _text . attr ( 'contenteditable' , allowedit ) ;
2021-09-27 19:11:15 +02:00
modified _chunks = new Set ( ) ;
empty _chunks = new Set ( ) ;
2021-05-03 00:48:47 +02:00
game _text . html ( msg . data ) ;
2021-10-13 06:42:03 +02:00
if ( game _text [ 0 ] . lastChild !== null && game _text [ 0 ] . lastChild . tagName === "CHUNK" ) {
game _text [ 0 ] . lastChild . appendChild ( document . createElement ( "br" ) ) ;
}
2021-09-27 19:11:15 +02:00
bindGametext ( ) ;
2021-09-28 04:21:14 +02:00
if ( gamestarted ) {
2021-10-13 06:42:03 +02:00
saved _prompt = formatChunkInnerText ( $ ( "#n0" ) [ 0 ] ) ;
2021-09-28 04:21:14 +02:00
}
2021-05-04 15:56:48 +02:00
// Scroll to bottom of text
2021-08-23 08:34:27 +02:00
if ( newly _loaded ) {
2021-08-26 21:15:42 +02:00
scrollToBottom ( ) ;
2021-08-23 08:34:27 +02:00
}
newly _loaded = false ;
2021-08-24 17:24:29 +02:00
hideMessage ( ) ;
2021-08-24 01:19:36 +02:00
} else if ( msg . cmd == "scrolldown" ) {
2021-08-26 21:15:42 +02:00
scrollToBottom ( ) ;
2021-06-15 06:59:08 +02:00
} else if ( msg . cmd == "updatechunk" ) {
2021-08-26 01:22:35 +02:00
hideMessage ( ) ;
2021-10-13 06:42:03 +02:00
var index = msg . data . index ;
var html = msg . data . html ;
var existingChunk = game _text . children ( '#n' + index ) ;
var newChunk = $ ( html ) ;
2021-09-27 19:11:15 +02:00
unbindGametext ( ) ;
2021-06-15 06:59:08 +02:00
if ( existingChunk . length > 0 ) {
// Update existing chunk
2021-10-13 06:42:03 +02:00
if ( existingChunk [ 0 ] . nextSibling === null || existingChunk [ 0 ] . nextSibling . nodeType !== 1 || existingChunk [ 0 ] . nextSibling . tagName !== "CHUNK" ) {
newChunk [ 0 ] . appendChild ( document . createElement ( "br" ) ) ;
}
2021-06-15 06:59:08 +02:00
existingChunk . before ( newChunk ) ;
existingChunk . remove ( ) ;
2021-09-27 19:11:15 +02:00
} else if ( ! empty _chunks . has ( index . toString ( ) ) ) {
2021-06-15 06:59:08 +02:00
// Append at the end
2021-10-13 06:42:03 +02:00
unbindGametext ( ) ;
var lc = game _text [ 0 ] . lastChild ;
if ( lc . tagName === "CHUNK" && lc . lastChild !== null && lc . lastChild . tagName === "BR" ) {
lc . removeChild ( lc . lastChild ) ;
}
newChunk [ 0 ] . appendChild ( document . createElement ( "br" ) ) ;
2021-06-15 06:59:08 +02:00
game _text . append ( newChunk ) ;
2021-10-13 06:42:03 +02:00
bindGametext ( ) ;
2021-06-15 06:59:08 +02:00
}
2021-09-27 19:11:15 +02:00
bindGametext ( ) ;
2021-08-25 01:02:52 +02:00
hide ( [ $ ( '#curtain' ) ] ) ;
2021-06-15 06:59:08 +02:00
} else if ( msg . cmd == "removechunk" ) {
2021-08-26 01:22:35 +02:00
hideMessage ( ) ;
2021-10-13 06:42:03 +02:00
var index = msg . data ;
var element = game _text . children ( '#n' + index ) ;
if ( element . length ) {
unbindGametext ( ) ;
if ( ( element [ 0 ] . nextSibling === null || element [ 0 ] . nextSibling . nodeType !== 1 || element [ 0 ] . nextSibling . tagName !== "CHUNK" ) && element [ 0 ] . previousSibling !== null && element [ 0 ] . previousSibling . tagName === "CHUNK" ) {
element [ 0 ] . previousSibling . appendChild ( document . createElement ( "br" ) ) ;
}
element . remove ( ) ; // Remove the chunk
bindGametext ( ) ;
}
2021-08-25 01:02:52 +02:00
hide ( [ $ ( '#curtain' ) ] ) ;
2021-05-03 00:48:47 +02:00
} else if ( msg . cmd == "setgamestate" ) {
// Enable or Disable buttons
if ( msg . data == "ready" ) {
enableSendBtn ( ) ;
2021-08-23 08:34:27 +02:00
enableButtons ( [ button _actmem , button _actwi , button _actback , button _actretry ] ) ;
2021-05-03 00:48:47 +02:00
hideWaitAnimation ( ) ;
} else if ( msg . data == "wait" ) {
disableSendBtn ( ) ;
2021-08-23 08:34:27 +02:00
disableButtons ( [ button _actmem , button _actwi , button _actback , button _actretry ] ) ;
2021-05-03 00:48:47 +02:00
showWaitAnimation ( ) ;
} else if ( msg . data == "start" ) {
2021-05-29 11:46:03 +02:00
setStartState ( ) ;
2021-05-03 00:48:47 +02:00
}
2021-10-22 20:18:10 +02:00
} else if ( msg . cmd == "allowsp" ) {
allowsp = ! ! msg . data ;
if ( allowsp ) {
button _softprompt . removeClass ( "hidden" ) ;
} else {
button _softprompt . addClass ( "hidden" ) ;
}
2021-09-19 17:41:37 +02:00
} else if ( msg . cmd == "setstoryname" ) {
storyname = msg . data ;
2021-05-03 00:48:47 +02:00
} else if ( msg . cmd == "editmode" ) {
// Enable or Disable edit mode
if ( msg . data == "true" ) {
enterEditMode ( ) ;
} else {
exitEditMode ( ) ;
}
} else if ( msg . cmd == "setinputtext" ) {
2021-08-23 08:34:27 +02:00
// Set input box text for memory mode
2021-09-19 17:41:37 +02:00
if ( memorymode ) {
memorytext = msg . data ;
input _text . val ( msg . data ) ;
}
} else if ( msg . cmd == "setmemory" ) {
memorytext = msg . data ;
2021-08-23 08:34:27 +02:00
if ( memorymode ) {
input _text . val ( msg . data ) ;
}
2021-05-03 00:48:47 +02:00
} 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 ) )
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "updatetemp" ) {
// Send current temp value to input
2021-05-07 20:32:10 +02:00
$ ( "#settemp" ) . val ( parseFloat ( msg . data ) ) ;
$ ( "#settempcur" ) . html ( msg . data ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "updatetopp" ) {
2021-05-07 20:32:10 +02:00
// Send current top p value to input
$ ( "#settopp" ) . val ( parseFloat ( msg . data ) ) ;
$ ( "#settoppcur" ) . html ( msg . data ) ;
2021-08-19 14:47:57 +02:00
} else if ( msg . cmd == "updatetopk" ) {
// Send current top k value to input
$ ( "#settopk" ) . val ( parseFloat ( msg . data ) ) ;
$ ( "#settopkcur" ) . html ( msg . data ) ;
} else if ( msg . cmd == "updatetfs" ) {
// Send current tfs value to input
$ ( "#settfs" ) . val ( parseFloat ( msg . data ) ) ;
$ ( "#settfscur" ) . html ( msg . data ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "updatereppen" ) {
2021-05-07 20:32:10 +02:00
// Send current rep pen value to input
$ ( "#setreppen" ) . val ( parseFloat ( msg . data ) ) ;
$ ( "#setreppencur" ) . html ( msg . data ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "updateoutlen" ) {
2021-05-07 20:32:10 +02:00
// 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 ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "setlabeltemp" ) {
// Update setting label with value from server
2021-05-07 20:32:10 +02:00
$ ( "#settempcur" ) . html ( msg . data ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "setlabeltopp" ) {
// Update setting label with value from server
2021-05-07 20:32:10 +02:00
$ ( "#settoppcur" ) . html ( msg . data ) ;
2021-08-19 14:47:57 +02:00
} else if ( msg . cmd == "setlabeltopk" ) {
// Update setting label with value from server
$ ( "#settopkcur" ) . html ( msg . data ) ;
} else if ( msg . cmd == "setlabeltfs" ) {
// Update setting label with value from server
$ ( "#settfscur" ) . html ( msg . data ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "setlabelreppen" ) {
// Update setting label with value from server
2021-05-07 20:32:10 +02:00
$ ( "#setreppencur" ) . html ( msg . data ) ;
2021-05-04 15:56:48 +02:00
} else if ( msg . cmd == "setlabeloutput" ) {
// Update setting label with value from server
2021-05-07 20:32:10 +02:00
$ ( "#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" ) {
2021-05-05 09:04:06 +02:00
// 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 ) ;
2021-05-07 20:32:10 +02:00
} else if ( msg . cmd == "addsetting" ) {
// Add setting controls
addSetting ( msg . data ) ;
2021-05-11 01:17:10 +02:00
} else if ( msg . cmd == "addformat" ) {
// Add setting controls
addFormat ( msg . data ) ;
} else if ( msg . cmd == "updatefrmttriminc" ) {
// Update toggle state
2021-05-29 11:46:03 +02:00
$ ( "#frmttriminc" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-05-11 01:17:10 +02:00
} else if ( msg . cmd == "updatefrmtrmblln" ) {
// Update toggle state
2021-05-29 11:46:03 +02:00
$ ( "#frmtrmblln" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-05-11 01:17:10 +02:00
} else if ( msg . cmd == "updatefrmtrmspch" ) {
// Update toggle state
2021-05-29 11:46:03 +02:00
$ ( "#frmtrmspch" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-05-11 01:17:10 +02:00
} else if ( msg . cmd == "updatefrmtadsnsp" ) {
// Update toggle state
2021-05-29 11:46:03 +02:00
$ ( "#frmtadsnsp" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-10-23 17:30:48 +02:00
} else if ( msg . cmd == "updatesingleline" ) {
// Update toggle state
$ ( "#singleline" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-05-11 01:17:10 +02:00
} else if ( msg . cmd == "allowtoggle" ) {
// Allow toggle change states to propagate
allowtoggle = msg . data ;
2021-05-11 06:27:34 +02:00
} else if ( msg . cmd == "popupshow" ) {
// Show/Hide Popup
popupShow ( msg . data ) ;
2021-09-01 00:22:30 +02:00
} else if ( msg . cmd == "hidepopupdelete" ) {
// Hide the dialog box that asks you to confirm deletion of a story
$ ( "#loadcontainerdelete" ) . removeClass ( "flex" ) . addClass ( "hidden" ) ;
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
} else if ( msg . cmd == "hidepopuprename" ) {
// Hide the story renaming dialog box
$ ( "#loadcontainerrename" ) . removeClass ( "flex" ) . addClass ( "hidden" ) ;
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
2021-05-11 06:27:34 +02:00
} 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 ( "" ) ;
2021-05-13 07:26:42 +02:00
} 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 ) ;
2021-05-22 11:28:40 +02:00
} 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 ) ;
2021-10-22 20:18:10 +02:00
} else if ( msg . cmd == "buildsp" ) {
buildSPList ( msg . data ) ;
2021-05-22 11:28:40 +02:00
} else if ( msg . cmd == "askforoverwrite" ) {
// Show overwrite warning
2021-09-01 00:22:30 +02:00
show ( [ $ ( ".saveasoverwrite" ) ] ) ;
} else if ( msg . cmd == "popuperror" ) {
// Show error in the current dialog box
$ ( ".popuperror" ) . text ( msg . data ) ;
show ( [ $ ( ".popuperror" ) ] ) ;
2021-05-29 11:46:03 +02:00
} 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 ( ) ;
2021-08-19 13:18:01 +02:00
} else if ( msg . cmd == "updateadventure" ) {
// Update toggle state
$ ( "#setadventure" ) . prop ( 'checked' , msg . data ) . change ( ) ;
// Update adventure state
setadventure ( msg . data ) ;
2021-11-03 17:18:48 +01:00
} else if ( msg . cmd == "updatedynamicscan" ) {
// Update toggle state
$ ( "#setdynamicscan" ) . prop ( 'checked' , msg . data ) . change ( ) ;
2021-08-20 00:37:59 +02:00
} else if ( msg . cmd == "runs_remotely" ) {
2021-11-05 00:33:17 +01:00
remote = true ;
hide ( [ button _savetofile , button _import , button _importwi ] ) ;
2021-05-03 00:48:47 +02:00
}
2021-08-25 00:32:48 +02:00
} ) ;
2021-05-03 00:48:47 +02:00
socket . on ( 'disconnect' , function ( ) {
2021-08-23 08:34:27 +02:00
connected = false ;
2021-05-07 20:32:10 +02:00
connect _status . html ( "<b>Lost connection...</b>" ) ;
connect _status . removeClass ( "color_green" ) ;
connect _status . addClass ( "color_orange" ) ;
2021-05-03 00:48:47 +02:00
} ) ;
2021-09-27 19:11:15 +02:00
2021-09-27 21:57:07 +02:00
// Register editing events
2021-10-12 06:09:02 +02:00
game _text . on ( 'textInput' ,
chunkOnTextInput
2021-11-18 19:18:18 +01:00
) . on ( 'beforeinput' ,
chunkOnBeforeInput
2021-10-12 06:09:02 +02:00
) . on ( 'keydown' ,
2021-09-27 19:11:15 +02:00
chunkOnKeyDown
) . on ( 'paste' ,
chunkOnPaste
2021-09-27 22:33:24 +02:00
) . on ( 'click' ,
2021-09-27 19:11:15 +02:00
chunkOnSelectionChange
) . on ( 'keydown' ,
2021-09-30 23:52:35 +02:00
chunkOnKeyDownSelectionChange
2021-09-27 19:11:15 +02:00
) . on ( 'focusout' ,
chunkOnFocusOut
) ;
// This is required for the editor to work correctly in Firefox on desktop
// because the gods of HTML and JavaScript say so
$ ( document . body ) . on ( 'focusin' , function ( event ) {
setTimeout ( function ( ) {
2021-09-27 22:04:42 +02:00
if ( document . activeElement !== game _text [ 0 ] && game _text [ 0 ] . contains ( document . activeElement ) ) {
game _text [ 0 ] . focus ( ) ;
2021-09-27 19:11:15 +02:00
}
} , 2 ) ;
} ) ;
2021-05-03 00:48:47 +02:00
// Bind actions to UI buttons
button _send . on ( "click" , function ( ev ) {
dosubmit ( ) ;
} ) ;
2021-08-19 13:18:01 +02:00
button _mode . on ( "click" , function ( ev ) {
changemode ( ) ;
} ) ;
2021-05-03 00:48:47 +02:00
button _actretry . on ( "click" , function ( ev ) {
2021-08-25 20:42:37 +02:00
hideMessage ( ) ;
2021-05-03 00:48:47 +02:00
socket . send ( { 'cmd' : 'retry' , 'data' : '' } ) ;
2021-05-29 11:46:03 +02:00
hidegenseqs ( ) ;
2021-05-03 00:48:47 +02:00
} ) ;
button _actback . on ( "click" , function ( ev ) {
2021-08-25 20:42:37 +02:00
hideMessage ( ) ;
2021-05-03 00:48:47 +02:00
socket . send ( { 'cmd' : 'back' , 'data' : '' } ) ;
2021-05-29 11:46:03 +02:00
hidegenseqs ( ) ;
2021-05-03 00:48:47 +02:00
} ) ;
button _actmem . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'memory' , 'data' : '' } ) ;
} ) ;
2021-05-22 11:28:40 +02:00
button _savetofile . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'savetofile' , 'data' : '' } ) ;
2021-05-03 00:48:47 +02:00
} ) ;
2021-05-22 11:28:40 +02:00
button _loadfrfile . on ( "click" , function ( ev ) {
2021-11-05 00:33:17 +01:00
if ( remote ) {
$ ( "#remote-save-select" ) . click ( ) ;
} else {
socket . send ( { 'cmd' : 'loadfromfile' , 'data' : '' } ) ;
}
} ) ;
$ ( "#remote-save-select" ) . on ( "change" , function ( ) {
var reader = new FileReader ( ) ;
var file = $ ( "#remote-save-select" ) [ 0 ] . files [ 0 ] ;
reader . addEventListener ( "load" , function ( response ) {
socket . send ( { 'cmd' : 'loadfromstring' , 'filename' : file . name , 'data' : response . target . result } ) ;
} , false ) ;
reader . readAsText ( file ) ;
2021-05-03 00:48:47 +02:00
} ) ;
2021-05-11 06:27:34 +02:00
button _import . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'import' , 'data' : '' } ) ;
} ) ;
2021-05-29 11:46:03 +02:00
button _importwi . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'importwi' , 'data' : '' } ) ;
} ) ;
2021-05-04 15:56:48 +02:00
button _settings . on ( "click" , function ( ev ) {
$ ( '#settingsmenu' ) . slideToggle ( "slow" ) ;
} ) ;
2021-05-11 01:17:10 +02:00
button _format . on ( "click" , function ( ev ) {
$ ( '#formatmenu' ) . slideToggle ( "slow" ) ;
} ) ;
2021-05-11 06:27:34 +02:00
popup _close . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'importcancel' , 'data' : '' } ) ;
2021-05-04 15:56:48 +02:00
} ) ;
2021-05-11 06:27:34 +02:00
popup _accept . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'importaccept' , 'data' : '' } ) ;
} ) ;
2021-05-13 07:26:42 +02:00
button _actwi . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'wi' , 'data' : '' } ) ;
} ) ;
2021-05-16 11:29:39 +02:00
button _impaidg . on ( "click" , function ( ev ) {
showAidgPopup ( ) ;
} ) ;
aidg _close . on ( "click" , function ( ev ) {
hideAidgPopup ( ) ;
} ) ;
aidg _accept . on ( "click" , function ( ev ) {
sendAidgImportRequest ( ) ;
} ) ;
2021-05-11 06:27:34 +02:00
2021-05-22 11:28:40 +02:00
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 ( ) ;
} ) ;
2021-09-01 19:32:11 +02:00
button _download . on ( "click" , function ( ev ) {
2021-09-19 23:16:01 +02:00
downloadStory ( 'json' ) ;
2021-09-01 19:32:11 +02:00
} ) ;
2021-09-01 19:46:37 +02:00
button _downloadtxt . on ( "click" , function ( ev ) {
2021-09-19 23:16:01 +02:00
downloadStory ( 'plaintext' ) ;
2021-09-01 19:46:37 +02:00
} ) ;
2021-05-22 11:28:40 +02:00
button _load . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'loadlistrequest' , 'data' : '' } ) ;
} ) ;
2021-10-22 20:18:10 +02:00
button _softprompt . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'splistrequest' , 'data' : '' } ) ;
} ) ;
2021-05-22 11:28:40 +02:00
load _close . on ( "click" , function ( ev ) {
hideLoadPopup ( ) ;
} ) ;
load _accept . on ( "click" , function ( ev ) {
2021-08-23 08:34:27 +02:00
newly _loaded = true ;
2021-05-22 11:28:40 +02:00
socket . send ( { 'cmd' : 'loadrequest' , 'data' : '' } ) ;
hideLoadPopup ( ) ;
} ) ;
2021-10-22 20:18:10 +02:00
sp _close . on ( "click" , function ( ev ) {
hideSPPopup ( ) ;
} ) ;
sp _accept . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'sprequest' , 'data' : '' } ) ;
hideSPPopup ( ) ;
} ) ;
2021-05-22 11:28:40 +02:00
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 ( ) ;
2021-08-19 12:54:44 +02:00
} ) ;
2021-09-01 19:05:24 +02:00
$ ( "#btn_dsclose" ) . on ( "click" , function ( ) {
$ ( "#loadcontainerdelete" ) . removeClass ( "flex" ) . addClass ( "hidden" ) ;
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
} ) ;
2021-09-01 19:10:21 +02:00
$ ( "#newsavename" ) . on ( "input" , function ( ev ) {
if ( $ ( this ) . val ( ) == "" ) {
disableButtons ( [ $ ( "#btn_rensaccept" ) ] ) ;
} else {
enableButtons ( [ $ ( "#btn_rensaccept" ) ] ) ;
}
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
2021-09-01 19:05:24 +02:00
} ) ;
$ ( "#btn_rensclose" ) . on ( "click" , function ( ) {
$ ( "#loadcontainerrename" ) . removeClass ( "flex" ) . addClass ( "hidden" ) ;
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
} ) ;
2021-08-19 12:54:44 +02:00
button _rndgame . on ( "click" , function ( ev ) {
showRandomStoryPopup ( ) ;
} ) ;
rs _accept . on ( "click" , function ( ev ) {
socket . send ( { 'cmd' : 'rndgame' , 'data' : topic . val ( ) } ) ;
hideRandomStoryPopup ( ) ;
} ) ;
rs _close . on ( "click" , function ( ev ) {
hideRandomStoryPopup ( ) ;
2021-05-22 11:28:40 +02:00
} ) ;
2021-05-23 04:06:10 +02:00
anote _slider . on ( "input" , function ( ) {
socket . send ( { 'cmd' : 'anotedepth' , 'data' : $ ( this ) . val ( ) } ) ;
} ) ;
2021-05-22 11:28:40 +02:00
saveasinput . on ( "input" , function ( ) {
if ( saveasinput . val ( ) == "" ) {
disableButtons ( [ saveas _accept ] ) ;
} else {
enableButtons ( [ saveas _accept ] ) ;
}
2021-09-01 00:22:30 +02:00
hide ( [ $ ( ".saveasoverwrite" ) , $ ( ".popuperror" ) ] ) ;
2021-05-22 11:28:40 +02:00
} ) ;
2021-05-03 00:48:47 +02:00
// 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 ;
}
} ) ;
2021-05-05 09:04:06 +02:00
// Enter to submit, but not if holding shift
2021-05-03 00:48:47 +02:00
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 ;
}
} ) ;
2021-05-16 11:29:39 +02:00
aidgpromptnum . keydown ( function ( ev ) {
if ( ev . which == 13 ) {
sendAidgImportRequest ( ) ;
}
} ) ;
2021-05-22 11:28:40 +02:00
saveasinput . keydown ( function ( ev ) {
if ( ev . which == 13 && saveasinput . val ( ) != "" ) {
sendSaveAsRequest ( ) ;
}
} ) ;
2021-05-03 00:48:47 +02:00
} ) ;