Minor fixes
This commit is contained in:
parent
b891ff76b4
commit
884b23c5a5
16
src/lib.rs
16
src/lib.rs
|
@ -90,6 +90,7 @@
|
||||||
clippy::module_name_repetitions,
|
clippy::module_name_repetitions,
|
||||||
clippy::missing_errors_doc
|
clippy::missing_errors_doc
|
||||||
)]
|
)]
|
||||||
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
pub mod physics;
|
pub mod physics;
|
||||||
pub mod vec2;
|
pub mod vec2;
|
||||||
|
@ -107,9 +108,6 @@ use sdl2::{
|
||||||
video::{Window, WindowBuildError, WindowContext},
|
video::{Window, WindowBuildError, WindowContext},
|
||||||
EventPump, IntegerOrSdlError,
|
EventPump, IntegerOrSdlError,
|
||||||
};
|
};
|
||||||
use std::fs::File;
|
|
||||||
use std::io::BufReader;
|
|
||||||
use std::thread;
|
|
||||||
use std::{
|
use std::{
|
||||||
cell::Cell,
|
cell::Cell,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
|
@ -782,13 +780,21 @@ impl Game {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "audio")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "audio")))]
|
||||||
/// Plays an audio file given the path of file and plays it for y seconds
|
/// Plays an audio file given the path of file and plays it for y seconds
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use cat_box::play;
|
/// # use cat_box::play;
|
||||||
/// play("/path/to/song.mp3", 15);
|
/// play("/path/to/song.mp3", 15);
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(feature = "audio")]
|
pub fn play<P: AsRef<Path>>(path: P, time: u64) -> std::thread::JoinHandle<Result<()>> {
|
||||||
pub fn play<P: AsRef<Path> + std::marker::Send + 'static>(x: P, y: u64) -> thread::JoinHandle<()> {
|
use std::fs::File;
|
||||||
|
use std::io::BufReader;
|
||||||
|
use std::thread;
|
||||||
|
|
||||||
|
// bypass the Send + 'static requirement
|
||||||
|
let p = path.as_ref();
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let (_stream, stream_handle) = OutputStream::try_default()?;
|
let (_stream, stream_handle) = OutputStream::try_default()?;
|
||||||
// Load a sound from a file, using a path relative to Cargo.toml
|
// Load a sound from a file, using a path relative to Cargo.toml
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
#![warn(clippy::pedantic)]
|
#![warn(clippy::pedantic)]
|
||||||
|
|
||||||
use cat_box::{
|
use cat_box::{draw_text, get_keyboard_state, get_mouse_state, Game, Sprite, SpriteCollection};
|
||||||
draw_text, get_keyboard_state, get_mouse_state, play, Game, Sprite, SpriteCollection,
|
|
||||||
};
|
|
||||||
use sdl2::keyboard::Scancode;
|
use sdl2::keyboard::Scancode;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -21,7 +19,8 @@ fn main() {
|
||||||
coll.push(x);
|
coll.push(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
play(String::from("output.mp3"), 120);
|
#[cfg(feature = "audio")]
|
||||||
|
cat_box::play("output.mp3", 120);
|
||||||
game.run(|ctx| {
|
game.run(|ctx| {
|
||||||
i = (i + 1) % 255;
|
i = (i + 1) % 255;
|
||||||
ctx.set_background_colour(i as u8, 64, 255);
|
ctx.set_background_colour(i as u8, 64, 255);
|
||||||
|
|
Loading…
Reference in a new issue