Skip to content

Commit

Permalink
Release version 4.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
matco committed Nov 6, 2023
2 parents 0dbc024 + 84bdcdd commit dba1f63
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 106 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 4.3.0
- Add support for Vivoactive 5
- Drop support for Vivoactive 3
- Fix icons size

## 4.2.0
- Animate the court
- Add support for Venu 3 series
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Badminton

Badminton is an application for Garmin watches that will help you to track your score when you're playing badminton.
Badminton is an application for Garmin watches that will help you track your score when you're playing badminton.

It is available on the Garmin store here:
[https://apps.garmin.com/en-US/apps/51606451-57e2-4f99-9420-2ba5a80b5df6](https://apps.garmin.com/en-US/apps/51606451-57e2-4f99-9420-2ba5a80b5df6).

## Features

Here are the best features of the app:
- Choose type of match (double or single)
- Choose number of sets
- Choose which player has service (you, opponent, or random)
- Choose the type of match (double or single)
- Choose a number of sets
- Choose which player has service (you, your opponent, or random)
- Display the boundaries of the court according to the type of match
- Show the service corners and your position
- Display match duration
- Declares the winner of the match
- Use menu (long press on "Up") to reset scores and start a new match
- Use the menu (long press on "Up") to reset scores and start a new match
- Save matches as Garmin Connect activities

## Installation
Expand Down
2 changes: 1 addition & 1 deletion manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
<iq:product id="venusq2"/>
<iq:product id="venusq2m"/>
<iq:product id="venusqm"/>
<iq:product id="vivoactive3"/>
<iq:product id="vivoactive3m"/>
<iq:product id="vivoactive3mlte"/>
<iq:product id="vivoactive4"/>
<iq:product id="vivoactive4s"/>
<iq:product id="vivoactive5"/>
</iq:products>
<iq:permissions>
<iq:uses-permission id="Fit"/>
Expand Down
5 changes: 4 additions & 1 deletion monkey.jungle
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ venusq.resourcePath = resources;icons/36x36
venusqm.resourcePath = resources;icons/36x36
venu2.resourcePath = resources;icons/70x70
venu2s.resourcePath = resources;icons/61x61
venu2plus.resourcePath = resources;icons/70x70
venu3.resourcePath = resources;icons/70x70
venu3s.resourcePath = resources;icons/70x70

vivoactive3.resourcePath = resources;icons/40x33
vivoactive3m.resourcePath = resources;icons/40x33
vivoactive3mlte.resourcePath = resources;icons/40x33

vivoactive4.resourcePath = resources;icons/35x35
vivoactive4s.resourcePath = resources;icons/30x30

vivoactive5.resourcePath = resources;icons/70x70

fenix5s.resourcePath = resources;icons/36x36

epix2.resourcePath = resources;icons/60x60
epix2pro51mm.resourcePath = resources;icons/60x60
epix2pro47mm.resourcePath = resources;icons/60x60
epix2pro42mm.resourcePath = resources;icons/60x60
Expand Down
4 changes: 2 additions & 2 deletions source/BadmintonApp.mc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BadmintonApp extends Application.AppBase {
return BUS;
}

function getMatch() as Match {
function getMatch() as Match? {
return match;
}

Expand All @@ -46,7 +46,7 @@ class BadmintonApp extends Application.AppBase {
}
}

function onMatchEnd(payload) as Void {
function onMatchEnd(payload as Dictionary) as Void {
var winner = payload["winner"];
if(winner != null && Attention has :playTone && Properties.getValue("enable_sound")) {
Attention.playTone(winner == YOU ? Attention.TONE_SUCCESS : Attention.TONE_FAILURE);
Expand Down
2 changes: 1 addition & 1 deletion source/MenuDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MatchMenuDelegate extends WatchUi.Menu2InputDelegate {

function onSelect(item as MenuItem) {
var id = item.getId();
var match = (Application.getApp() as BadmintonApp).getMatch();
var match = (Application.getApp() as BadmintonApp).getMatch() as Match;
if(id == :menu_end_game) {
match.end(null);
//pop once to close the menu
Expand Down
10 changes: 5 additions & 5 deletions source/UIHelpers.mc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module UIHelpers {

//for now consider all drawables are labels and are justified
//improve this as soon as a method getJustification exists
function findTappedDrawable(event as ClickEvent, drawables as Array<Drawable>) as Drawable {
function findTappedDrawable(event as ClickEvent, drawables as Array<Drawable>) as Drawable? {
var coordinate = event.getCoordinates();
var event_x = coordinate[0];
var event_y = coordinate[1];
Expand All @@ -28,8 +28,8 @@ module UIHelpers {
}
}
//second loop to find closest drawable
var closest_distance = null as Float;
var closest_drawable = null;
var closest_distance = null as Float?;
var closest_drawable = null as Drawable?;
for(var i = 0; i < drawables.size(); i++) {
var drawable = drawables[i];
var drawable_x = drawable.locX;
Expand All @@ -44,11 +44,11 @@ module UIHelpers {
return closest_drawable;
}

function drawPolygon(dc as Dc, points as Array<Array>) as Void {
function drawPolygon(dc as Dc, points as Array<Array<Float>>) as Void {
var counts = points.size();
for(var i = 0; i < counts; i++) {
var next_index = (i + 1) % counts;
dc.drawLine(points[i][0] as Number, points[i][1] as Number, points[next_index][0] as Number, points[next_index][1] as Number);
dc.drawLine(points[i][0], points[i][1], points[next_index][0], points[next_index][1]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/model/BetterMath.mc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module BetterMath {
return (number1 - number2).abs() * weight_ratio + min(number1, number2);
}

function roundAll(numbers as Array<Numeric>) {
function roundAll(numbers as Array<Numeric>) as Array<Numeric> {
var rounded = new [numbers.size()] as Array<Numeric>;
for(var i = 0; i < numbers.size(); i++) {
rounded[i] = Math.round(numbers[i]);
Expand Down
10 changes: 5 additions & 5 deletions source/model/Geometry.mc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Perspective {

function initialize(front_left_corner as Array<Float>, back_left_corner as Array<Float>, front_right_corner as Array<Float>, back_right_corner as Array<Float>) {
origin = [
BetterMath.mean(front_right_corner[0], front_left_corner[0]) as Float,
BetterMath.mean(front_right_corner[0], front_left_corner[0]),
front_left_corner[1]
] as Array<Float>;
height = front_left_corner[1] - back_left_corner[1];
Expand Down Expand Up @@ -56,10 +56,10 @@ class Perspective {
return [origin[0] + adjusted_x, origin[1] - adjusted_y] as Array<Float>;
}

function transformArray(coordinates as Array<Array>) as Array<Array> {
var transformed_coordinates = new [coordinates.size()] as Array<Array>;
function transformArray(coordinates as Array<Array<Float>>) as Array<Array<Float>> {
var transformed_coordinates = new [coordinates.size()] as Array<Array<Float>>;
for(var i = 0; i < coordinates.size(); i++) {
transformed_coordinates[i] = transform(coordinates[i] as Array<Float>);
transformed_coordinates[i] = transform(coordinates[i]);
}
return transformed_coordinates;
}
Expand All @@ -80,7 +80,7 @@ class Perspective {
dc.drawLine(beginning[0], beginning[1], end[0], end[1]);
}

function fillPolygon(dc as Dc, coordinates as Array<Array>) as Void {
function fillPolygon(dc as Dc, coordinates as Array<Array<Float>>) as Void {
dc.fillPolygon(transformArray(coordinates));
}

Expand Down
18 changes: 7 additions & 11 deletions source/model/Match.mc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class Match {
sets.push(new MatchSet(beginner as Player));
}

function getMaximumSets() as Number {
function getMaximumSets() as Number? {
return maximumSets;
}

Expand Down Expand Up @@ -224,7 +224,7 @@ class Match {
if(isEndless()) {
return null;
}
var winning_sets = maximumSets / 2;
var winning_sets = maximumSets as Number / 2; //if not in endless mode, maximum sets cannot be null
var player_1_sets = getSetsWon(YOU);
if(player_1_sets > winning_sets) {
return YOU;
Expand All @@ -245,12 +245,9 @@ class Match {
}
}

function getActivity() as Info {
return Activity.getActivityInfo();
}

function getDuration() as Duration {
var time = getActivity().elapsedTime;
var info = Activity.getActivityInfo() as Info;
var time = info.elapsedTime;
var seconds = time != null ? time / 1000 : 0;
return new Time.Duration(seconds);
}
Expand Down Expand Up @@ -300,7 +297,7 @@ class Match {
return won;
}

function getWinner() as Player {
function getWinner() as Player? {
return winner;
}

Expand All @@ -314,12 +311,11 @@ class Match {

function getReceivingCorner() as Corner {
var serving_corner = getServingCorner();
return OPPOSITE_CORNER[serving_corner];
return OPPOSITE_CORNER[serving_corner] as Corner;
}

function getPlayerIsServer() as Boolean {
var player_corner = getPlayerCorner();
return player_corner == getServingCorner();
return getPlayerCorner() == getServingCorner();
}

//methods used from perspective of player 1 (watch carrier)
Expand Down
2 changes: 1 addition & 1 deletion source/model/MatchSet.mc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MatchSet {
}

function getScore(player as Player) as Number {
return scores[player];
return scores[player] as Number;
}

function getServerTeam() as Player {
Expand Down
38 changes: 38 additions & 0 deletions source/test/MatchTest.mc
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,42 @@ module MatchTest {

return true;
}

function scorePoints(match as Match, points as Number) as Void {
for(var i = 0; i < points; i++) {
match.score(YOU);
match.score(OPPONENT);
}
}

(:test)
function testMemory(logger) {
//create a very complex match
var match = new Match(create_match_config(SINGLE, Match.MAX_SETS, YOU, true, 21, 30));
//set 1, won by YOU
scorePoints(match, 29);
match.score(YOU);
//set 2, won by OPPONENT
match.nextSet();
scorePoints(match, 29);
match.score(OPPONENT);
//set 3, won by YOU
match.nextSet();
scorePoints(match, 29);
match.score(YOU);
//set 4, won by OPPONENT
match.nextSet();
scorePoints(match, 29);
match.score(OPPONENT);
//set 5, won by YOU
match.nextSet();
scorePoints(match, 29);
match.score(YOU);
//end of match, won by YOU 3-2
BetterTest.assertTrue(match.hasEnded(), "Match has ended if all its sets have ended");
BetterTest.assertEqual(match.getTotalScore(YOU), 148, "Total score of player 1 is 148");
BetterTest.assertEqual(match.getTotalScore(OPPONENT), 147, "Total score of player 2 is 147");

return true;
}
}
6 changes: 2 additions & 4 deletions source/views/ActivityStatsView.mc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Toybox.Lang;
import Toybox.WatchUi;
using Toybox.WatchUi;
import Toybox.Activity;
using Toybox.Graphics;
using Toybox.Activity;

class ActivityStatsView extends WatchUi.View {

Expand All @@ -15,9 +14,8 @@ class ActivityStatsView extends WatchUi.View {
}

function onShow() {
var match = (Application.getApp() as BadmintonApp).getMatch();
//retrieve stats from activity
var activity = match.getActivity();
var activity = Activity.getActivityInfo() as Info;
var stats_available = false;

var average_heart_rate = activity.averageHeartRate;
Expand Down
4 changes: 2 additions & 2 deletions source/views/InitialView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class InitialView extends WatchUi.View {
//if config is valid, start the match
else if(config.isValid()) {
//adjust match configuration with app configuration
config.maximumPoints = Properties.getValue("maximum_points");
config.absoluteMaximumPoints = Properties.getValue("absolute_maximum_points");
config.maximumPoints = Properties.getValue("maximum_points") as Number;
config.absoluteMaximumPoints = Properties.getValue("absolute_maximum_points") as Number;

//create match
var match = new Match(config);
Expand Down
Loading

0 comments on commit dba1f63

Please sign in to comment.