Merge branch 'espruino:master' into master

pull/1628/head
GrandVizierOlaf 2022-03-27 15:43:40 -05:00 committed by GitHub
commit beec98e835
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 113 additions and 40 deletions

View File

@ -2,4 +2,5 @@
0.02: Temporary intermediate version
0.03: Basic colors
0.04: Bug fix score reset after Game Over, new icon
0.05: Chevron marker on the randomly added square
0.05: Chevron marker on the randomly added square
0.06: Fixed issue 1609 added a message popup state handler to control unwanted screen redraw

View File

@ -144,6 +144,13 @@ const buttons = {
},
add: function(btn) {
this.all.push(btn);
},
isPopUpActive: false,
activatePopUp: function() {
this.isPopUpActive = true;
},
deActivatePopUp: function() {
this.isPopUpActive = false;
}
};
/**
@ -253,7 +260,6 @@ const dragThreshold = 10;
const clickThreshold = 3;
let allSquares = [];
// let buttons = [];
class Button {
constructor(name, x0, y0, width, height, text, bg, fg, cb, enabled) {
@ -483,6 +489,7 @@ function initGame() {
Bangle.drawWidgets();
}
function drawPopUp(message,cb) {
buttons.activatePopUp();
g.setColor('#FFFFFF');
let rDims = Bangle.appRect;
g.fillPoly([rDims.x+10, rDims.y+20,
@ -505,6 +512,7 @@ function drawPopUp(message,cb) {
g.drawString(message, rDims.x+20, rDims.y+20);
buttons.add(btnYes);
buttons.add(btnNo);
}
function handlePopUpClicks(btn) {
const name = btn.name;
@ -512,6 +520,7 @@ function handlePopUpClicks(btn) {
buttons.all.pop(); // remove the yes button
buttons.all.forEach(b => {b.enable();}); // enable the remaining buttons again
debug(() => console.log("Button name =", name));
buttons.deActivatePopUp();
switch (name) {
case 'yes':
resetGame();
@ -568,14 +577,13 @@ function handleclick(e) {
// Handle a drag event (moving the stones around)
function handledrag(e) {
/*debug(Math.abs(e.dx) > Math.abs(e.dy) ?
(e.dx > 0 ? e => console.log('To the right') : e => console.log('To the left') ) :
(e.dy > 0 ? e => console.log('Move down') : e => console.log('Move up') ));
*/
// [move.right, move.left, move.up, move.down]
runGame((Math.abs(e.dx) > Math.abs(e.dy) ?
(e.dx > 0 ? mover.direction.right : mover.direction.left ) :
(e.dy > 0 ? mover.direction.down : mover.direction.up )));
// Stop moving things around when the popup message is active
// Bangleapps issue #1609
if (!(buttons.isPopUpActive)) {
runGame((Math.abs(e.dx) > Math.abs(e.dy) ?
(e.dx > 0 ? mover.direction.right : mover.direction.left ) :
(e.dy > 0 ? mover.direction.down : mover.direction.up )));
}
}
// Evaluate "drag" events from the UI and call handlers for drags or clicks
// The UI sends a drag as a series of events indicating partial movements

View File

