forked from Nanofus/novel.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnovel.min.js
1 lines (1 loc) · 51.4 KB
/
novel.min.js
1
function __range__(left,right,inclusive){let range=[],ascending=left<right,end=inclusive?ascending?right+1:right-1:right;for(let i=left;ascending?i<end:i>end;ascending?i++:i--)range.push(i);return range}function __range__(left,right,inclusive){let range=[],ascending=left<right,end=inclusive?ascending?right+1:right-1:right;for(let i=left;ascending?i<end:i>end;ascending?i++:i--)range.push(i);return range}function __range__(left,right,inclusive){let range=[],ascending=left<right,end=inclusive?ascending?right+1:right-1:right;for(let i=left;ascending?i<end:i>end;ascending?i++:i--)range.push(i);return range}function __in__(needle,haystack){return haystack.indexOf(needle)>=0}function __range__(left,right,inclusive){let range=[],ascending=left<right,end=inclusive?ascending?right+1:right-1:right;for(let i=left;ascending?i<end:i>end;ascending?i++:i--)range.push(i);return range}let novelData={novel:null,choices:null,debugMode:!1,status:"Loading",inventoryHidden:!1,choicesHidden:!1,printedText:"",parsedJavascriptCommands:[],parsedScrollsounds:[],music:[],csvEnabled:!1,input:{presses:0},printer:{fullText:"",currentText:"",currentOffset:0,defaultInterval:0,soundBuffer:[],musicBuffer:[],stopMusicBuffer:[],executeBuffer:[],buffersExecuted:!1,scrollSound:null,tickSoundFrequency:1,tickCounter:0,speedMod:!1,tickSpeedMultiplier:1,pause:0,interval:0,printCompleted:!1}},novelPath;"undefined"!=typeof Papa&&(novelData.csvEnabled=!0);class InputManager{static keyDown(charCode){if(!this.formsSelected())return 13===charCode||32===charCode?(novelData.novel.settings.scrollSettings.continueWithKeyboard&&SceneManager.tryContinue(),novelData.novel.settings.scrollSettings.skipWithKeyboard&&TextPrinter.trySkip(),TextPrinter.unpause()):void 0}static keyPressed(charCode){if(!this.formsSelected())return novelData.input.presses++,(13===charCode||32===charCode)&&novelData.input.presses>2&&novelData.novel.settings.scrollSettings.fastScrollWithKeyboard?TextPrinter.fastScroll():void 0}static keyUp(charCode){if(!this.formsSelected())return this.presses=0,13===charCode||32===charCode?TextPrinter.stopFastScroll():void 0}static formsSelected(){let novelArea=document.getElementById("novel-area");if(novelArea){let inputs=novelArea.querySelectorAll("input");for(let j=0;j<inputs.length;j++){let i=inputs[j];if(i===document.activeElement)return!0}}return!1}}document.onkeydown=function(evt){let charCode=(evt=evt||window.event).keyCode||evt.which;return InputManager.keyDown(charCode)},document.onkeypress=function(evt){let charCode=(evt=evt||window.event).keyCode||evt.which;return InputManager.keyPressed(charCode)},document.onkeyup=function(evt){let charCode=(evt=evt||window.event).keyCode||evt.which;return InputManager.keyUp(charCode)};class InventoryManager{static checkRequirements(requirements){Util.checkFormat(requirements,"array");let reqsFilled=0;for(let k=0;k<novelData.novel.inventories[novelData.novel.currentInventory].length;k++){let i=novelData.novel.inventories[novelData.novel.currentInventory][k];for(let i1=0;i1<requirements.length;i1++){let j=requirements[i1];j[0]===i.name&&j[1]<=i.value&&(reqsFilled+=1)}}return reqsFilled===requirements.length}static setValue(parsed,newValue){Util.checkFormat(parsed,"string");let getValueArrayLast=this.getValueArrayLast(parsed);return Parser.findValue(parsed,!1)[getValueArrayLast]=newValue}static increaseValue(parsed,change){Util.checkFormat(parsed,"string");let getValueArrayLast=this.getValueArrayLast(parsed),value=Parser.findValue(parsed,!1);if(value[getValueArrayLast]=value[getValueArrayLast]+change,!isNaN(parseFloat(value[getValueArrayLast])))return value[getValueArrayLast]=parseFloat(value[getValueArrayLast].toFixed(novelData.novel.settings.floatPrecision))}static decreaseValue(parsed,change){Util.checkFormat(parsed,"string");let getValueArrayLast=this.getValueArrayLast(parsed),value=Parser.findValue(parsed,!1);if(value[getValueArrayLast]=value[getValueArrayLast]-change,!isNaN(parseFloat(value[getValueArrayLast])))return value[getValueArrayLast]=parseFloat(value[getValueArrayLast].toFixed(novelData.novel.settings.floatPrecision))}static getValueArrayLast(parsed){let getValueArrayLast=parsed.split(",");return getValueArrayLast=getValueArrayLast[getValueArrayLast.length-1].split("."),getValueArrayLast=getValueArrayLast[getValueArrayLast.length-1]}static addItems(items){return this.editItems(items,"add")}static setItems(items){return this.editItems(items,"set")}static removeItems(items){return this.editItems(items,"remove")}static editItems(items,mode){Util.checkFormat(items,"array");for(let i=0;i<items.length;i++){let j=items[i],hidden=!1;"!"===j[0].substring(0,1)&&(hidden=!0,j[0]=j[0].substring(1,j[0].length));let itemAdded=this.tryEditInInventory(mode,j,hidden);itemAdded||this.tryEditNotInInventory(mode,j,hidden)}}static tryEditInInventory(mode,j,hidden){for(let k=0;k<novelData.novel.inventories[novelData.novel.currentInventory].length;k++){let i=novelData.novel.inventories[novelData.novel.currentInventory][k];if(i.name===j[0]){let probability=1;if(j.length>2){var displayName=j[2],value=parseInt(Parser.parseStatement(j[1]));isNaN(displayName)||(probability=j[2],displayName=j.name),j.length>3&&(probability=parseFloat(j[2]),displayName=j[3])}else var displayName=j[0],value=parseInt(Parser.parseStatement(j[1]));let random=Math.random();return random<probability&&("set"===mode?isNaN(parseInt(j[1]))?i.value=j[1]:i.value=parseInt(j[1]):"add"===mode?(isNaN(parseInt(i.value))&&(i.value=0),i.value=parseInt(i.value)+value):"remove"===mode&&(isNaN(parseInt(i.value))?i.value=0:(i.value=parseInt(i.value)-value,i.value<0&&(i.value=0))),i.hidden=hidden),!0}}return!1}static tryEditNotInInventory(mode,j,hidden){if("remove"!==mode){let probability=1,value=parseInt(Parser.parseStatement(j[1]));if(isNaN(value)&&(value=Parser.parseStatement(j[1])),j.length>2){displayName=j[2];isNaN(displayName)||(probability=j[2],displayName=j.name),j.length>3&&(probability=parseFloat(j[2]),displayName=j[3])}else displayName=j[0];let random=Math.random();if(void 0===displayName)var displayName=j[0];if(random<probability)return novelData.novel.inventories[novelData.novel.currentInventory].push({name:j[0],value:value,displayName:displayName,hidden:hidden})}}}class LanguageManager{static setLanguage(name){return novelData.novel.settings.language=name,UI.updateUILanguage()}static getUIString(name){Util.checkFormat(name,"string");for(let j=0;j<novelData.novel.uiText.length;j++){let i=novelData.novel.uiText[j];if(i.name===name&&i.language===novelData.novel.settings.language)return Parser.parseText(i.content)}return console.error(`Error! UI string ${name} not found!`),"[NOT FOUND]"}static getCorrectLanguageCsvString(name){if(Util.checkFormat(name,"string"),void 0===novelData.csvData||!1===novelData.csvEnabled)return console.error("Error! CSV data cannot be parsed, because Papa Parse can't be detected."),"[NOT FOUND]";for(let j=0;j<novelData.csvData.length;j++){let i=novelData.csvData[j];if(i.name===name)return void 0===i[novelData.novel.settings.language]?void 0===i.english?(console.error(`Error! No CSV value by name ${name} could be found.`),"[NOT FOUND]"):Parser.parseText(i.english):Parser.parseText(i[novelData.novel.settings.language])}}static getItemAttribute(item,type){switch(type){case"displayName":return"[csv]"===item.displayName?this.getCorrectLanguageCsvString(item.name+"|displayName"):this.getCorrectLanguageString(item.displayName);case"description":return"[csv]"===item.description?this.getCorrectLanguageCsvString(item.name+"|description"):this.getCorrectLanguageString(item.description);default:return console.error("Error! Trying to get an invalid item attribute in LanguageManager."),"[NOT FOUND]"}}static getCorrectLanguageString(obj,type){if(Util.checkFormat(obj,"arrayOrString"),"string"==typeof obj)return obj;if("[object Array]"===Object.prototype.toString.call(obj))for(let j=0;j<obj.length;j++){let i=obj[j];if(i.language===novelData.novel.settings.language)return i.content}}}class NovelManager{static loadCookie(cname){let name=cname+"=",ca=document.cookie.split(";"),i=0;for(;i<ca.length;){let c=ca[i];for(;" "===c.charAt(0);)c=c.substring(1);if(0===c.indexOf(name))return c.substring(name.length,c.length);i++}}static saveCookie(cname,cvalue,exdays){let d=new Date;d.setTime(d.getTime()+24*exdays*60*60*1e3);let expires=`expires=${d.toUTCString()}`;return document.cookie=cname+"="+cvalue+"; "+expires+"; path=/"}static loadData(novel,changeScene){if(void 0===changeScene&&(changeScene=!0),void 0===novel){if(""!==this.loadCookie("gameData")){console.log("Cookie found!");let cookie=this.loadCookie("gameData");console.log("Cookie loaded"),console.log(cookie);loadedData=JSON.parse(atob(this.loadCookie("gameData")));return this.prepareLoadedData(loadedData,changeScene)}}else if(void 0!==novel&&""!==novel){var loadedData=JSON.parse(atob(novel));return this.prepareLoadedData(loadedData,changeScene)}}static prepareLoadedData(loadedData,changeScene){if(novelData.novel.name===loadedData.name)return novelData.novel.version!==loadedData.version&&console.warn("WARNING! novel version mismatch"),novelData.novel.inventories=loadedData.inventories,novelData.debugMode=novelData.novel.debugMode,SoundManager.init(),changeScene?SceneManager.updateScene(loadedData.currentScene,!0):void 0;console.error("ERROR! novel name mismatch")}static saveDataAsJson(){let saveData=JSON.parse(JSON.stringify(novelData.novel));return delete saveData.scenes,delete saveData.tagPresets,delete saveData.sounds,delete saveData.externalText,delete saveData.externalJson,btoa(JSON.stringify(saveData))}static saveData(){let save=this.saveDataAsJson();return"cookie"===novelData.novel.settings.saveMode?this.saveCookie("novelData",save,365):"text"===novelData.novel.settings.saveMode?UI.showSaveNotification(save):void 0}static prepareData(json){json.currentScene="",json.parsedChoices="",void 0===json.currentInventory&&(json.currentInventory=0),void 0===json.inventories&&(json.inventories=[[]]),0===json.inventories.length&&(json.inventories[0]=[]),void 0===json.scenes&&(json.scenes=[{}]),void 0===json.tagPresets&&(json.tagPresets=[]),void 0===json.sounds&&(json.sounds=[]);for(let k=0;k<json.inventories.length;k++){let i=json.inventories[k];for(let i1=0;i1<i.length;i1++){let j=i[i1];void 0===j.displayName&&(j.displayName=j.name)}}for(let j1=0;j1<json.scenes.length;j1++){let s=json.scenes[j1];s.combinedText="",s.parsedText="",s.visited=!1,void 0===s.text&&(console.warn(`WARNING! scene ${s.name} has no text`),s.text=""),void 0===s.choices&&(console.warn(`WARNING! scene ${s.name} has no choices`),s.choices=[]);for(let k1=0;k1<s.choices.length;k1++){let c=s.choices[k1];c.parsedText="",void 0===c.alwaysShow&&(c.alwaysShow=!1)}}return void 0===json.settings&&(json.settings={}),void 0===json.settings.debugMode&&(json.settings.debugMode=!1),void 0===json.settings.saveMode&&(json.settings.saveMode="text"),void 0===json.settings.language&&(json.settings.language="english"),void 0===json.settings.showSaveButtons&&(json.settings.showSaveButtons=!0),void 0===json.settings.showSkipButton&&(json.settings.showSkipButton=!1),void 0===json.settings.inventoryHidden&&(json.settings.inventoryHidden=!1),void 0===json.settings.choicesHidden&&(json.settings.choicesHidden=!1),void 0===json.settings.alwaysShowDisabledChoices&&(json.settings.alwaysShowDisabledChoices=!1),void 0===json.settings.floatPrecision&&(json.settings.floatPrecision=5),void 0===json.settings.scrollSettings&&(json.settings.scrollSettings={}),void 0===json.settings.scrollSettings.defaultScrollSpeed&&(json.settings.scrollSettings.defaultScrollSpeed=60),void 0===json.settings.scrollSettings.revisitSkipEnabled&&(json.settings.scrollSettings.revisitSkipEnabled=!0),void 0===json.settings.scrollSettings.textSkipEnabled&&(json.settings.scrollSettings.textSkipEnabled=!0),void 0===json.settings.scrollSettings.skipWithKeyboard&&(json.settings.scrollSettings.skipWithKeyboard=!1),void 0===json.settings.scrollSettings.continueWithKeyboard&&(json.settings.scrollSettings.continueWithKeyboard=!0),void 0===json.settings.scrollSettings.fastScrollWithKeyboard&&(json.settings.scrollSettings.fastScrollWithKeyboard=!0),void 0===json.settings.scrollSettings.fastScrollSpeedMultiplier&&(json.settings.scrollSettings.fastScrollSpeedMultiplier=20),void 0===json.settings.scrollSettings.tickFreqThreshold&&(json.settings.scrollSettings.tickFreqThreshold=100),void 0===json.settings.soundSettings&&(json.settings.soundSettings={}),void 0===json.settings.soundSettings.soundVolume&&(json.settings.soundSettings.soundVolume=.5),void 0===json.settings.soundSettings.musicVolume&&(json.settings.soundSettings.musicVolume=.4),void 0===json.uiText?json.uiText=JSON.parse([{name:"saveText",language:"english",content:"Copy and save your save data:"},{name:"loadText",language:"english",content:"Paste your save data here:"},{name:"closeButton",language:"english",content:"Close"},{name:"copyButton",language:"english",content:"Copy"},{name:"saveButton",language:"english",content:"Save"},{name:"loadButton",language:"english",content:"Load"},{name:"loadDataButton",language:"english",content:"Load"},{name:"skipButton",language:"english",content:"Skip"},{name:"continueButton",language:"english",content:"Continue"},{name:"inventoryTitle",language:"english",content:"Inventory:"},{name:"hiddenInventoryTitle",language:"english",content:"Stats:"}]):json}static start(){console.log("-- Starting Novel.js... --"),this.getNovelName(),this.loadMainJson()}static getNovelName(){let n=document.getElementsByTagName("novel")[0];n||(n=document.getElementById("novel-area")),(novelPath=n.getAttribute("src"))||(novelPath="./novel")}static loadMainJson(){console.log("Loading main json...");let request=new XMLHttpRequest;return request.open("GET",novelPath+"/novel.json",!0),request.onload=function(){if(request.status>=200&&request.status<400){let json=JSON.parse(request.responseText);return NovelManager.loadExternalJson(json)}},request.onerror=function(){},request.send(),UI.showContinueButton(!1)}static loadExternalJson(json){if(console.log("Loading external json files..."),void 0===json.externalJson)return NovelManager.includeJsons(json,json),void NovelManager.loadExternalText(json);if(0===json.externalJson.length)return NovelManager.includeJsons(json,json),void NovelManager.loadExternalText(json);let ready=0;return json.externalJson.map(s=>(function(s){let request=new XMLHttpRequest;return request.open("GET",novelPath+"/json/"+s.file,!0),request.onload=function(){if(request.status>=200&&request.status<400&&(s.content=JSON.parse(request.responseText),++ready===json.externalJson.length))return NovelManager.includeJsons(json,json),NovelManager.loadExternalText(json)},request.onerror=function(){},request.send()})(s))}static includeJsons(root,object){if(void 0!==root.externalJson)for(let x in object)if("object"==typeof object[x]&&this.includeJsons(root,object[x]),void 0!==object[x].include)for(let j=0;j<root.externalJson.length;j++){let i=root.externalJson[j];if(i.name===object[x].include){object[x]=i.content,this.includeJsons(root,object[x]);break}}}static loadExternalText(json){if(console.log("Loading external text files..."),void 0===json.externalText)return void NovelManager.loadExternalCsv(json);if(0===json.externalText.length)return void NovelManager.loadExternalCsv(json);let ready=0;return json.externalText.map(s=>(function(s){let request=new XMLHttpRequest;return request.open("GET",novelPath+"/texts/"+s.file,!0),request.onload=function(){if(request.status>=200&&request.status<400&&(s.content=request.responseText,++ready===json.externalText.length))return NovelManager.loadExternalCsv(json)},request.onerror=function(){},request.send()})(s))}static loadExternalCsv(json){if(!novelData.csvEnabled)return NovelManager.prepareLoadedJson(json);{if(console.log("Loading external CSV files..."),void 0===json.externalText)return void NovelManager.prepareLoadedJson(json);if(0===json.externalText.length)return void NovelManager.prepareLoadedJson(json);let ready=0;for(let i=0;i<json.externalCsv.length;i++){let s=json.externalCsv[i];Papa.parse(novelPath+"/csv/"+s.file,{download:!0,header:!0,comments:"#",complete(results){if(void 0===novelData.csvData?novelData.csvData=results.data:novelData.csvData=Util.mergeObjArrays(novelData.csvData,results.data),++ready===json.externalCsv.length)return NovelManager.prepareLoadedJson(json)}})}}}static prepareLoadedJson(json){return json=this.prepareData(json),novelData.novel=json,novelData.debugMode=novelData.novel.settings.debugMode,SoundManager.init(),UI.init(),novelData.novel.currentScene=SceneManager.changeScene(novelData.novel.scenes[0].name),novelData.status="Ready",novelData.debugMode&&console.log(novelData),console.log("-- Loading Novel.js complete! --")}}class Parser{static selectRandomOption(name){Util.checkFormat(name,"string");let separate=name.split("|");if(1===separate.length)return separate[0];let parsed=[];for(let j=0;j<separate.length;j++){let i=separate[j];i=i.split(","),parsed.push(i)}return parsed=this.chooseRandomly(parsed)}static chooseRandomly(options){let names=[],chances=[],rawChances=[],previous=0;for(let j=0;j<options.length;j++){i=options[j];names.push(i[0]),previous=parseFloat(i[1])+previous,chances.push(previous),rawChances.push(parseFloat(i[1]))}let totalChance=0;for(let k=0;k<rawChances.length;k++){var i=rawChances[k];totalChance+=parseFloat(i)}1!==totalChance&&console.error("ERROR: Invalid scene or choice odds (should add up to exactly 1)!");let value=Math.random(),nameIndex=0;for(let i1=0;i1<chances.length;i1++){if(value<(i=chances[i1]))return names[nameIndex];nameIndex++}}static parseItems(items){if(Util.checkFormat(items,"string"),""===items)return;let separate=items.split("|"),parsed=[];for(let j=0;j<separate.length;j++){let i=separate[j];i=i.split(","),parsed.push(i)}return parsed}static parseText(text){if(void 0!==text){Util.checkFormat(text,"string"),Util.validateTagParentheses(text)||console.error("ERROR: Invalid tags in text");let splitText=text.split("[file "),iterable=__range__(1,splitText.length,!0);for(let j=0;j<iterable.length;j++){let name="";if(splitText[index=iterable[j]]){let iterable1=splitText[index].split("");for(let k=0;k<iterable1.length&&"]"!==(i=iterable1[k]);k++)name+=i}if(""!==(name=name.replace(/\s+/g,""))){let newText=null;for(let i1=0;i1<novelData.novel.externalText.length;i1++)if((i=novelData.novel.externalText[i1]).name===name){newText=i.content;break}null===newText&&(newText=LanguageManager.getCorrectLanguageCsvString(name)),null!==newText&&(text=text.split(`[file ${name}]`).join(newText))}}for(let j1=0;j1<novelData.novel.tagPresets.length;j1++){let tagName=`[p ${(i=novelData.novel.tagPresets[j1]).name}]`;text.indexOf(tagName)>-1&&(text=text.split(tagName).join(i.start)),tagName=`[/p ${i.name}]`,text.indexOf(tagName)>-1&&(text=text.split(tagName).join(i.end))}for(let i=0;i<100;i++)text=text.split(`[s${i}]`).join(`<span class="highlight-${i}">`);splitText=(text=(text=text.split("[/s]").join("</span>")).replace(/\/\[/g,"OPEN_BRACKET_REPLACEMENT").replace(/\/\]/g,"CLOSE_BRACKET_REPLACEMENT")).split(/\[|\]/);var index=0;for(let i2=0;i2<splitText.length;i2++){var s=splitText[i2];splitText[index]=s.replace(/OPEN_BRACKET_REPLACEMENT/g,"[").replace(/CLOSE_BRACKET_REPLACEMENT/g,"]"),index++}let spansToBeClosed=0,asToBeClosed=0;index=0;let iterable3=__range__(0,splitText.length-1,!0);for(let j2=0;j2<iterable3.length;j2++){if("if"===(s=splitText[index=iterable3[j2]]).substring(0,2)){parsed=s.split("if ");this.parseStatement(parsed[1])?splitText[index]="":(splitText[index]='<span style="display:none;">',spansToBeClosed++)}else if("/if"===s.substring(0,3))spansToBeClosed>0?(splitText[index]="</span>",spansToBeClosed--):splitText[index]="";else if("inv."===s.substring(0,4)){let value=s.substring(4,s.length);splitText[index]=0;for(let k2=0;k2<novelData.novel.inventories[novelData.novel.currentInventory].length;k2++)(i=novelData.novel.inventories[novelData.novel.currentInventory][k2]).name===value&&(splitText[index]=i.value)}else if("print"===s.substring(0,5)){parsed=s.split("print ");parsed=this.parseStatement(parsed[1]),isNaN(parseFloat(parsed))||(parsed=parseFloat(parsed.toFixed(novelData.novel.settings.floatPrecision))),splitText[index]=parsed}else if("exec"===s.substring(0,4)){parsed=s.substring(5,s.length);let p=novelData.parsedJavascriptCommands.push(parsed);p--,splitText[index]=`<span class="execute-command com-${p}"></span>`}else if("pause"===s.substring(0,5)){parsed=s.substring(6,s.length);splitText[index]=`<span class="pause ${parsed}"></span>`}else if("sound"===s.substring(0,5)){parsed=s.split("sound ");splitText[index]=`<span class="play-sound ${parsed[1]}"></span>`}else if("/music"===s.substring(0,6)){parsed=s.split("/music ");splitText[index]=`<span class="stop-music ${parsed[1]}"></span>`}else if("music"===s.substring(0,5)){parsed=s.split("music ");splitText[index]=`<span class="play-music ${parsed[1]}"></span>`}else if("/speed"===s.substring(0,6))splitText[index]='<span class="default-speed"></span>';else if("speed"===s.substring(0,5)){parsed=s.split("speed ");splitText[index]=`<span class="set-speed ${parsed[1]}"></span>`}else if("/scrollSound"===s.substring(0,12))splitText[index]='<span class="default-scroll-sound"></span>';else if("scrollSound"===s.substring(0,11)){parsed=s.split("scrollSound ");let p=novelData.parsedScrollsounds.push(parsed);p--,splitText[index]=`<span class="set-scroll-sound s-${p}"></span>`}else if("input"===s.substring(0,5)){parsed=s.split("input ");let nameText="";for(let i3=0;i3<novelData.novel.inventories[novelData.novel.currentInventory].length;i3++){var i=novelData.novel.inventories[novelData.novel.currentInventory][i3];i.name===parsed[1]&&(nameText=i.value)}splitText[index]=`<input type="text" value="${nameText}" name="input" class="input-${parsed[1]}" onblur="UI.updateInputs(true)">`}else if("choice"===s.substring(0,6)){var parsed=s.split("choice ");splitText[index]=`<a href="#" onclick="SceneManager.selectChoiceByNameByClicking(event,'${parsed[1]}')">`,asToBeClosed++}else"/choice"===s.substring(0,7)&&(asToBeClosed>0?(splitText[index]="</a>",asToBeClosed--):splitText[index]="");index++}return text=splitText.join("")}}static parseStatement(s){if(void 0===s)return;s=s.toString(),Util.checkFormat(s,"string"),Util.validateParentheses(s)||console.error("ERROR: Invalid parentheses in statement"),s=s.replace(/\s+/g,"");let parsedString=s.split(/\(|\)|\+|\*|\-|\/|<=|>=|<|>|==|!=|\|\||&&/),parsedValues=[];for(let j=0;j<parsedString.length;j++){let val=parsedString[j],type=this.getStatementType(val);switch(type){case"item":let found=!1;for(let k=0;k<novelData.novel.inventories[novelData.novel.currentInventory].length;k++){var i=novelData.novel.inventories[novelData.novel.currentInventory][k];i.name===val.substring(4,val.length)&&(parsedValues.push(i.value),found=!0)}found||parsedValues.push(0);break;case"rand":val=val.split(".");let vals=val[1].split(","),plus=!0;if("minus"===vals[0].substring(0,5)&&(vals[0]=vals[0].substring(5,vals[0].length),plus=!1),"minus"===vals[1].substring(0,5)&&(vals[1]=vals[1].substring(5,vals[1].length),plus=!1),plus)var result=Math.random()*vals[1]+vals[0];else var result=Math.random()*vals[1]-vals[0];if(void 0===vals[2]&&(vals[2]=0),0===vals[2])var result=Math.round(result);else var result=parseFloat(result).toFixed(vals[2]);parsedValues.push(result);break;case"var":val=this.findValue(val.substring(4,val.length),!0),val=isNaN(parseFloat(val))?`'${val}'`:parseFloat(val).toFixed(novelData.novel.settings.floatPrecision),parsedValues.push(val);break;case"float":parsedValues.push(parseFloat(val).toFixed(novelData.novel.settings.floatPrecision));break;case"int":parsedValues.push(parseInt(val));break;case"string":""!==val?parsedValues.push(`'${val}'`):parsedValues.push("")}}let iterable=__range__(0,parsedString.length-1,!0);for(let i1=0;i1<iterable.length;i1++){var i=iterable[i1];""!==parsedString[i]&&""!==parsedValues[i]&&(s=s.replace(new RegExp(parsedString[i],"g"),parsedValues[i]),s=s.replace(new RegExp("''","g"),"'"))}let returnVal=eval(s);return"true"===returnVal&&(returnVal=!0),"false"===returnVal&&(returnVal=!1),returnVal}static getStatementType(val){let type=null;return type="inv."===val.substring(0,4)?"item":"var."===val.substring(0,4)?"var":"rand."===val.substring(0,5)?"rand":isNaN(parseFloat(val))||-1!==val.toString().indexOf(".")?isNaN(parseFloat(val))||-1===val.toString().indexOf(".")?"string":"float":"int"}static findValue(parsed,toPrint){let splitted=parsed.split(",");if(toPrint)variable=this.findValueByName(novelData.novel,splitted[0])[0];else if(splitted.length>1)variable=this.findValueByName(novelData.novel,splitted[0])[0];else variable=this.findValueByName(novelData.novel,splitted[0])[1];let iterable=__range__(0,splitted.length-1,!0);for(let j=0;j<iterable.length;j++){let i=iterable[j];if(Util.isOdd(i))variable=variable[parseInt(splitted[i])];else if(0!==i)if(toPrint){"parsedText"!==splitted[i]&&"text"!==splitted[i]||(splitted[i]="parsedText",variable.parsedText=this.parseText(variable.text));variable=this.findValueByName(variable,splitted[i])[0]}else var variable=this.findValueByName(variable,splitted[i])[1]}return void 0===variable&&console.warn("WARNING: Searched value not found."),variable}static findValueByName(obj,string){Util.checkFormat(string,"string");let parts=string.split("."),newObj=obj[parts[0]];if(parts[1]){parts.splice(0,1);let newString=parts.join(".");return this.findValueByName(newObj,newString)}let r=[];return r[0]=newObj,r[1]=obj,r}}class SceneManager{static tryContinue(){if(TextPrinter.printCompleted&&1===TextPrinter.tickSpeedMultiplier)return this.selectChoiceByName("Continue")}static selectChoice(choice){return this.exitScene(novelData.novel.currentScene),this.readItemEdits(choice),this.readSounds(choice,!0),this.readSaving(choice),this.readExecutes(choice),this.readCheckpoints(choice),this.readLanguage(choice),void 0!==choice.nextScene?this.changeScene(choice.nextScene):void 0!==choice.nextChoice?this.selectChoiceByName(Parser.selectRandomOption(choice.nextChoice)):this.updateScene(novelData.novel.currentScene,!0),UI.updateInventories()}static selectChoiceByNameByClicking(event,name){return event.stopPropagation(),event.preventDefault(),this.selectChoiceByName(name)}static selectChoiceByName(name){for(let j=0;j<novelData.novel.currentScene.choices.length;j++){let i=novelData.novel.currentScene.choices[j];if(i.name===name){this.selectChoice(i);break}}}static selectChoiceById(id){if(novelData.novel.currentScene.choices[id])return this.selectChoice(novelData.novel.currentScene.choices[id])}static exitScene(scene){return scene.visited=!0,UI.updateInputs(!1),UI.resetChoices()}static changeScene(sceneNames){Util.checkFormat(sceneNames,"string");let scene=this.findSceneByName(Parser.selectRandomOption(sceneNames));return this.setupScene(scene),scene}static setupScene(scene){return this.updateScene(scene,!1),this.readItemEdits(novelData.novel.currentScene),this.readSounds(novelData.novel.currentScene,!1),this.readSaving(novelData.novel.currentScene),this.readExecutes(novelData.novel.currentScene),this.readCheckpoints(novelData.novel.currentScene),this.readLanguage(novelData.novel.currentScene),this.readMisc(novelData.novel.currentScene),UI.showHiddenInventoryArea(),TextPrinter.printText(scene.parsedText,!1)}static updateScene(scene,onlyUpdating){return scene=this.combineSceneTexts(scene),scene.parsedText=Parser.parseText(scene.combinedText),novelData.novel.currentScene=scene,UI.updateStyle(scene.style),onlyUpdating?(TextPrinter.printText(scene.parsedText,!0),TextPrinter.complete()):novelData.novel.parsedChoices=null}static findSceneByName(name){Util.checkFormat(name,"string");for(let j=0;j<novelData.novel.scenes.length;j++){let i=novelData.novel.scenes[j];if(i.name===name)return i}return console.error(`ERROR: Scene by name '${name}' not found!`)}static combineSceneTexts(s){if(Util.checkFormat(s,"object"),Util.checkFormat(s.text,"arrayOrString"),s.combinedText="","[object Array]"===Object.prototype.toString.call(s.text))for(let j=0;j<s.text.length;j++){let i=s.text[j];s.combinedText=s.combinedText+"<p>"+LanguageManager.getCorrectLanguageString(i)+"</p>"}else s.combinedText=s.text;return s}static readItemEdits(source){if(void 0!==source.changeInventory&&(novelData.novel.currentInventory=Parser.parseStatement(source.changeInventory),novelData.novel.currentInventory>novelData.novel.inventories.length)){let iterable=__range__(0,novelData.novel.currentInventory,!0);for(let j=0;j<iterable.length;j++){let i=iterable[j];void 0===novelData.novel.inventories[i]&&(novelData.novel.inventories[i]=[])}}if(void 0!==source.removeItem&&InventoryManager.removeItems(Parser.parseItems(source.removeItem)),void 0!==source.addItem&&InventoryManager.addItems(Parser.parseItems(source.addItem)),void 0!==source.setItem&&InventoryManager.setItems(Parser.parseItems(source.setItem)),void 0!==source.setValue)for(let k=0;k<source.setValue.length;k++){val=source.setValue[k];InventoryManager.setValue(val.path,Parser.parseStatement(val.value.toString()))}if(void 0!==source.increaseValue)for(let i1=0;i1<source.increaseValue.length;i1++){var val=source.increaseValue[i1];InventoryManager.increaseValue(val.path,Parser.parseStatement(val.value.toString()))}if(void 0!==source.decreaseValue)return source.decreaseValue.map(val=>InventoryManager.decreaseValue(val.path,Parser.parseStatement(val.value.toString())))}static readSounds(source,clicked){let played=!1;return void 0!==source.playSound&&(SoundManager.playSound(Parser.parseStatement(source.playSound),!1),played=!0),clicked&&!played&&SoundManager.playDefaultClickSound(),void 0!==source.startMusic&&SoundManager.startMusic(Parser.parseStatement(source.startMusic)),void 0!==source.stopMusic&&SoundManager.stopMusic(Parser.parseStatement(source.stopMusic)),void 0!==source.scrollSound?novelData.novel.currentScene.scrollSound=Parser.parseStatement(source.scrollSound):novelData.novel.settings.soundSettings.defaultScrollSound?novelData.novel.currentScene.scrollSound=novelData.novel.settings.soundSettings.defaultScrollSound:novelData.novel.currentScene.scrollSound=void 0}static readExecutes(source){if(void 0!==source.executeJs)return eval(source.executeJs)}static readLanguage(source){if(void 0!==source.setLanguage)return LanguageManager.setLanguage(source.setLanguage)}static readMisc(source){if(void 0!==source.skipEnabled)val=Parser.parseStatement(source.skipEnabled);else val=novelData.novel.settings.scrollSettings.textSkipEnabled;if(novelData.novel.currentScene.skipEnabled=val,UI.showSkipButton(val),void 0!==source.revisitSkipEnabled?novelData.novel.currentScene.revisitSkipEnabled=Parser.parseStatement(source.revisitSkipEnabled):novelData.novel.currentScene.revisitSkipEnabled=novelData.novel.settings.scrollSettings.revisitSkipEnabled,void 0!==source.scrollSpeed?novelData.novel.currentScene.scrollSpeed=source.scrollSpeed:novelData.novel.currentScene.scrollSpeed=novelData.novel.settings.scrollSettings.defaultScrollSpeed,void 0!==source.inventoryHidden)val=Parser.parseStatement(source.inventoryHidden);else val=novelData.novel.settings.inventoryHidden;if(novelData.inventoryHidden=val,UI.showInventoryArea(!val),void 0!==source.choicesHidden)val=Parser.parseStatement(source.choicesHidden);else val=novelData.novel.settings.choicesHidden;if(novelData.choicesHidden=val,UI.showChoicesArea(!val),void 0!==source.saveButtonsHidden)val=Parser.parseStatement(source.saveButtonsHidden);else var val=!novelData.novel.settings.showSaveButtons;return novelData.saveButtonsHidden=val,UI.showSaveButtons(!val)}static readSaving(source){if(void 0!==source.save&&NovelManager.saveData(),void 0!==source.load)return UI.showLoadNotification()}static readCheckpoints(source){if(void 0!==source.saveCheckpoint){void 0===novelData.novel.checkpoints&&(novelData.novel.checkpoints=[]);let dataChanged=!1;for(let j=0;j<novelData.novel.checkpoints.length;j++)(i=novelData.novel.checkpoints[j]).name===Parser.parseStatement(source.saveCheckpoint)&&(i.scene=novelData.novel.currentScene.name,dataChanged=!0);if(!dataChanged){let checkpoint={name:Parser.parseStatement(source.saveCheckpoint),scene:novelData.novel.currentScene.name};novelData.novel.checkpoints.push(checkpoint)}}if(void 0!==source.loadCheckpoint){void 0===novelData.novel.checkpoints&&(novelData.novel.checkpoints=[]);for(let k=0;k<novelData.novel.checkpoints.length;k++){var i=novelData.novel.checkpoints[k];i.name===Parser.parseStatement(source.loadCheckpoint)&&this.changeScene(i.scene)}}}static requirementsFilled(choice){let reqs=[];if(void 0!==choice.itemRequirement){let requirements=Parser.parseItems(choice.itemRequirement);reqs.push(InventoryManager.checkRequirements(requirements))}void 0!==choice.requirement&&reqs.push(Parser.parseStatement(choice.requirement));let success=!0;for(let i=0;i<reqs.length;i++){let r=reqs[i];!1===r&&(success=!1)}return success}}class SoundManager{static init(){let index=0;for(let i=0;i<novelData.novel.sounds.length;i++){let s=novelData.novel.sounds[i];s.sound=new Audio(novelPath+"/sounds/"+s.file),index++}}static playDefaultClickSound(name,clicked){return this.playSound(novelData.novel.settings.soundSettings.defaultClickSound,!1)}static playSound(name,isMusic){if(void 0!==name){name=Parser.selectRandomOption(name);for(let i=0;i<novelData.novel.sounds.length;i++){let s=novelData.novel.sounds[i];if(s.name===name){let{sound:sound}=s;return sound.volume=isMusic?novelData.novel.settings.soundSettings.musicVolume:novelData.novel.settings.soundSettings.soundVolume,sound.play(),sound}}}}static isPlaying(name){for(let j=0;j<novelData.music.length;j++){let i=novelData.music[j];return!i.paused}}static startMusic(name){for(let i=0;i<novelData.music.length;i++){let m=novelData.music[i];if(m.name===name)return}let music=this.playSound(name,!0);if(void 0!==music)return music.addEventListener("ended",function(){this.currentTime=0,this.play()},!1),novelData.music.push({name:name,music:music})}static stopMusic(name){for(let j=0;j<novelData.music.length;j++){let i=novelData.music[j];if(name===i.name){i.music.pause();let index=novelData.music.indexOf(i);novelData.music.splice(index,1)}}}}class TextPrinter{static printText(text,noBuffers){if(novelData.printer.printCompleted=!1,novelData.printer.currentText="",UI.updateText(novelData.printer.currentText),UI.disableSkipButton(),UI.showContinueButton(!1),novelData.printer.fullText=text,novelData.printer.currentOffset=-1,novelData.printer.soundBuffer=[],novelData.printer.musicBuffer=[],novelData.printer.stopMusicBuffer=[],novelData.printer.executeBuffer=[],novelData.printer.buffersExecuted=!1,noBuffers&&(novelData.printer.buffersExecuted=!0),novelData.printer.defaultInterval=novelData.novel.currentScene.scrollSpeed,this.setTickSoundFrequency(novelData.printer.defaultInterval),!novelData.novel.currentScene.visited||!novelData.novel.currentScene.revisitSkipEnabled)return setTimeout(this.onTick(),novelData.printer.defaultInterval);this.complete()}static trySkip(){novelData.novel.currentScene.skipEnabled&&this.complete()}static complete(){novelData.printer.printCompleted=!0,novelData.printer.currentOffset=0,UI.enableSkipButton(),this.executeBuffers(),novelData.printer.currentText=novelData.printer.fullText,UI.updateText(novelData.printer.currentText),UI.updateChoices()}static executeBuffers(){if(!novelData.printer.buffersExecuted){let ss=[],first=!0;if(novelData.printer.fullText.indexOf("play-sound")>-1){var s=novelData.printer.fullText.split("play-sound ");for(let j=0;j<s.length;j++){var i=s[j];first||ss.push(i.split(/\s|\"/)[0]),first=!1}}if(ss.length>0){let iterable=__range__(0,ss.length,!0);for(let k=0;k<iterable.length;k++){var i=iterable[k];__in__(ss[i],novelData.printer.soundBuffer)||SoundManager.playSound(Parser.parseStatement(ss[i]))}}if(ss=[],first=!0,novelData.printer.fullText.indexOf("play-music")>-1){var s=novelData.printer.fullText.split("play-music ");for(let i1=0;i1<s.length;i1++){var i=s[i1];first||ss.push(i.split(/\s|\"/)[0]),first=!1}}if(ss.length>0){let iterable1=__range__(0,ss.length,!0);for(let j1=0;j1<iterable1.length;j1++){var i=iterable1[j1];__in__(ss[i],novelData.printer.musicBuffer)||SoundManager.startMusic(Parser.parseStatement(ss[i]))}}if(ss=[],first=!0,novelData.printer.fullText.indexOf("stop-music")>-1){var s=novelData.printer.fullText.split("stop-music ");for(let k1=0;k1<s.length;k1++){var i=s[k1];first||ss.push(i.split(/\s|\"/)[0]),first=!1}}if(ss.length>0){let iterable2=__range__(0,ss.length,!0);for(let i2=0;i2<iterable2.length;i2++){var i=iterable2[i2];__in__(ss[i],novelData.printer.stopMusicBuffer)||SoundManager.stopMusic(Parser.parseStatement(ss[i]))}}if(ss=[],first=!0,novelData.printer.fullText.indexOf("execute-command")>-1){var s=novelData.printer.fullText.split("execute-command ");for(let j2=0;j2<s.length;j2++){var i=s[j2];first||ss.push(i.split(/\s|\"/)[0]),first=!1}}if(ss.length>0){let iterable3=__range__(0,ss.length,!0);for(let k2=0;k2<iterable3.length;k2++){var i=iterable3[k2];__in__(ss[i],novelData.printer.executeBuffer)||void 0===ss[i]||eval(novelData.parsedJavascriptCommands[parseInt(ss[i].substring(4,ss[i].length))])}}novelData.printer.buffersExecuted=!0}}static unpause(){UI.showContinueButton(!1),"input"===novelData.printer.pause&&(novelData.printer.pause=0)}static fastScroll(){novelData.novel.currentScene.skipEnabled&&(novelData.printer.tickSpeedMultiplier=novelData.novel.settings.scrollSettings.fastScrollSpeedMultiplier)}static stopFastScroll(){novelData.printer.tickSpeedMultiplier=1}static setTickSoundFrequency(freq){let threshold=novelData.novel.settings.scrollSettings.tickFreqThreshold;novelData.printer.tickSoundFrequency=1,freq<=2*threshold&&(novelData.printer.tickSoundFrequency=2),freq<=threshold&&(novelData.printer.tickSoundFrequency=3)}static onTick(){if("input"!==novelData.printer.pause&&novelData.printer.pause>0&&novelData.printer.pause--,0===novelData.printer.pause){if(novelData.printer.speedMod||(novelData.printer.interval=novelData.printer.defaultInterval),0===novelData.printer.defaultInterval)return void this.complete();if(novelData.printer.currentText===novelData.printer.fullText)return;for(;" "===novelData.printer.fullText[novelData.printer.currentOffset]||"<"===novelData.printer.fullText[novelData.printer.currentOffset]||">"===novelData.printer.fullText[novelData.printer.currentOffset];)this.readTags();if(novelData.printer.currentText=novelData.printer.fullText.substring(0,novelData.printer.currentOffset),UI.updateText(novelData.printer.currentText),++novelData.printer.currentOffset>=novelData.printer.fullText.length)return void this.complete();++novelData.printer.tickCounter>=novelData.printer.tickSoundFrequency&&"none"!==novelData.printer.scrollSound&&0!==novelData.printer.interval&&(null!==novelData.printer.scrollSound?SoundManager.playSound(novelData.printer.scrollSound):void 0!==novelData.novel.currentScene.scrollSound&&SoundManager.playSound(novelData.novel.currentScene.scrollSound),novelData.printer.tickCounter=0)}return this.setTickSoundFrequency(novelData.printer.interval/novelData.printer.tickSpeedMultiplier),setTimeout(function(){TextPrinter.onTick()},novelData.printer.interval/novelData.printer.tickSpeedMultiplier)}static readTags(){if(" "===novelData.printer.fullText[novelData.printer.currentOffset]&&novelData.printer.currentOffset++,">"===novelData.printer.fullText[novelData.printer.currentOffset]&&novelData.printer.currentOffset++,"<"===novelData.printer.fullText[novelData.printer.currentOffset]){let i=novelData.printer.currentOffset,str="";for(i++;">"!==novelData.printer.fullText[i-1]&&"<"!==novelData.printer.fullText[i];)str+=novelData.printer.fullText[i],i++;if((str=str.substring(1,str.length)).indexOf("display:none;")>-1){let disp="",spans=1;for(;;)if(i++,disp+=novelData.printer.fullText[i],-1!==disp.indexOf("/span")?(spans--,disp=""):-1!==disp.indexOf("span")&&(spans++,disp=""),0===spans)break;i++}this.bufferHidden(str),this.bufferNonHidden(str),novelData.printer.currentOffset=i,novelData.printer.offsetChanged=!0}}static bufferHidden(str){if(str.indexOf("play-sound")>-1&&str.indexOf("display:none;")>-1&&(s=(s=str.split("play-sound "))[1].split(/\s|\"/)[0],novelData.printer.soundBuffer.push(Parser.parseStatement(s))),str.indexOf("play-music")>-1&&str.indexOf("display:none;")>-1&&(s=(s=str.split("play-music "))[1].split(/\s|\"/)[0],novelData.printer.musicBuffer.push(Parser.parseStatement(s))),str.indexOf("stop-music")>-1&&str.indexOf("display:none;")>-1&&(s=(s=str.split("stop-music "))[1].split(/\s|\"/)[0],novelData.printer.stopMusicBuffer.push(Parser.parseStatement(s))),str.indexOf("execute-command")>-1&&str.indexOf("display:none;")>-1){var s=str.split("execute-command ");return s=s[1].split(/\s|\"/)[0],novelData.printer.executeBuffer.push(Parser.parseStatement(s))}}static bufferNonHidden(str){if(-1===str.indexOf("display:none;")){if(str.indexOf("play-sound")>-1){var s=str.split("play-sound ");s=s[1].split(/\s|\"/)[0],novelData.printer.soundBuffer.push(Parser.parseStatement(s)),SoundManager.playSound(Parser.parseStatement(s))}if(str.indexOf("play-music")>-1){var s=str.split("play-music ");s=s[1].split(/\s|\"/)[0],novelData.printer.musicBuffer.push(Parser.parseStatement(s)),SoundManager.startMusic(Parser.parseStatement(s))}if(str.indexOf("stop-music")>-1){var s=str.split("stop-music ");s=s[1].split(/\s|\"/)[0],novelData.printer.stopMusicBuffer.push(Parser.parseStatement(s)),SoundManager.stopMusic(Parser.parseStatement(s))}if(str.indexOf("pause")>-1){var s=str.split("pause ");s=s[1].split(/\s|\"/)[0],novelData.printer.pause=s,"input"===novelData.printer.pause&&UI.showContinueButton(!0)}if(str.indexOf("execute-command")>-1){var s=str.split("execute-command ");s=s[1].split(/\s|\"/)[0],novelData.printer.executeBuffer.push(s),void 0!==s&&eval(novelData.parsedJavascriptCommands[parseInt(s.substring(4,s.length))])}if(str.indexOf("set-speed")>-1){var s=str.split("set-speed ");s=s[1].split(/\s|\"/)[0],novelData.printer.interval=Parser.parseStatement(s),novelData.printer.speedMod=!0}if(str.indexOf("default-speed")>-1&&(novelData.printer.interval=novelData.printer.defaultInterval,novelData.printer.speedMod=!1),str.indexOf("set-scroll-sound")>-1){var s=str.split("set-scroll-sound ");s=s[1].split(/\s|\"/)[0],novelData.printer.scrollSound=Parser.selectRandomOption(novelData.parsedScrollsounds[parseInt(s.substring(2,s.length))][1]),console.log(novelData.printer.scrollSound+" ---")}if(str.indexOf("default-scroll-sound")>-1)return novelData.printer.scrollSound=void 0}}}class UI{static init(){let n=document.getElementsByTagName("novel")[0];if(n||(n=document.getElementById("novel-area")),n){let d=document.createElement("div");return d.id="novel-area",d.innerHTML=`<div id="novel-style-area">\r\n <div id="novel-notification-wrapper">\r\n <div id="novel-save-notification" class="novel-notification">\r\n <p class="novel-save-text"></p>\r\n <p><textarea name="save-text" readonly></textarea></p>\r\n <p><button type="button" class="novel-close-button" onclick="UI.closeSaveNotification()"></button><button type="button" class="novel-copy-button" onclick="UI.copyText()"></button></p>\r\n </div>\r\n <div id="novel-load-notification" class="novel-notification">\r\n <p class="novel-load-text"></p>\r\n <p><textarea name="load-text"></textarea></p>\r\n <p><button type="button" class="novel-close-button" onclick="UI.closeLoadNotification(false)"></button><button type="button" class="novel-load-data-button" onclick="UI.closeLoadNotification(true)"></button></p>\r\n </div>\r\n </div>\r\n <div id="novel-text-area">\r\n <div id="novel-text"></div>\r\n <button type="button" class="novel-skip-button" onclick="TextPrinter.complete()"></button>\r\n <button type="button" class="novel-continue-button" onclick="TextPrinter.unpause()"></button>\r\n </div>\r\n <div id="novel-choices-area">\r\n <ul id="novel-choice-list"></ul>\r\n </div>\r\n <div id="novel-inventory-area">\r\n <h5 class="novel-inventory-title"></h5>\r\n <ul id="novel-inventory"></ul>\r\n </div>\r\n <div id="novel-hidden-inventory-area">\r\n <h5 class="novel-hidden-inventory-title"></h5>\r\n <ul id="novel-hidden-inventory"></ul>\r\n </div>\r\n <div id="novel-save-area">\r\n <button type="button" class="novel-save-button" onclick="NovelManager.saveData()"></button>\r\n <button type="button" class="novel-load-button" onclick="UI.showLoadNotification()"></button>\r\n </div>\r\n </div>`,n.parentNode.insertBefore(d,n),n.parentNode.removeChild(n),void this.updateUILanguage()}}static updateUILanguage(){document.getElementsByClassName("novel-save-text")[0].innerHTML=LanguageManager.getUIString("saveText"),document.getElementsByClassName("novel-load-text")[0].innerHTML=LanguageManager.getUIString("loadText");let iterable=document.getElementsByClassName("novel-close-button");for(let j=0;j<iterable.length;j++){let i=iterable[j];i.innerHTML=LanguageManager.getUIString("closeButton")}document.getElementsByClassName("novel-copy-button")[0].innerHTML=LanguageManager.getUIString("copyButton"),document.getElementsByClassName("novel-skip-button")[0].innerHTML=LanguageManager.getUIString("skipButton"),document.getElementsByClassName("novel-continue-button")[0].innerHTML=LanguageManager.getUIString("continueButton"),document.getElementsByClassName("novel-inventory-title")[0].innerHTML=LanguageManager.getUIString("inventoryTitle"),document.getElementsByClassName("novel-hidden-inventory-title")[0].innerHTML=LanguageManager.getUIString("hiddenInventoryTitle"),document.getElementsByClassName("novel-load-button")[0].innerHTML=LanguageManager.getUIString("loadButton"),document.getElementsByClassName("novel-load-data-button")[0].innerHTML=LanguageManager.getUIString("loadDataButton"),document.getElementsByClassName("novel-save-button")[0].innerHTML=LanguageManager.getUIString("saveButton")}static updateStyle(style){let e=document.getElementById("novel-style-area");void 0===style&&(style=""),e.setAttribute("class",style)}static disableSkipButton(){null!==document.querySelector(".novel-skip-button")&&(document.querySelector(".novel-skip-button").disabled=!0)}static enableSkipButton(){null!==document.querySelector(".novel-skip-button")&&(document.querySelector(".novel-skip-button").disabled=!0)}static showSkipButton(show){let e=document.getElementsByClassName("novel-skip-button")[0];show&&novelData.novel.settings.showSkipButton?e.style.display="inline":e.style.display="none"}static showChoicesArea(show){let e=document.getElementById("novel-choices-area");e.style.display=show?"inline":"none"}static showInventoryArea(show){let e=document.getElementById("novel-inventory-area");e.style.display=show?"inline":"none"}static showHiddenInventoryArea(){let e=document.getElementById("novel-hidden-inventory-area");novelData.novel.settings.debugMode?e.style.display="inline":e.style.display="none"}static showSaveButtons(show){let e=document.getElementById("novel-save-area");e.style.display=show?"inline":"none"}static showContinueButton(show){null!==document.querySelector(".novel-continue-button")&&(document.querySelector(".novel-continue-button").style.display=show?"inline":"none")}static updateText(text){document.getElementById("novel-text").innerHTML=text}static showSaveNotification(text){let e=document.getElementById("novel-save-notification");e.querySelectorAll("textarea")[0].value=text,e.style.display="block"}static closeSaveNotification(){document.getElementById("novel-save-notification").style.display="none"}static showLoadNotification(){if("text"===novelData.novel.settings.saveMode){let e=document.getElementById("novel-load-notification");e.style.display="block"}else NovelManager.loadGame()}static closeLoadNotification(load,changeScene){let e=document.getElementById("novel-load-notification");if(load){let textArea=e.querySelectorAll("textarea");NovelManager.loadData(textArea[0].value,changeScene),textArea[0].value=""}e.style.display="none"}static copyText(){document.getElementById("novel-save-notification").querySelector("textarea").select();try{let successful;return successful=document.execCommand("copy")}catch(err){console.error(`Error! Copying to clipboard failed: ${err}`)}}static updateInputs(needForUpdate){let inputs=document.getElementById("novel-area").querySelectorAll("input");for(let j=0;j<inputs.length;j++){let i=inputs[j];for(let k=0;k<novelData.novel.inventories[novelData.novel.currentInventory].length;k++){let a=novelData.novel.inventories[novelData.novel.currentInventory][k];a.name===i.className.substring(6,i.className.length)&&(a.value=Util.stripHTML(i.value),needForUpdate&&SceneManager.updateScene(novelData.novel.currentScene,!0))}}}static resetChoices(){let choiceArea=document.getElementById("novel-choice-list");return(()=>{let result=[];for(;choiceArea.firstChild;)result.push(choiceArea.removeChild(choiceArea.firstChild));return result})()}static resetInventories(){let inventoryArea=document.getElementById("novel-inventory");for(;inventoryArea.firstChild;)inventoryArea.removeChild(inventoryArea.firstChild);return inventoryArea=document.getElementById("novel-hidden-inventory"),(()=>{let result=[];for(;inventoryArea.firstChild;)result.push(inventoryArea.removeChild(inventoryArea.firstChild));return result})()}static updateChoices(){this.resetChoices();let choiceArea=document.getElementById("novel-choice-list"),i=0,iterable=__range__(0,novelData.novel.currentScene.choices.length,!1);for(let j=0;j<novelData.novel.currentScene.choices.length;j++){i=iterable[j];let choice=novelData.novel.currentScene.choices[i];if(choice.text)if(choice.parsedText=Parser.parseText(LanguageManager.getCorrectLanguageString(choice.text)),SceneManager.requirementsFilled(choice))(li=document.createElement("li")).innerHTML=`<a href="#"; onclick="SceneManager.selectChoiceById(${i})">${choice.parsedText}</a>`,choiceArea.appendChild(li);else if(choice.alwaysShow||novelData.novel.settings.alwaysShowDisabledChoices){var li=document.createElement("li");li.innerHTML=choice.parsedText,choiceArea.appendChild(li)}}}static updateInventories(){this.resetInventories();let inventoryArea=document.getElementById("novel-inventory"),hiddenInventoryArea=document.getElementById("novel-hidden-inventory");for(let i=0;i<novelData.novel.inventories[novelData.novel.currentInventory].length;i++){let item=novelData.novel.inventories[novelData.novel.currentInventory][i],targetInventory=hiddenInventoryArea;if(item.hidden&&void 0!==item.hidden||(targetInventory=inventoryArea),item.value>0||isNaN(item.value)){let li=document.createElement("li");li.class="novel-inventory-item";let innerHTML=LanguageManager.getItemAttribute(item,"displayName")+" - "+item.value;innerHTML+='<ul class="novel-inventory-item-info">',item.description&&(innerHTML=innerHTML+'<li class="novel-inventory-item-description">'+LanguageManager.getItemAttribute(item,"description")+"</li>"),innerHTML+="</ul>",li.innerHTML=innerHTML,targetInventory.appendChild(li)}}}}class Util{static isEven(n){return n%2==0}static isOdd(n){return 1===Math.abs(n%2)}static stripHTML(text){let regex=/(<([^>]+)>)/gi;return text.replace(regex,"")}static checkFormat(s,format,suppressErrors){return void 0===suppressErrors&&(suppressErrors=!1),"array"===format?"[object Array]"===Object.prototype.toString.call(s)||(suppressErrors||console.error(`ERROR: Invalid input format (should be ${format})`),!1):"arrayOrString"===format?"[object Array]"===Object.prototype.toString.call(s)||"string"==typeof s||(suppressErrors||console.error(`ERROR: Invalid input format (should be ${format})`),!1):typeof s===format||(suppressErrors||console.error(`ERROR: Invalid input format (should be ${format})`),!1)}static validateParentheses(s){let open=0;for(let j=0;j<s.length;j++){let i=s[j];if("("===i&&open++,")"===i){if(!(open>0))return!1;open--}}return 0===open}static validateTagParentheses(s){let open=0,index=0;for(let j=0;j<s.length;j++){let i=s[j];if("["===i&&(s[index-1]?"/"!==s[index-1]&&open++:open++),"]"===i)if(s[index-1]){if("/"!==s[index-1]){if(!(open>0))return!1;open--}}else{if(!(open>0))return!1;open--}index++}return 0===open}static mergeObjArrays(list1,list2){let result={};return list1.concat(list2).forEach(function(item){let{name:name}=item,row=result[name];if(row)for(let column in item)row[column]=item[column];else result[name]=item}),Object.keys(result).map(name=>result[name])}}NovelManager.start();