Add an uploader for importing game files
This commit is contained in:
parent
750c395a4f
commit
6b66b70eb1
54
takhta.html
54
takhta.html
|
@ -77,6 +77,10 @@
|
||||||
.numentry {
|
.numentry {
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
#moveupload {
|
||||||
|
visibility: hidden;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -205,8 +209,12 @@
|
||||||
<input type="button" value="Undo" onclick="undoMove()">
|
<input type="button" value="Undo" onclick="undoMove()">
|
||||||
<input type="button" value="Redo" onclick="redoMove()">
|
<input type="button" value="Redo" onclick="redoMove()">
|
||||||
<input type="button" value="Flip board" onclick="flipBoard()">
|
<input type="button" value="Flip board" onclick="flipBoard()">
|
||||||
<input type="button" value="Download moves" onclick="download()">
|
|
||||||
</form>
|
</form>
|
||||||
|
<p><form id="shipping">
|
||||||
|
<input type="button" value="Download moves" onclick="download()">
|
||||||
|
<input type="file" id="moveupload" name="moveupload">
|
||||||
|
<button type="button"><label for="moveupload">Upload moves</label></button>
|
||||||
|
</form></p>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<form id="options">
|
<form id="options">
|
||||||
|
@ -279,6 +287,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// List the move
|
// List the move
|
||||||
|
updateMoveTable(move);
|
||||||
|
|
||||||
|
// Empty input field
|
||||||
|
document.getElementById('move').value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateMoveTable(move) {
|
||||||
let listElement = document.createElement('li');
|
let listElement = document.createElement('li');
|
||||||
|
|
||||||
if(moveHistory.length % 2 === 1) {
|
if(moveHistory.length % 2 === 1) {
|
||||||
|
@ -302,9 +317,6 @@
|
||||||
|
|
||||||
listElement.appendChild(document.createTextNode(move));
|
listElement.appendChild(document.createTextNode(move));
|
||||||
movelist.appendChild(listElement);
|
movelist.appendChild(listElement);
|
||||||
|
|
||||||
// Empty input field
|
|
||||||
document.getElementById('move').value = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function doMove(move) {
|
function doMove(move) {
|
||||||
|
@ -758,6 +770,40 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let moveUpload = document.getElementById("moveupload");
|
||||||
|
|
||||||
|
moveUpload.addEventListener("change", (event) => {
|
||||||
|
let file = event.target.files[0];
|
||||||
|
let reader = new FileReader();
|
||||||
|
let moveLine = /^\s*\d+\. /;
|
||||||
|
|
||||||
|
reader.addEventListener("load", (event) => {
|
||||||
|
let moveFile = event.target;
|
||||||
|
|
||||||
|
if(moveFile.error === null) {
|
||||||
|
let rows = moveFile.result.split("\n");
|
||||||
|
|
||||||
|
for(let row of rows) {
|
||||||
|
if(moveLine.test(row)) {
|
||||||
|
let entries = row.replace(moveLine, "").split(/\s+/);
|
||||||
|
|
||||||
|
for(let entry of entries) {
|
||||||
|
let ret = doMove(entry);
|
||||||
|
|
||||||
|
if("error" in ret) {
|
||||||
|
alert(ret.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateMoveTable(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
reader.readAsText(file);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue