Import from Text ( format used in waidotto )

This commit is contained in:
wphiphi 2022-01-04 17:51:27 +01:00 committed by GitHub
parent 9013a40a80
commit ee0174594c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -296,6 +296,50 @@ function getInfoBits(){
return result;
}
/***
*
* Load Waidotto QR text format
* https://github.com/waidotto/strong-qr-decoder
***/
function loadtxt2qrarray(lines) {
let sz = lines.length;
var is_data_module = getDataModule(lines); //getDataModule use lines.lenght only :D
for(let i=0;i<sz;i++) {
for (let j=0; j<sz ; j++ ) {
if ( true || is_data_module[i][j]){
switch ( lines[i][j] )
{
case 'X':
case 'x':
case 'O':
case 'o':
case '#':
case '1':
qr_array[i][j] = 1;
break;
case '_':
case ' ':
case '0':
qr_array[i][j] = 0;
break;
case '?':
qr_array[i][j] = -1 ; //grey
break;
default:
throw "Error invalid text QR caracters"
}
}
}
}
}
/***
*
* Create text format compatible with Strong Decoder based on qr_array values
@ -1452,6 +1496,35 @@ $(document).ready(function(){
}
})
$("#new-btn-import-txt").click(function(){
$("#import-txt").click();
return false;
})
$("#import-txt").change(function(){
if(this.files && this.files[0]){
var reader = new FileReader();
reader.onload = function (e) {
const file = e.target.result;
const lines = file.split(/\r\n|\n/);
$("#hidden-txt").val(lines.join('\n'));
$("#div-new").hide();
var version = (lines[0].length-17)/4;
generateTable( version );
loadtxt2qrarray(lines);
updateQRArray(qr_array);
clearHistory();
updateHistory("Load from image");
refreshTable();
changed_state = true;
};
reader.readAsText(this.files[0]);
}
})
$("#menu-new").click(function(){
if(changed_state){
if(!confirm("Are you sure want to proceed?\nYour unsaved progress will be lost!"))