/* savegame-editor.js v20170504 A library that lets you create easily a savegame editor. Made with vanilla JS. by Marc Robledo 2016-2017 http://www.marcrobledo.com/license */ /* LIBRARIES */ /* MarcBinFile.js v2016 */ function MarcBinFile(a,b){if("function"!=typeof window.FileReader)throw console.error("MarcBinFile.js: Browser doesn't support FileReader."),"Invalid browser";if("object"==typeof a&&a.name&&a.size)this.file=a,this.fileName=this.file.name,this.fileSize=this.file.size,this.fileType=a.type;else if("object"==typeof a&&a.files){if(1!=a.files.length){for(var c=[],d=a.files.length,e=function(){d--,0==d&&b&&b.call()},f=0;f0;e++)d+=String.fromCharCode(c[e]);return d},MarcBinFile.prototype.writeByte=function(a,b){this.fileReader.dataView.setUint8(a,b,this.littleEndian)},MarcBinFile.prototype.writeByteSigned=function(a,b){this.fileReader.dataView.setInt8(a,b,this.littleEndian)},MarcBinFile.prototype.writeBytes=function(a,b){for(var c=0;c here or '; var inputFile=document.createElement('input'); inputFile.type='file'; inputFile.className='hidden'; inputFile.id='file-load'; inputFile.addEventListener('change', function(){ loadSavegameFromInput(this); }, false); var demoMessage=document.createElement('a'); demoMessage.id='demo'; demoMessage.href=SavegameEditor.Filename; demoMessage.download=SavegameEditor.Filename; demoMessage.innerHTML='Do you want to try it out? Download an example savegame'; dragZone.appendChild(dragMessage); dragZone.appendChild(inputFile); dragZone.appendChild(demoMessage); document.body.appendChild(dragZone); MarcDragAndDrop.add('dragzone', function(droppedFiles){ tempFile=new MarcBinFile(droppedFiles[0], _tempFileLoadFunction); }); //var warningMessage=mCreate('div', {id:'warning',class:'clickable padding-vertical'}); var warningMessage=document.createElement('div'); warningMessage.id='warning'; warningMessage.className='clickable padding-vertical'; warningMessage.addEventListener('click', function(){ this.className=this.className.replace(' visible',''); },false); var wrapper=document.createElement('div'); wrapper.className='wrapper text-center'; wrapper.innerHTML='Use this tool at your own risk. By using it, you are responsible of any data lost. I understand'; warningMessage.appendChild(wrapper); document.body.appendChild(warningMessage); }, false); /* binary and other helpers */ function compareBytes(offset,a2){ var a1=tempFile.readBytes(offset, a2.length); for(var i=0;i field.maxValue){ val=field.maxValue; } field.value=val; } function fixNumericFieldValueFromEvent(){fixNumericFieldValue(this)} function inputNumber(id,min,max,def){ var input=document.createElement('input'); input.id='number-'+id; input.className='full-width text-right'; input.type='text'; /* type='number' validation breaks getting input value when it's not valid */ input.minValue=min; input.maxValue=max; input.value=def; input.addEventListener('change', fixNumericFieldValueFromEvent, false); return input; } function inputFloat(id,min,max,def){ var input=document.createElement('input'); input.id='float-'+id; input.className='full-width text-right'; input.type='text'; input.minValue=min; input.maxValue=max; input.value=def; input.addEventListener('change', fixNumericFieldValueFromEvent, false); return input } function input(id,def){ var input=document.createElement('input'); input.id='input-'+id; input.className='full-width'; input.type='text'; input.value=def; return input } function checkbox(id,val){ var input=document.createElement('input'); input.id='checkbox-'+id; input.type='checkbox'; if(val) input.value=val; return input } function select(id,options,func){ var select; if(document.getElementById('select-'+id)){ select=document.getElementById('select-'+id); }else{ select=document.createElement('select'); select.id='select-'+id; select.className='full-width'; } if(options){ for(var i=0; i