@ -1,7 +1,7 @@
{ "id": "game1024",
"name": "1024 Game",
"shortName" : "1024 Game",
"version": "0.05",
"version": "0.06",
"icon": "game1024.png",
"screenshots": [ {"url":"screenshot.png" } ],
"readme":"README.md",

1
apps/gsat/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: Added Source Code

3
apps/gsat/README.md Normal file
View File

@ -0,0 +1,3 @@
# Geek Squad Appointment Timer
An app dedicated to setting a 20 minute timer for Geek Squad Appointments.

1
apps/gsat/app-icon.js Normal file
View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwwIdah/wAof//4ECgYFB4AFBg4FB8AFBj/wh/4AoM/wEB/gFBvwCEBAU/AQP4gfAj8AgPwAoMPwED8AFBg/AAYIBDA4ngg4TB4EBApkPKgJSBJQIFTMgIFCJIIFDKoIFEvgFBGoMAnw7DP4IFEh+BAoItBg+DNIQwBMIaeCKoKxCPoIzCEgKVHUIqtFXIrFFaIrdFdIwAV"))

38
apps/gsat/app.js Normal file
View File

@ -0,0 +1,38 @@
// Clear screen
g.clear();
const secsinmin = 60;
const quickfixperiod = 900;
var seconds = 1200;
function countSecs() {
if (seconds != 0) {seconds -=1;}
console.log(seconds);
}
function drawTime() {
g.clear();
g.setFontAlign(0,0);
g.setFont('Vector', 12);
g.drawString('Geek Squad Appointment Timer', 125, 20);
if (seconds == 0) {
g.setFont('Vector', 35);
g.drawString('Appointment', 125, 100);
g.drawString('finished!', 125, 150);
Bangle.buzz();
return;
}
min = seconds / secsinmin;
if (seconds < quickfixperiod) {
g.setFont('Vector', 20);
g.drawString('Quick Fix', 125, 50);
g.drawString('Period Passed!', 125, 75);
}
g.setFont('Vector', 50);
g.drawString(Math.ceil(min), 125, 125);
g.setFont('Vector', 25);
g.drawString('minutes', 125, 165);
g.drawString('remaining', 125, 195);
}
drawTime();
setInterval(countSecs, 1000);
setInterval(drawTime, 60000);

BIN
apps/gsat/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 929 B

16
apps/gsat/metadata.json Normal file
View File

@ -0,0 +1,16 @@
{
"id": "gsat",
"name": "Geek Squad Appointment Timer",
"shortName": "gsat",
"version": "0.01",
"description": "Starts a 20 minute timer for appointments at Geek Squad.",
"icon": "app.png",
"tags": "tool",
"readme": "README.md",
"supports": ["BANGLEJS"],
"screenshots": [{"url":"screenshot.png"}],
"storage": [
{"name":"gsat.app.js","url":"app.js"},
{"name":"gsat.img","url":"app-icon.js","evaluate":true}
]
}

BIN
apps/gsat/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,2 @@
0.01: New app!
0.02: Make Bangle.js 2 compatible

View File

@ -24,7 +24,7 @@ need to travel in to reach the selected waypoint. The blue text is
the name of the current waypoint. NONE means that there is no
waypoint set and so bearing and distance will remain at 0. To select
a waypoint, press BTN2 (middle) and wait for the blue text to turn
white. Then use BTN1 and BTN3 to select a waypoint. The waypoint
white. Then use BTN1 and BTN3 (swipe up/down on Bangle.js 2) to select a waypoint. The waypoint
choice is fixed by pressing BTN2 again. In the screen shot below a
waypoint giving the location of Stone Henge has been selected.

View File

@ -1,24 +1,25 @@
var pal_by = new Uint16Array([0x0000,0xFFC0],0,1); // black, yellow
var pal_bw = new Uint16Array([0x0000,0xffff],0,1); // black, white
var pal_bb = new Uint16Array([0x0000,0x07ff],0,1); // black, blue
const scale = g.getWidth()/240;
var pal_by = new Uint16Array([g.getBgColor(),0xFFC0],0,1); // black, yellow
var pal_bw = new Uint16Array([g.getBgColor(),g.getColor()],0,1); // black, white
var pal_bb = new Uint16Array([g.getBgColor(),0x07ff],0,1); // black, blue
// having 3 2 color pallette keeps the memory requirement lower
var buf1 = Graphics.createArrayBuffer(160,160,1, {msb:true});
var buf2 = Graphics.createArrayBuffer(80,40,1, {msb:true});
var buf1 = Graphics.createArrayBuffer(160*scale,160*scale,1, {msb:true});
var buf2 = Graphics.createArrayBuffer(g.getWidth()/3,40*scale,1, {msb:true});
var arrow_img = require("heatshrink").decompress(atob("lEowIPMjAEDngEDvwED/4DCgP/wAEBgf/4AEBg//8AEBh//+AEBj///AEBn///gEBv///wmCAAImCAAIoBFggE/AkaaEABo="));
function flip1(x,y) {
g.drawImage({width:160,height:160,bpp:1,buffer:buf1.buffer, palette:pal_by},x,y);
g.drawImage({width:160*scale,height:160*scale,bpp:1,buffer:buf1.buffer, palette:pal_by},x,y);
buf1.clear();
}
function flip2_bw(x,y) {
g.drawImage({width:80,height:40,bpp:1,buffer:buf2.buffer, palette:pal_bw},x,y);
g.drawImage({width:g.getWidth()/3,height:40*scale,bpp:1,buffer:buf2.buffer, palette:pal_bw},x,y);
buf2.clear();
}
function flip2_bb(x,y) {
g.drawImage({width:80,height:40,bpp:1,buffer:buf2.buffer, palette:pal_bb},x,y);
g.drawImage({width:g.getWidth()/3,height:40*scale,bpp:1,buffer:buf2.buffer, palette:pal_bb},x,y);
buf2.clear();
}
@ -51,12 +52,12 @@ function drawCompass(course) {
previous.course = course;
buf1.setColor(1);
buf1.fillCircle(80,80,79,79);
buf1.fillCircle(buf1.getWidth()/2,buf1.getHeight()/2,79*scale);
buf1.setColor(0);
buf1.fillCircle(80,80,69,69);
buf1.fillCircle(buf1.getWidth()/2,buf1.getHeight()/2,69*scale);
buf1.setColor(1);
buf1.drawImage(arrow_img, 80, 80, {scale:3, rotate:radians(course)} );
flip1(40, 30);
buf1.drawImage(arrow_img, buf1.getWidth()/2, buf1.getHeight()/2, {scale:3*scale, rotate:radians(course)} );
flip1(40*scale, Bangle.appRect.y+6*scale);
}
/***** COMPASS CODE ***********/
@ -138,7 +139,7 @@ function distance(a,b){
function drawN(){
buf2.setFont("Vector",24);
buf2.setFont("Vector",24*scale);
var bs = wp_bearing.toString();
bs = wp_bearing<10?"00"+bs : wp_bearing<100 ?"0"+bs : bs;
var dst = loc.distance(dist);
@ -147,12 +148,12 @@ function drawN(){
// show distance on the left
if (previous.dst !== dst) {
previous.dst = dst
previous.dst = dst;
buf2.setColor(1);
buf2.setFontAlign(-1,-1);
buf2.setFont("Vector", 20);
buf2.setFont("Vector", 20*scale);
buf2.drawString(dst,0,0);
flip2_bw(0, 200);
flip2_bw(0, g.getHeight()-40*scale);
}
// bearing, place in middle at bottom of compass
@ -160,9 +161,9 @@ function drawN(){
previous.bs = bs;
buf2.setColor(1);
buf2.setFontAlign(0, -1);
buf2.setFont("Vector",38);
buf2.drawString(bs,40,0);
flip2_bw(80, 200);
buf2.setFont("Vector",38*scale);
buf2.drawString(bs,40*scale,0);
flip2_bw(g.getWidth()/3, g.getHeight()-40*scale);
}
// waypoint name on right
@ -170,13 +171,13 @@ function drawN(){
previous.selected = selected;
buf2.setColor(1);
buf2.setFontAlign(1,-1); // right, bottom
buf2.setFont("Vector", 20);
buf2.drawString(wp.name, 80, 0);
buf2.setFont("Vector", 20*scale);
buf2.drawString(wp.name, 80*scale, 0);
if (selected)
flip2_bw(160, 200);
flip2_bw(g.getWidth()/3*2, g.getHeight()-40*scale);
else
flip2_bb(160, 200);
flip2_bb(g.getWidth()/3*2, g.getHeight()-40*scale);
}
}
@ -229,9 +230,11 @@ function startdraw(){
}
function setButtons(){
setWatch(nextwp.bind(null,-1), BTN1, {repeat:true,edge:"falling"});
setWatch(doselect, BTN2, {repeat:true,edge:"falling"});
setWatch(nextwp.bind(null,1), BTN3, {repeat:true,edge:"falling"});
Bangle.setUI("updown", d=>{
if (d<0) { nextwp(-1); }
else if (d>0) { nextwp(1); }
else { doselect(); }
});
}
Bangle.on('lcdPower',function(on) {

View File

@ -1,11 +1,11 @@
{
"id": "waypointer",
"name": "Way Pointer",
"version": "0.01",
"version": "0.02",
"description": "Navigate to a waypoint using the GPS for bearing and compass to point way, uses the same waypoint interface as GPS Navigation",
"icon": "waypointer.png",
"tags": "tool,outdoors,gps",
"supports": ["BANGLEJS"],
"supports": ["BANGLEJS", "BANGLEJS2"],
"readme": "README.md",
"interface": "waypoints.html",
"storage": [