Skip to content

Commit bbe102c

Browse files
committed
add docs
1 parent 40a75d1 commit bbe102c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/stats.rs

+18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ pub struct Board(pub u8);
88

99
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
1010
pub struct Progress {
11+
/// How many points the player already has.
1112
pub done: u16,
13+
/// How many points the player needs to earn the badge.
1214
pub goal: u16,
1315
}
1416

@@ -19,11 +21,19 @@ impl Progress {
1921
}
2022
}
2123

24+
/// Get the progress of earning the badge.
2225
#[must_use]
2326
pub fn get_progress(p: Peer, b: Badge) -> Progress {
2427
add_progress(p, b, 0)
2528
}
2629

30+
/// Add the given value to the progress for the badge.
31+
///
32+
/// May be negative if you want to decrease the progress.
33+
/// If zero, does not change the progress.
34+
///
35+
/// If the Peer is [`Peer::COMBINED`], the progress is added to every peer
36+
/// and the returned value is the lowest progress.
2737
#[expect(clippy::must_use_candidate)]
2838
pub fn add_progress(p: Peer, b: Badge, v: i16) -> Progress {
2939
let r = unsafe { bindings::add_progress(u32::from(p.0), u32::from(b.0), i32::from(v)) };
@@ -33,11 +43,19 @@ pub fn add_progress(p: Peer, b: Badge, v: i16) -> Progress {
3343
}
3444
}
3545

46+
/// Get the personal best of the player.
3647
#[must_use]
3748
pub fn get_score(p: Peer, b: Badge) -> i16 {
3849
add_score(p, b, 0)
3950
}
4051

52+
/// Add the given score to the board.
53+
///
54+
/// May be negative if you want the lower scores
55+
/// to rank higher. Zero value is not added to the board.
56+
///
57+
/// If the Peer is [`Peer::COMBINED`], the score is added for every peer
58+
/// and the returned value is the lowest of their best scores.
4159
#[expect(clippy::must_use_candidate)]
4260
pub fn add_score(p: Peer, b: Badge, v: i16) -> i16 {
4361
let r = unsafe { bindings::add_score(u32::from(p.0), u32::from(b.0), i32::from(v)) };

0 commit comments

Comments
 (0)