#[repr(C, packed(1))]pub struct ObserverGame {
pub in_game: bool,
pub clock_ms: u32,
pub active_player_count: u8,
pub game_name: PaddedString<MAX_GAME_NAME_LENGTH>,
pub map_name: PaddedString<MAX_MAP_NAME_LENGTH>,
}Expand description
Game-wide state exposed by the Warcraft III Stats Observer API.
Fields§
§in_game: booltrue while a game is in progress.
clock_ms: u32Elapsed game time in milliseconds. Use Self::time for a
strongly-typed Duration.
active_player_count: u8Number of valid entries in crate::ObserverData::players.
game_name: PaddedString<MAX_GAME_NAME_LENGTH>Name of the current game / lobby.
map_name: PaddedString<MAX_MAP_NAME_LENGTH>Name of the map currently being played.
Implementations§
Source§impl ObserverGame
impl ObserverGame
Sourcepub fn time(&self) -> Duration
pub fn time(&self) -> Duration
Returns the elapsed game time as a Duration.
Examples found in repository?
examples/stats.rs (line 22)
5fn main() {
6 let od = match ObserverHandle::new() {
7 Ok(od) => od,
8 Err(e) => {
9 eprintln!("Error opening observer API. Is Warcraft3 running? Error: {e:?}");
10 return;
11 }
12 };
13
14 println!("version: {}", { od.version });
15 println!("refresh rate: {}", { od.refresh_rate });
16
17 let game = &od.game;
18
19 println!("in game: {:?}", game.in_game);
20 println!(
21 "time: {:02}:{:02}",
22 game.time().as_secs() / 60,
23 game.time().as_secs() % 60
24 );
25 println!("active player count: {:?}", game.active_player_count);
26 println!("game name: {}", game.game_name);
27 println!("map name: {}", game.map_name);
28
29 loop {
30 for player in od.players.iter().take(od.game.active_player_count as usize) {
31 println!("{} has {} gold {} lumber", player.name, { player.gold }, {
32 player.lumber
33 });
34 }
35 println!();
36 std::thread::sleep(Duration::from_millis(od.refresh_rate as u64));
37 }
38}Auto Trait Implementations§
impl Freeze for ObserverGame
impl RefUnwindSafe for ObserverGame
impl Send for ObserverGame
impl Sync for ObserverGame
impl Unpin for ObserverGame
impl UnsafeUnpin for ObserverGame
impl UnwindSafe for ObserverGame
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more