mirror of
https://github.com/marcrobledo/savegame-editors.git
synced 2025-04-28 09:05:10 +00:00
feature: option to hide example file message
This commit is contained in:
parent
6fd9d4a7e6
commit
8603e4d4ea
@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
savegame-editor.js v20200719
|
savegame-editor.js v20230505
|
||||||
A library that lets you create easily a savegame editor. Made with vanilla JS.
|
A library that lets you create easily a savegame editor. Made with vanilla JS.
|
||||||
|
|
||||||
by Marc Robledo 2016-2020
|
by Marc Robledo 2016-2023
|
||||||
http://www.marcrobledo.com/license
|
http://www.marcrobledo.com/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -187,56 +187,58 @@ window.addEventListener('load', function(){
|
|||||||
loadSavegameFromInput(this);
|
loadSavegameFromInput(this);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
var demoMessage=document.createElement('button');
|
|
||||||
demoMessage.id='demo';
|
|
||||||
demoMessage.innerHTML='Do you want to try it out? <u>Try an example savegame</u>';
|
|
||||||
demoMessage.addEventListener('click', function(){
|
|
||||||
if(typeof window.fetch==='function'){
|
|
||||||
fetch(SavegameEditor.Filename)
|
|
||||||
.then(res => res.arrayBuffer()) // Gets the response and returns it as a blob
|
|
||||||
.then(ab => {
|
|
||||||
tempFile=new MarcFile(ab.byteLength);
|
|
||||||
tempFile.fileName=SavegameEditor.Filename;
|
|
||||||
tempFile._u8array=new Uint8Array(ab);
|
|
||||||
tempFile._dataView=new DataView(ab);
|
|
||||||
_tempFileLoadFunction();
|
|
||||||
})
|
|
||||||
.catch(function(){
|
|
||||||
alert('Unexpected error: can\'t download example savegame');
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
var oReq=new XMLHttpRequest();
|
|
||||||
oReq.open('GET', SavegameEditor.Filename, true);
|
|
||||||
oReq.responseType='arraybuffer';
|
|
||||||
|
|
||||||
oReq.onload=function(oEvent){
|
|
||||||
if(this.status===200) {
|
|
||||||
var ab=oReq.response; //Note: not oReq.responseText
|
|
||||||
|
|
||||||
tempFile=new MarcFile(ab.byteLength);
|
|
||||||
tempFile.fileName=SavegameEditor.Filename;
|
|
||||||
tempFile._u8array=new Uint8Array(ab);
|
|
||||||
tempFile._dataView=new DataView(ab);
|
|
||||||
_tempFileLoadFunction();
|
|
||||||
}else{
|
|
||||||
alert('Unexpected error: can\'t download example savegame');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
oReq.onerror=function(oEvent){
|
|
||||||
alert('Unexpected error: can\'t download example savegame');
|
|
||||||
};
|
|
||||||
|
|
||||||
oReq.send(null);
|
|
||||||
}
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
dragZone.appendChild(dragMessage);
|
dragZone.appendChild(dragMessage);
|
||||||
dragZone.appendChild(inputFile);
|
dragZone.appendChild(inputFile);
|
||||||
dragZone.appendChild(demoMessage);
|
|
||||||
document.body.appendChild(dragZone);
|
document.body.appendChild(dragZone);
|
||||||
|
|
||||||
|
|
||||||
|
if(!SavegameEditor.noDemo){
|
||||||
|
var demoMessage=document.createElement('button');
|
||||||
|
demoMessage.id='demo';
|
||||||
|
demoMessage.innerHTML='Do you want to try it out? <u>Try an example savegame</u>';
|
||||||
|
demoMessage.addEventListener('click', function(){
|
||||||
|
if(typeof window.fetch==='function'){
|
||||||
|
fetch(SavegameEditor.Filename)
|
||||||
|
.then(res => res.arrayBuffer()) // Gets the response and returns it as a blob
|
||||||
|
.then(ab => {
|
||||||
|
tempFile=new MarcFile(ab.byteLength);
|
||||||
|
tempFile.fileName=SavegameEditor.Filename;
|
||||||
|
tempFile._u8array=new Uint8Array(ab);
|
||||||
|
tempFile._dataView=new DataView(ab);
|
||||||
|
_tempFileLoadFunction();
|
||||||
|
})
|
||||||
|
.catch(function(){
|
||||||
|
alert('Unexpected error: can\'t download example savegame');
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
var oReq=new XMLHttpRequest();
|
||||||
|
oReq.open('GET', SavegameEditor.Filename, true);
|
||||||
|
oReq.responseType='arraybuffer';
|
||||||
|
|
||||||
|
oReq.onload=function(oEvent){
|
||||||
|
if(this.status===200) {
|
||||||
|
var ab=oReq.response; //Note: not oReq.responseText
|
||||||
|
|
||||||
|
tempFile=new MarcFile(ab.byteLength);
|
||||||
|
tempFile.fileName=SavegameEditor.Filename;
|
||||||
|
tempFile._u8array=new Uint8Array(ab);
|
||||||
|
tempFile._dataView=new DataView(ab);
|
||||||
|
_tempFileLoadFunction();
|
||||||
|
}else{
|
||||||
|
alert('Unexpected error: can\'t download example savegame');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
oReq.onerror=function(oEvent){
|
||||||
|
alert('Unexpected error: can\'t download example savegame');
|
||||||
|
};
|
||||||
|
|
||||||
|
oReq.send(null);
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
dragZone.appendChild(demoMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MarcDragAndDrop.add('dragzone', function(droppedFiles){
|
MarcDragAndDrop.add('dragzone', function(droppedFiles){
|
||||||
tempFile=new MarcFile(droppedFiles[0], _tempFileLoadFunction);
|
tempFile=new MarcFile(droppedFiles[0], _tempFileLoadFunction);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user