From e71e7db333d68f462ba2ccb6a36ef7fb728f7a49 Mon Sep 17 00:00:00 2001 From: ASL97 Date: Sun, 10 Dec 2023 07:20:30 +0800 Subject: [PATCH] Add QuaggaJS for scanner function and implement card loader/viewer --- index.html | 128 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 120 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index f5841c2..efbb8c2 100644 --- a/index.html +++ b/index.html @@ -240,9 +240,24 @@

Card Printer

- -
- +
+
+ +
+ +
+
+ + + +
+
+ + +
+
+
+
@@ -819,6 +834,13 @@

Batch Card Printer

} serializer = { + formats : [ + [/^cs(\d+)-(\d+)$/gi, (match)=>{ + let arr = this.randomize_array(match[2], parseInt(match[1])); + return arr.slice(0, 25); + }] + ], + to_arrays: function (c){return function* _(){ for (let row of c.getElementsByClassName('table_row')){ yield function* (r){ @@ -855,10 +877,18 @@

Batch Card Printer

}, from_card_id: (card_id)=>{ - alert(card_id.split(/(?:\s+)/).length); - if (card_id.startsWith("CS-")){ - // TODO - } else if (card_id.split(/(?:\s+)/).length == this.slots) { + for (let [format_regex, func] of this.serializer.formats){ + if (format_regex.test(card_id)){ + // reset regex + format_regex.lastIndex = 0; + for (let id of card_id.matchAll(format_regex)){ + // there should only be 1 id + return func(id); + } + } + } + + if (card_id.split(/(?:\s+)/).length == this.slots) { // number of numbers match expected bingo card // for support of using google len or OCR to load physical card alert(card_id); @@ -1818,10 +1848,43 @@

Batch Card Printer

this.init_ui(); } + display_card(arr){ + // TODO: support other cards type, for now assume 5x5 + let flipped = document.getElementById('loader_flip_card').checked; + arr = arr.slice(0,25); + if (flipped){ + arr = this.bingo.cards.arr_2d_flip(arr, 5); + } + + let card = this.bingo.cards.generate_card(arr); + for (let span of card.getElementsByTagName('span')){ + span.onclick = ()=>{}; + } + this.bingo.cards.mark_rolled_number(card); + + card.style.height = 'min(50vh,50vw)'; + card.style.width = 'min(50vh,50vw)'; + card.style['font-size'] = 'min(5vh, 5vw)' + + let loader_card = document.getElementById('loader_card'); + loader_card.innerHTML = card.outerHTML; + } + init_ui(){ let loader_button = document.getElementById("loader_button"); loader_button.onclick = ()=>{ - this.bingo.cards.serializer.from_card_id(document.getElementById("card_loader").value); + let arr = this.bingo.cards.serializer.from_card_id(document.getElementById("card_loader").value); + this.display_card(arr) + } + + let start_scanner_button = document.getElementById("start_scanner_button"); + start_scanner_button.onclick = ()=>{ + start_barcode_scanner(); + } + + let stop_scanner_button = document.getElementById("stop_scanner_button"); + stop_scanner_button.onclick = ()=>{ + stop_barcode_scanner(); } } } @@ -1831,6 +1894,55 @@

Batch Card Printer

navigator.serviceWorker.register("sw-offline.js"); } + +