mirror of https://github.com/espruino/BangleApps
initial commit of counter2 app
parent
31d24d77d0
commit
b72de7fb04
|
@ -0,0 +1,2 @@
|
|||
0.01: New App!
|
||||
0.02: Added Settings & readme
|
|
@ -0,0 +1,24 @@
|
|||
# Counter2 by Michael
|
||||
|
||||
I needed an HP/XP-Tracker for a game, so i made one.
|
||||
The counter state gets saved. Best to use this with pattern launcher or ClockCal
|
||||
|
||||
- Colored Text Mode
|
||||
- 
|
||||
- Colored Background Mode
|
||||
- 
|
||||
|
||||
## Howto
|
||||
- Tap top side or swipe up to increase counter
|
||||
- Tap top side or swipe down to decrease counter
|
||||
- Hold (600ms) to reset to default value (configurable)
|
||||
- Press button to exit
|
||||
|
||||
## Configurable Features
|
||||
- Default value Counter 1
|
||||
- Default value Counter 2
|
||||
- Buzz on interact
|
||||
- Colored Text/Background
|
||||
|
||||
## Feedback
|
||||
If something isn't working, please tell me: https://github.com/Stuff-etc/BangleApps/issues
|
|
@ -0,0 +1 @@
|
|||
require("heatshrink").decompress(atob("mEwwcAyVJkgCFAwwCBAgd5CI+eCI2T/IRH/wR7n//AAPyCIdPBAX8CKpr/CLTpSCOipB8gRFXoPJCIknCJAIBOoYRCagLNCa4f8Q4gREI4tP8mT/41HCKJHFGoQRG+QKBLI4RHLIx9CCJ7zBGpxZCPoyhQYpIIBYor7kCP4R8YoX/WY69DAIM/BAT+BdIYICeYQRTGqKP/CNIA=="))
|
|
@ -0,0 +1,96 @@
|
|||
Bangle.loadWidgets();
|
||||
|
||||
var s = Object.assign({
|
||||
counter0:10,
|
||||
counter1:20,
|
||||
max0:15,
|
||||
max1:25,
|
||||
buzz: true,
|
||||
colortext: true,
|
||||
}, require('Storage').readJSON("counter2.json", true) || {});
|
||||
|
||||
f1 = (s.colortext) ? "#f00" : "#fff";
|
||||
f2 = (s.colortext) ? "#00f" : "#fff";
|
||||
b1 = (s.colortext) ? "#000" : "#f00";
|
||||
b2 = (s.colortext) ? "#000" : "#00f";
|
||||
|
||||
var counter = 0;
|
||||
var drag;
|
||||
|
||||
screenwidth = g.getWidth();
|
||||
screenheight = g.getHeight();
|
||||
halfwidth = screenwidth / 2;
|
||||
halfheight = screenheight / 2;
|
||||
|
||||
counter = [];
|
||||
counter[0] = s.counter0;
|
||||
counter[1] = s.counter1;
|
||||
defaults = [];
|
||||
defaults[0] = s.max0;
|
||||
defaults[1] = s.max1;
|
||||
|
||||
function saveSettings() {
|
||||
s.counter0 = counter[0];
|
||||
s.counter1 = counter[1];
|
||||
s.max0 = defaults[0];
|
||||
s.max1 = defaults[1];
|
||||
require('Storage').writeJSON("counter2.json", s);
|
||||
}
|
||||
|
||||
ignoreonce = false;
|
||||
var dragtimeout;
|
||||
|
||||
function updateScreen() {
|
||||
g.setBgColor(b1);
|
||||
g.clearRect(0, 0, halfwidth, screenheight);
|
||||
g.setBgColor(b2);
|
||||
g.clearRect(halfwidth, 0, screenwidth, screenheight);
|
||||
g.setFont("Vector", 60).setFontAlign(0, 0);
|
||||
g.setColor(f1);
|
||||
g.drawString(Math.floor(counter[0]), halfwidth * 0.5, halfheight);
|
||||
g.setColor(f2);
|
||||
g.drawString(Math.floor(counter[1]), halfwidth * 1.5, halfheight);
|
||||
saveSettings();
|
||||
if (s.buzz) Bangle.buzz(50,.5);
|
||||
Bangle.drawWidgets();
|
||||
}
|
||||
|
||||
Bangle.on("drag", e => {
|
||||
c = (e.x < halfwidth) ? 0 : 1;
|
||||
if (!drag) {
|
||||
if (ignoreonce) {
|
||||
ignoreonce = false;
|
||||
return;
|
||||
}
|
||||
drag = { x: e.x, y: e.y };
|
||||
dragtimeout = setTimeout(function () { resetcounter(c); }, 600); //if dragging for 500ms, reset counter
|
||||
}
|
||||
else if (drag && !e.b) { // released
|
||||
adjust = 0;
|
||||
const dx = e.x - drag.x, dy = e.y - drag.y;
|
||||
if (Math.abs(dy) > Math.abs(dx) + 30) {
|
||||
adjust = (dy > 0) ? -1 : 1;
|
||||
} else {
|
||||
adjust = (e.y > halfwidth) ? -1 : 1;
|
||||
}
|
||||
counter[c] += adjust;
|
||||
updateScreen();
|
||||
drag = undefined;
|
||||
clearTimeout(dragtimeout);
|
||||
}
|
||||
});
|
||||
|
||||
function resetcounter(which) {
|
||||
counter[which] = defaults[which];
|
||||
console.log("resetting counter ", which);
|
||||
updateScreen();
|
||||
drag = undefined;
|
||||
ignoreonce = true;
|
||||
}
|
||||
|
||||
|
||||
updateScreen();
|
||||
|
||||
setWatch(function() {
|
||||
load();
|
||||
}, BTN1, {repeat:true, edge:"falling"});
|
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"id": "counter2",
|
||||
"name": "Counter2",
|
||||
"version": "0.01",
|
||||
"description": "Dual Counter",
|
||||
"icon": "counter2-icon.png",
|
||||
"tags": "tool",
|
||||
"supports": ["BANGLEJS2"],
|
||||
"screenshots": [{"url":"counter2-screenshot.png"}],
|
||||
"allow_emulator": true,
|
||||
"storage": [
|
||||
{"name":"counter2.app.js","url":"app.js"},
|
||||
{"name":"counter2.settings.js","url":"settings.js"},
|
||||
{"name":"counter2.img","url":"app-icon.js","evaluate":true}
|
||||
],
|
||||
"data": [{"name":"counter2.json"}]
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
(function (back) {
|
||||
var FILE = "counter2.json";
|
||||
defaults={
|
||||
counter0:12,
|
||||
counter1:0,
|
||||
max0:12,
|
||||
max1:0,
|
||||
buzz: true,
|
||||
colortext: true,
|
||||
};
|
||||
settings = Object.assign(defaults, require('Storage').readJSON(FILE, true) || {});
|
||||
|
||||
function writeSettings() {
|
||||
require('Storage').writeJSON(FILE, settings);
|
||||
}
|
||||
|
||||
menu = {
|
||||
"": { "title": "Counter2" },
|
||||
"< Back": () => back(),
|
||||
'Default C1': {
|
||||
value: settings[0],
|
||||
min: -99, max: 99,
|
||||
onchange: v => {
|
||||
settings.max0 = v;
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
'Default C2': {
|
||||
value: settings[2],
|
||||
min: -99, max: 99,
|
||||
onchange: v => {
|
||||
settings.max1 = v;
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
'Color Text': {
|
||||
value: settings[colortext],
|
||||
format: v => v?"Text":"Background",
|
||||
onchange: v => {
|
||||
settings.colortext = v;
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
'Buzz': {
|
||||
value: settings.buzz,
|
||||
format: v => v?"On":"Off",
|
||||
onchange: v => {
|
||||
settings.buzz = v;
|
||||
writeSettings();
|
||||
}
|
||||
}
|
||||
};
|
||||
// Show the menu
|
||||
E.showMenu(menu);
|
||||
});
|
Loading…
Reference in New Issue