access save and load features from the UI
This commit is contained in:
parent
2fbc484f4d
commit
618dcbcb0d
|
@ -27,6 +27,9 @@
|
|||
<button id="restart">Restart game</button>
|
||||
<button id="takeback">Take back</button>
|
||||
<button id="fullscreen" style="display: none;">Full screen</button>
|
||||
<button id="save">Save</button>
|
||||
<input type="file" id="fileElem" accept="application/json" style="display:none"/>
|
||||
<button id="load">Load</button>
|
||||
<br/><br/>
|
||||
<select id="mode">
|
||||
<option value="self-self">Self / Self</option>
|
||||
|
|
|
@ -212,6 +212,37 @@ $(document).ready(function () {
|
|||
});
|
||||
});
|
||||
|
||||
$("#save").on("click",function() {
|
||||
// save match to the file system
|
||||
match.save()
|
||||
.then( (data) => {
|
||||
var json = JSON.stringify(data,null,2);
|
||||
var a = document.createElement("a");
|
||||
var uriContent = "data:application/octet-stream," + encodeURIComponent(json);
|
||||
a.setAttribute("href",uriContent);
|
||||
a.setAttribute("download",gameName+".json");
|
||||
a.click();
|
||||
});
|
||||
});
|
||||
|
||||
// reading file locally
|
||||
var fileElem = $("#fileElem").on("change",function() {
|
||||
var fileReader = new FileReader();
|
||||
fileReader.readAsText(fileElem[0].files[0]);
|
||||
fileReader.onload = function(event) {
|
||||
var json = event.target.result;
|
||||
var data = JSON.parse(json);
|
||||
// load match
|
||||
match.load(data)
|
||||
.catch((e)=>{
|
||||
console.info("Failed to load",e);
|
||||
});
|
||||
}
|
||||
})
|
||||
$("#load").on("click",function() {
|
||||
fileElem[0].click();
|
||||
});
|
||||
|
||||
$("#takeback").on("click",function() {
|
||||
match.getPlayedMoves()
|
||||
.then( (playedMoves) => {
|
||||
|
|
Loading…
Reference in a new issue