2047pp - Workaround for the minifier removing the class definition

master
Martin Boonk 2023-01-14 21:55:07 +01:00
parent 705a5d7a1b
commit c5df6873c0
3 changed files with 131 additions and 128 deletions

View File

@ -1,4 +1,5 @@
class TwoK {
{ // wrap app in scope to prevent minifier from removing the class definition completely
class TwoK {
constructor() {
this.b = Array(4).fill().map(() => Array(4).fill(0));
this.score = 0;
@ -103,9 +104,9 @@ class TwoK {
while (this.b[Math.floor(id/4)][id%4] > 0) id = Math.floor(Math.random()*16);
this.b[Math.floor(id/4)][id%4] = d;
}
}
}
function dragHandler(e) {
function dragHandler(e) {
if (e.b && (Math.abs(e.dx)>7 || Math.abs(e.dy)>7)) {
var res = false;
if (Math.abs(e.dx)>Math.abs(e.dy)) {
@ -119,22 +120,23 @@ function dragHandler(e) {
if (res) twok.addDigit();
twok.render();
}
}
}
function swipeHandler() {
function swipeHandler() {
}
}
function buttonHandler() {
function buttonHandler() {
}
}
var twok = new TwoK();
twok.addDigit(); twok.addDigit();
twok.render();
if (process.env.HWVERSION==2) Bangle.on("drag", dragHandler);
if (process.env.HWVERSION==1) {
var twok = new TwoK();
twok.addDigit(); twok.addDigit();
twok.render();
if (process.env.HWVERSION==2) Bangle.on("drag", dragHandler);
if (process.env.HWVERSION==1) {
Bangle.on("swipe", (e) => { res = twok.shift(e); if (res) twok.addDigit(); twok.render(); });
setWatch(() => { res = twok.shift(2); if (res) twok.addDigit(); twok.render(); }, BTN1, {repeat: true});
setWatch(() => { res = twok.shift(-2); if (res) twok.addDigit(); twok.render(); }, BTN3, {repeat: true});
}
}

View File

@ -1,2 +1,3 @@
0.01: New app!
0.02: Better support for watch themes
0.03: Workaround minifier bug

View File

@ -2,7 +2,7 @@
"name": "2047pp",
"shortName":"2047pp",
"icon": "app.png",
"version":"0.02",
"version":"0.03",
"description": "Bangle version of a tile shifting game",
"supports" : ["BANGLEJS","BANGLEJS2"],
"allow_emulator": true,