Merge pull request #3835 from bobrippling/feat/score-fixes-and-squash
score: fix bangle 2 compat and add squash presetmaster
commit
711c46c5f6
|
|
@ -1,3 +1,4 @@
|
|||
0.01: New App!
|
||||
0.02: Minor code improvements
|
||||
0.03: Bug fixes and some usability and performance improvements
|
||||
0.04: Add squash preset, simplify logic, fix compatibility with BangleJS 2
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ In this mode any score increments will be decrements. To move back a set, reduce
|
|||
| `Sets per page` | How many sets should be shown in the app. Further sets will be available by scrolling (ignored if higher than `Sets to win`) |
|
||||
| `Score to win` | What score ends a given set |
|
||||
| `2-point lead` | Does winning a set require a two-point lead |
|
||||
| `Maximum score?` | Should there be a maximum score, at which point the two-point lead rule falls away |
|
||||
| `Maximum score` | At which score should the two-point lead rule fall away (ignored if lower than Sets to win) |
|
||||
| `Maximum score` | Should there be a maximum score, at which point the two-point lead rule falls away (ignored if lower than Sets to win) |
|
||||
| `Tennis scoring` | If enabled, each point in a set will require a full tennis game |
|
||||
| `TB sets?` | Should sets that have reached `(maxScore-1):(maxScore-1)` be decided with a tiebreak |
|
||||
| All other options starting with TB | Equivalent to option with same name but applied to tiebreaks |
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "score",
|
||||
"name": "Score Tracker",
|
||||
"version": "0.03",
|
||||
"version": "0.04",
|
||||
"description": "Score Tracker for sports that use plain numbers (e.g. Badminton, Volleyball, Soccer, Table Tennis, ...). Also supports tennis scoring.",
|
||||
"icon": "score.app.png",
|
||||
"screenshots": [{"url":"screenshot_score.png"}],
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@ require('Font5x9Numeric7Seg').add(Graphics);
|
|||
require('Font7x11Numeric7Seg').add(Graphics);
|
||||
require('FontTeletext5x9Ascii').add(Graphics);
|
||||
|
||||
const KEY_SCORE_L = 0;
|
||||
const KEY_SCORE_R = 1;
|
||||
const KEY_MENU = 2;
|
||||
const KEY_TENNIS_H = 3;
|
||||
const KEY_TENNIS_L = 4;
|
||||
|
||||
let settingsMenu = eval(require('Storage').read('score.settings.js'));
|
||||
let settings = settingsMenu(null, null, true);
|
||||
|
||||
|
|
@ -44,39 +50,49 @@ function setupDisplay() {
|
|||
}
|
||||
|
||||
function setupInputWatchers(init) {
|
||||
Bangle.setUI('updown', v => {
|
||||
Bangle.setUI('updown',
|
||||
isBangle1
|
||||
? (v => {
|
||||
if (v) {
|
||||
if (isBangle1) {
|
||||
let i = settings.mirrorScoreButtons ? v : v * -1;
|
||||
handleInput(Math.floor((i+2)/2));
|
||||
} else {
|
||||
}
|
||||
})
|
||||
: (v => {
|
||||
if (v) {
|
||||
// +1 -> 4
|
||||
// -1 -> 3
|
||||
handleInput(Math.floor((v+2)/2)+3);
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
if (init) {
|
||||
if (isBangle1) {
|
||||
setWatch(() => handleInput(2), BTN2, { repeat: true });
|
||||
}
|
||||
Bangle.on('touch', (b, e) => {
|
||||
if (isBangle1) {
|
||||
setWatch(
|
||||
() => handleInput(KEY_MENU),
|
||||
isBangle1 ? BTN2 : BTN,
|
||||
{ repeat: true },
|
||||
);
|
||||
Bangle.on('touch',
|
||||
isBangle1
|
||||
? ((b, e) => {
|
||||
if (b === 1) {
|
||||
handleInput(3);
|
||||
handleInput(KEY_TENNIS_H);
|
||||
} else {
|
||||
handleInput(4);
|
||||
handleInput(KEY_TENNIS_L);
|
||||
}
|
||||
} else {
|
||||
})
|
||||
: ((b, e) => {
|
||||
if (e.y > 18) {
|
||||
if (e.x < getXCoord(w => w/2)) {
|
||||
handleInput(0);
|
||||
handleInput(KEY_SCORE_L);
|
||||
} else {
|
||||
handleInput(1);
|
||||
handleInput(KEY_SCORE_R);
|
||||
}
|
||||
} else {
|
||||
// long press except if we have the menu opened or we are in the emulator (that doesn't
|
||||
// seem to support long press events)
|
||||
if (e.type === 2 || settingsMenuOpened || process.env.BOARD === 'EMSCRIPTEN2') {
|
||||
handleInput(2);
|
||||
handleInput(KEY_MENU);
|
||||
} else {
|
||||
let p = null;
|
||||
|
||||
|
|
@ -97,8 +113,8 @@ function setupInputWatchers(init) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -137,14 +153,13 @@ function showSettingsMenu() {
|
|||
if (reset) {
|
||||
setupMatch();
|
||||
}
|
||||
if (isBangle1 || (!isBangle1 && back)) {
|
||||
|
||||
settingsMenuOpened = null;
|
||||
|
||||
draw();
|
||||
|
||||
setupDisplay();
|
||||
setupInputWatchers();
|
||||
}
|
||||
}, function (msg) {
|
||||
switch (msg) {
|
||||
case 'end_set':
|
||||
|
|
@ -344,7 +359,7 @@ function handleInput(button) {
|
|||
// console.log('button:', button);
|
||||
if (settingsMenuOpened) {
|
||||
|
||||
if (!isBangle1 && button == 2) {
|
||||
if (!isBangle1 && button == KEY_MENU) { // Bangle2 long press, hide menu
|
||||
E.showMenu();
|
||||
|
||||
settingsMenuOpened = null;
|
||||
|
|
@ -359,15 +374,15 @@ function handleInput(button) {
|
|||
}
|
||||
|
||||
switch (button) {
|
||||
case 0:
|
||||
case 1:
|
||||
case KEY_SCORE_L:
|
||||
case KEY_SCORE_R:
|
||||
score(button);
|
||||
break;
|
||||
case 2:
|
||||
case KEY_MENU:
|
||||
showSettingsMenu();
|
||||
return;
|
||||
case 3:
|
||||
case 4: {
|
||||
case KEY_TENNIS_H:
|
||||
case KEY_TENNIS_L: {
|
||||
let hLimit = currentSet() - setsPerPage() + 1;
|
||||
let lLimit = 0;
|
||||
let val = (button * 2 - 7);
|
||||
|
|
@ -382,8 +397,7 @@ function handleInput(button) {
|
|||
}
|
||||
|
||||
function draw() {
|
||||
g.setFontAlign(0,0);
|
||||
g.clear();
|
||||
g.reset().setFontAlign(0,0).clear();
|
||||
|
||||
for (let p = 0; p < 2; p++) {
|
||||
if (matchWon(p)) {
|
||||
|
|
|
|||
|
|
@ -26,5 +26,10 @@
|
|||
"winScore": 11,
|
||||
"enableTwoAhead": true,
|
||||
"enableMaxScore": false
|
||||
},
|
||||
"Squash": {
|
||||
"winScore": 9,
|
||||
"enableTwoAhead": true,
|
||||
"enableMaxScore": false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,52 +1,28 @@
|
|||
(function () {
|
||||
return (function (back, inApp, ret) {
|
||||
(function (back, inApp, ret) {
|
||||
const isBangle1 = process.env.BOARD === 'BANGLEJS'
|
||||
|
||||
function fillSettingsWithDefaults(settings) {
|
||||
if (isBangle1) {
|
||||
if (settings.mirrorScoreButtons == null) {
|
||||
settings.mirrorScoreButtons = false;
|
||||
}
|
||||
if (settings.keepDisplayOn == null) {
|
||||
settings.keepDisplayOn = true;
|
||||
}
|
||||
}
|
||||
if (settings.winSets == null) {
|
||||
settings.winSets = 2;
|
||||
}
|
||||
if (settings.setsPerPage == null) {
|
||||
settings.setsPerPage = 5;
|
||||
}
|
||||
if (settings.winScore == null) {
|
||||
settings.winScore = 21;
|
||||
}
|
||||
if (settings.enableTwoAhead == null) {
|
||||
settings.enableTwoAhead = true;
|
||||
}
|
||||
if (settings.enableMaxScore == null) {
|
||||
settings.enableMaxScore = true;
|
||||
}
|
||||
if (settings.maxScore == null) {
|
||||
settings.maxScore = 30;
|
||||
}
|
||||
if (settings.enableTennisScoring == null) {
|
||||
settings.enableTennisScoring = false;
|
||||
}
|
||||
settings = Object.assign({
|
||||
winSets: 2,
|
||||
setsPerPage: 5,
|
||||
winScore: 21,
|
||||
enableTwoAhead: true,
|
||||
enableMaxScore: true,
|
||||
maxScore: 30,
|
||||
enableTennisScoring: false,
|
||||
|
||||
if (settings.enableMaxScoreTiebreak == null) {
|
||||
settings.enableMaxScoreTiebreak = false;
|
||||
}
|
||||
if (settings.maxScoreTiebreakWinScore == null) {
|
||||
settings.maxScoreTiebreakWinScore = 6;
|
||||
}
|
||||
if (settings.maxScoreTiebreakEnableTwoAhead == null) {
|
||||
settings.maxScoreTiebreakEnableTwoAhead = true;
|
||||
}
|
||||
if (settings.maxScoreTiebreakEnableMaxScore == null) {
|
||||
settings.maxScoreTiebreakEnableMaxScore = false;
|
||||
}
|
||||
if (settings.maxScoreTiebreakMaxScore == null) {
|
||||
settings.maxScoreTiebreakMaxScore = 15;
|
||||
enableMaxScoreTiebreak: false,
|
||||
maxScoreTiebreakWinScore: 6,
|
||||
maxScoreTiebreakEnableTwoAhead: true,
|
||||
maxScoreTiebreakEnableMaxScore: false,
|
||||
maxScoreTiebreakMaxScore: 15,
|
||||
}, settings);
|
||||
|
||||
if (isBangle1) {
|
||||
settings = Object.assign({
|
||||
mirrorScoreButtons: false,
|
||||
keepDisplayOn: true,
|
||||
}, settings);
|
||||
}
|
||||
|
||||
return settings;
|
||||
|
|
@ -198,10 +174,10 @@
|
|||
const inAppMenu = function () {
|
||||
let m = {
|
||||
'': {'title': 'Score Menu'},
|
||||
'< Back': function () { back(settings, changed, false); },
|
||||
'Correct mode': function () { inApp('correct_mode'); back(settings, false, true); },
|
||||
'Reset match': function () { back(settings, true, true); },
|
||||
'End current set': function () { inApp('end_set'); back(settings, changed, true); },
|
||||
'< Back': function () { back(settings, changed); },
|
||||
'Correct mode': function () { inApp('correct_mode'); back(settings, false); },
|
||||
'Reset match': function () { back(settings, true); },
|
||||
'End current set': function () { inApp('end_set'); back(settings, changed); },
|
||||
'Configuration': function () { E.showMenu(appMenu(function () {
|
||||
E.showMenu(inAppMenu());
|
||||
})); },
|
||||
|
|
@ -215,6 +191,4 @@
|
|||
} else {
|
||||
E.showMenu(appMenu(back));
|
||||
}
|
||||
|
||||
});
|
||||
})()
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue