mirror of https://github.com/espruino/BangleApps
swiping and hole stats
parent
394ffeb378
commit
29c3a5e62f
|
@ -1,12 +1,14 @@
|
|||
let course = require("Storage").readJSON("course_data(3).json");
|
||||
let hole = course;
|
||||
let current_hole = 1;
|
||||
let hole = course[current_hole.toString()];
|
||||
|
||||
function distance(a, b) {
|
||||
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2))
|
||||
return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
|
||||
}
|
||||
|
||||
function drawHole(l) {
|
||||
|
||||
console.log(l);
|
||||
//console.log(l);
|
||||
let hole_straight_distance = distance(
|
||||
hole.nodesXY[0],
|
||||
hole.nodesXY[hole.nodesXY.length - 1]
|
||||
|
@ -15,22 +17,24 @@ function drawHole(l) {
|
|||
let scale = 0.9 * l.h / hole_straight_distance;
|
||||
|
||||
let transform = {
|
||||
x: l.x + l.w / 2, // x offset (default 0)
|
||||
y: l.h * 0.95, // y offset (default 0)
|
||||
x: l.x + l.w / 2, // center in the box
|
||||
y: l.h * 0.95, // pad it just a bit
|
||||
scale: scale, // scale factor (default 1)
|
||||
rotate: hole.angle - Math.PI / 2.0, // angle in radians (default 0)
|
||||
}
|
||||
};
|
||||
|
||||
for (var feature of hole.features) {
|
||||
//console.log(Object.keys(feature));
|
||||
if (feature.type === "fairway") {
|
||||
g.setColor(0, 0, 1);
|
||||
g.setColor(1, 0, 1); // magenta
|
||||
} else if (feature.type === "tee") {
|
||||
g.setColor(1, 0, 0);
|
||||
g.setColor(1, 0, 0); // red
|
||||
} else if (feature.type === "green") {
|
||||
g.setColor(0, 1, 0);
|
||||
g.setColor(0, 1, 0); // green
|
||||
} else if (feature.type === "bunker") {
|
||||
g.setColor(1, 1, 0);
|
||||
g.setColor(1, 1, 0); // yellow
|
||||
} else if (feature.type === "water_hazard") {
|
||||
g.setColor(0, 0, 1); // blue
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
@ -54,7 +58,7 @@ function drawHole(l) {
|
|||
});
|
||||
|
||||
newnodelist = g.transformVertices(waynodelist, transform);
|
||||
g.setColor(0, 1, 1);
|
||||
g.setColor(0, 1, 1); // cyan
|
||||
g.drawPoly(newnodelist);
|
||||
}
|
||||
|
||||
|
@ -64,20 +68,38 @@ var layout = new Layout({
|
|||
type: "h", c: [
|
||||
{
|
||||
type: "v", c: [
|
||||
{ type: "txt", font: "10%", label: "Hole 1" },
|
||||
{ type: "txt", font: "10%", label: "Par 4" },
|
||||
{ type: "txt", font: "10%", label: "Hcp 15" },
|
||||
{ type: "txt", font: "35%", label: "420" },
|
||||
{ type: "txt", font: "20%", label: "69" },
|
||||
{ type: "txt", font: "10%", id: "hole", label: "Hole 1" },
|
||||
{ type: "txt", font: "10%", id: "par", label: "Par 4" },
|
||||
{ type: "txt", font: "10%", id: "hcp", label: "Hcp 15" },
|
||||
{ type: "txt", font: "35%", id: "postyardage", label: "420" },
|
||||
{ type: "txt", font: "20%", id: "measyardage", label: "69" },
|
||||
]
|
||||
},
|
||||
{ type: "custom", render: drawHole, id: "graph", bgCol: g.theme.bg, fillx: 1, filly: 1 }
|
||||
]
|
||||
],
|
||||
lazy: true
|
||||
});
|
||||
|
||||
console.log(g.getWidth());
|
||||
console.log(g.getHeight());
|
||||
|
||||
g.clear();
|
||||
layout.render();
|
||||
layout.debug();
|
||||
//layout.debug();
|
||||
|
||||
Bangle.on('swipe', function (direction) {
|
||||
if (direction > 0) {
|
||||
current_hole--;
|
||||
} else {
|
||||
current_hole++;
|
||||
}
|
||||
|
||||
if (current_hole > 18) { current_hole = 1; }
|
||||
if (current_hole < 1) { current_hole = 18; }
|
||||
hole = course[current_hole.toString()];
|
||||
|
||||
layout.hole.label = "Hole " + current_hole;
|
||||
layout.par.label = "Par " + course[current_hole.toString()].par;
|
||||
layout.hcp.label = "Hcp " + course[current_hole.toString()].handicap;
|
||||
layout.postyardage.label = 420; //TODO
|
||||
|
||||
g.clear();
|
||||
layout.render();
|
||||
});
|
Loading…
Reference in New Issue