diff --git a/apps.json b/apps.json index 8640433ee..70d0a8cf4 100644 --- a/apps.json +++ b/apps.json @@ -57,11 +57,12 @@ { "id": "golfscore", "name": "Golf Score", "shortName":"golfscore", - "version":"0.01", + "version":"0.02", "description": "keeps track of strokes during a golf game", "icon": "app.png", "tags": "outdoors", - "supports" : ["BANGLEJS2"], + "allow_emulator": true, + "supports" : ["BANGLEJS","BANGLEJS2"], "readme": "README.md", "storage": [ {"name":"golfscore.app.js","url":"app.js"}, diff --git a/apps/golfscore/ChangeLog b/apps/golfscore/ChangeLog index 5560f00bc..4995dd59a 100644 --- a/apps/golfscore/ChangeLog +++ b/apps/golfscore/ChangeLog @@ -1 +1,2 @@ 0.01: New App! +0.02: multiple player score support \ No newline at end of file diff --git a/apps/golfscore/README.md b/apps/golfscore/README.md index dc139bc9a..68552ad4b 100644 --- a/apps/golfscore/README.md +++ b/apps/golfscore/README.md @@ -1,25 +1,37 @@ -# App Name +# Golf Score -Describe the app... +Lets you keep track of strokes during a game of Golf. -Add screen shots (if possible) to the app folder and link then into this file with ![](.png) +![](mainmenu.png) +![](setupmenu.png) +![](scorecard.png) +![](holemenu.png) ## Usage -Describe how to use it +1. Open the app, +1. scroll to setup +2. set the number of holes (18 by default, but can be configured) +3. set the number of players (4 by default, but can be 1-20) +4. click back +5. scroll to a hole (hole 1) +6. scroll to a player and set the number of strokes they took (repeat as needed) +7. click next hole and repeat #6 and #7 as needed; or click back +8. at any time, check the score card for a sum total of all the strokes for each player ## Features -Name the function +Track strokes for multiple players (1-20) +Set number of holes on course ## Controls -Name the buttons and what they are used for +N/A ## Requests -Name who should be contacted for support/update requests +Michael Salaverry (github.com/barakplasma) ## Creator -Your name +Michael Salaverry diff --git a/apps/golfscore/app.js b/apps/golfscore/app.js index b971087ad..7c5c2d0e8 100644 --- a/apps/golfscore/app.js +++ b/apps/golfscore/app.js @@ -1,62 +1,113 @@ +// @ts-check +// @ts-ignore const menu = require("graphical_menu"); +/** + * @type {{showMenu: (config) => void}} + */ +let E; +/** + * @type {{clear: () => void}} + */ +let g; let holes_count = 18; -let course = new Array(holes_count).fill(0); -let total_strokes = 0; +let player_count = 4; +/** + * @type {number[][]} + */ +let course = new Array(holes_count).map(() => new Array(player_count).fill(0)); -const mainmenu = { +const main_menu = { "": { "title": "-- Golf --" }, + "Setup": function () { E.showMenu(setup_menu); }, + "Score Card": function () { + calculate_score(); + E.showMenu(score_card); + }, +}; + +function calculate_score() { + let scores = course.reduce((acc, hole) => { + hole.forEach((stroke_count, player) => { + acc[player] = acc[player]+stroke_count; + }); + return acc; + }, new Array(player_count).fill(0)); + + score_card = { + "": { + "title": "score card" + }, + "< Back": function () { E.showMenu(main_menu); }, + }; + + for (let player = 0; player < player_count; player++) { + score_card["Player - " + (player + 1)] = { + value: scores[player] + }; + } +} + +let score_card = {}; + +const setup_menu = { + "": { + "title": "-- Golf Setup --" + }, "Holes": { value: holes_count, min: 1, max: 20, step: 1, wrap: true, onchange: v => { holes_count = v; add_holes(); } }, - "Total Strokes": { - value: total_strokes, + "Players": { + value: player_count, + min: 1, max: 10, step: 1, wrap: true, + onchange: v => { player_count = v; } }, + "< Back": function () { E.showMenu(main_menu); }, }; -function updateTotalStrokes() { - total_strokes = course.reduce((acc, strokes) => acc + strokes, 0); - mainmenu["Total Strokes"].value = total_strokes; -} - -function inc_hole(i) { return function (v) { course[i] = v; updateTotalStrokes(); }; } +function inc_hole(i, player) { return function (v) { course[i][player] = v; }; } function add_holes() { - for (let j = 0; j < 100; j++) { - delete mainmenu["Hole - " + (j + 1)]; + for (let j = 0; j < 20; j++) { + delete main_menu["Hole - " + (j + 1)]; } for (let i = 0; i < holes_count; i++) { - course[i] = 0; - mainmenu["Hole - " + (i + 1)] = hole_menu(i); + course[i] = new Array(player_count).fill(0); + main_menu["Hole - " + (i + 1)] = goto_hole_menu(i); } - E.showMenu(mainmenu); + E.showMenu(main_menu); +} + +function goto_hole_menu(i) { + return function () { + E.showMenu(hole_menu(i)); + }; } function hole_menu(i) { - return function () { - E.showMenu(submenu(i)); - }; -} - -function submenu(i) { - return { + let menu = { "": { "title": `-- Hole ${i + 1}--` }, - "strokes:": { - value: course[i], - min: 1, max: 20, step: 1, wrap: true, - onchange: inc_hole(i) - }, - "Next hole": hole_menu(i + 1), - "< Back": function () { E.showMenu(mainmenu); }, + "Next hole": goto_hole_menu(i + 1), + "< Back": function () { E.showMenu(main_menu); }, }; + + for (let player = 0; player < player_count; player++) { + menu[`player - ${player + 1}`] = { + value: course[i][player], + min: 1, max: 20, step: 1, wrap: true, + onchange: inc_hole(i, player) + }; + } + + return menu; } +// @ts-ignore g.clear(); -add_holes(); -E.showMenu(mainmenu); \ No newline at end of file +add_holes(); \ No newline at end of file diff --git a/apps/golfscore/holemenu.png b/apps/golfscore/holemenu.png new file mode 100644 index 000000000..ac214f182 Binary files /dev/null and b/apps/golfscore/holemenu.png differ diff --git a/apps/golfscore/mainmenu.png b/apps/golfscore/mainmenu.png new file mode 100644 index 000000000..3ebeb0ca7 Binary files /dev/null and b/apps/golfscore/mainmenu.png differ diff --git a/apps/golfscore/scorecard.png b/apps/golfscore/scorecard.png new file mode 100644 index 000000000..9e7ff1130 Binary files /dev/null and b/apps/golfscore/scorecard.png differ diff --git a/apps/golfscore/setupmenu.png b/apps/golfscore/setupmenu.png new file mode 100644 index 000000000..13158e2e7 Binary files /dev/null and b/apps/golfscore/setupmenu.png differ diff --git a/apps/hebrew_calendar/ChangeLog b/apps/hebrew_calendar/ChangeLog index 8533c1df3..d7dbc19e3 100644 --- a/apps/hebrew_calendar/ChangeLog +++ b/apps/hebrew_calendar/ChangeLog @@ -1,4 +1,3 @@ 0.01: New App! 0.02: using TS and rollup to bundle -0.03: bug fixes and support bangle 1 -0.04: don't allow date to change & docs \ No newline at end of file +0.03: bug fixes and support bangle 1 \ No newline at end of file