Non movable callback
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
tournament = 'tournoi-kiouze-test'
|
tournament = 'tournoi-kiouze-test'
|
||||||
update = 15
|
update = 20
|
||||||
fullscreen = false
|
fullscreen = false
|
||||||
smash_key = 'Bearer API_TOKEN'
|
font_size = 40
|
||||||
|
font_size_departure = 60
|
||||||
|
smash_key = 'Bearer c4b3c20f0be75100d7ce375eb8effc1a'
|
||||||
|
margin = 10
|
||||||
|
|||||||
77
src/main.rs
77
src/main.rs
@@ -17,12 +17,14 @@ use serde::Deserialize;
|
|||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize,Clone)]
|
#[derive(Deserialize,Clone)]
|
||||||
struct Config {
|
pub struct Config {
|
||||||
tournament: String,
|
tournament: String,
|
||||||
update: Option<u32>,
|
update: Option<u32>,
|
||||||
fullscreen: Option<bool>,
|
fullscreen: Option<bool>,
|
||||||
smash_key: String,
|
smash_key: String,
|
||||||
font_size: u16
|
font_size: u16,
|
||||||
|
font_size_departure : u16,
|
||||||
|
margin: u32
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,12 +39,12 @@ struct Line<'a> {
|
|||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self { tournament: String::new(), update: Some(1),fullscreen:Some(false), smash_key: String::new(), font_size: 30 }
|
Self { tournament: String::new(), update: Some(1),fullscreen:Some(false), smash_key: String::new(), font_size: 30 , font_size_departure : 45, margin: 10 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn render(canvas : &mut Canvas<sdl2::video::Window> , queues : &Vec<smashrequest::SmashQueue>,font : &sdl2::ttf::Font<'_, '_> ){
|
pub fn render(canvas : &mut Canvas<sdl2::video::Window> , queues : &Vec<smashrequest::SmashQueue>,font : &sdl2::ttf::Font<'_, '_> , font_departure : &sdl2::ttf::Font<'_, '_>, config : &Config ){
|
||||||
|
|
||||||
|
|
||||||
let texture_creator = canvas.texture_creator();
|
let texture_creator = canvas.texture_creator();
|
||||||
@@ -65,7 +67,8 @@ pub fn render(canvas : &mut Canvas<sdl2::video::Window> , queues : &Vec<smashreq
|
|||||||
let textq : TextureQuery = text.query();
|
let textq : TextureQuery = text.query();
|
||||||
let _ = canvas.copy(&text, None, Rect::new(0, y.try_into().map_err(|_| 0).unwrap(), textq.width, textq.height));
|
let _ = canvas.copy(&text, None, Rect::new(0, y.try_into().map_err(|_| 0).unwrap(), textq.width, textq.height));
|
||||||
|
|
||||||
y += textq.height+10;
|
y += textq.height+config.margin * 2;
|
||||||
|
|
||||||
//compute line
|
//compute line
|
||||||
for current_match in &sq.matches {
|
for current_match in &sq.matches {
|
||||||
|
|
||||||
@@ -88,18 +91,16 @@ pub fn render(canvas : &mut Canvas<sdl2::video::Window> , queues : &Vec<smashreq
|
|||||||
lines.push(line);
|
lines.push(line);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let prev_y = y;
|
let prev_y = y;
|
||||||
// background
|
// background
|
||||||
for l in &lines {
|
for l in &lines {
|
||||||
if l.alt_color {
|
if l.alt_color {
|
||||||
let _ = canvas.copy(&backline_text, None, Rect::new(0, y.try_into().map_err(|_| 0).unwrap(), canvas.viewport().width(), l.height));
|
let _ = canvas.copy(&backline_text, None, Rect::new(0, y as i32 - config.margin as i32 , canvas.viewport().width(), l.height + config.margin ));
|
||||||
}
|
}
|
||||||
y += l.height + 5;
|
y += l.height + (config.margin*2);
|
||||||
}
|
}
|
||||||
// depart !
|
// depart !
|
||||||
let d_surface = font.render("Départ / Departure").blended(Color::RGBA(130, 218, 255, 255)).map_err(|e| e.to_string()).unwrap();
|
let d_surface = font_departure.render("Départ / Departure").blended(Color::RGBA(130, 218, 255, 255)).map_err(|e| e.to_string()).unwrap();
|
||||||
let d_text = texture_creator.create_texture_from_surface(&d_surface).unwrap();
|
let d_text = texture_creator.create_texture_from_surface(&d_surface).unwrap();
|
||||||
let d_textq : TextureQuery = d_text.query();
|
let d_textq : TextureQuery = d_text.query();
|
||||||
|
|
||||||
@@ -113,8 +114,8 @@ pub fn render(canvas : &mut Canvas<sdl2::video::Window> , queues : &Vec<smashreq
|
|||||||
// foreground
|
// foreground
|
||||||
y = prev_y;
|
y = prev_y;
|
||||||
for l in &lines {
|
for l in &lines {
|
||||||
let _ = canvas.copy(&l.texture, None, Rect::new(10, y.try_into().map_err(|e| 0).unwrap(), l.width, l.height));
|
let _ = canvas.copy(&l.texture, None, Rect::new(10, y as i32 - config.margin as i32/2 , l.width, l.height));
|
||||||
y += l.height + 5;
|
y += l.height + (config.margin *2) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -124,21 +125,26 @@ pub fn render(canvas : &mut Canvas<sdl2::video::Window> , queues : &Vec<smashreq
|
|||||||
|
|
||||||
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
println!("Read config");
|
println!("Read config");
|
||||||
|
|
||||||
let config_file = fs::read_to_string("config.toml");
|
let config_file = fs::read_to_string("config.toml");
|
||||||
|
|
||||||
let config : Config = if config_file.is_ok() {
|
let box_config : Box<Config> = if config_file.is_ok() {
|
||||||
toml::from_str(&config_file.unwrap()).unwrap()
|
Box::new(toml::from_str(&config_file.unwrap()).unwrap())
|
||||||
} else {
|
} else {
|
||||||
Config::new()
|
Box::new(Config::new())
|
||||||
};
|
};
|
||||||
|
let update_timer = match box_config.update {
|
||||||
|
Some(v) => v,
|
||||||
|
None => 10
|
||||||
|
} * 1000 ;
|
||||||
|
|
||||||
println!("{}",config.tournament);
|
println!("{}",box_config.tournament);
|
||||||
if config.tournament.is_empty(){
|
if box_config.tournament.is_empty(){
|
||||||
println!("Empty Tournament , Exiting.");
|
println!("Empty Tournament , Exiting.");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let fullscreen = match config.fullscreen {
|
let fullscreen = match box_config.fullscreen {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => false
|
None => false
|
||||||
};
|
};
|
||||||
@@ -165,42 +171,40 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
let mut canvas: Canvas<sdl2::video::Window> = window.into_canvas().build().unwrap();
|
let mut canvas: Canvas<sdl2::video::Window> = window.into_canvas().build().unwrap();
|
||||||
let ttf_context = sdl2::ttf::init().unwrap();
|
let ttf_context = sdl2::ttf::init().unwrap();
|
||||||
let font : sdl2::ttf::Font<'_, '_> = ttf_context.load_font("font/achemine_bold.ttf", config.font_size).unwrap();
|
let font : sdl2::ttf::Font<'_, '_> = ttf_context.load_font("font/achemine_bold.ttf", box_config.font_size).unwrap();
|
||||||
|
let font_departure : sdl2::ttf::Font<'_, '_> = ttf_context.load_font("font/achemine_bold.ttf", box_config.font_size_departure).unwrap();
|
||||||
// let stream_queues : Vec<smashrequest::SmashQueue>= smashrequest::get_matches(config.tournament.as_str(),config.smash_key.as_str());
|
|
||||||
|
|
||||||
let timer = sdl_context.timer()?;
|
let timer = sdl_context.timer()?;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let test_clone = Arc::clone(&test);
|
let test_clone = Arc::clone(&test);
|
||||||
|
|
||||||
let _timer_cb = &timer.add_timer(1,Box::new(move || {
|
let callback = Box::new(|| {
|
||||||
println!("timer");
|
println!("Smash!");
|
||||||
let data = smashrequest::get_matches(config.tournament.as_str(), config.smash_key.as_str());
|
let data = smashrequest::get_matches(box_config.tournament.as_str(), box_config.smash_key.as_str());
|
||||||
println!("{:?}", data);
|
|
||||||
let mut a = test_clone.lock().unwrap();
|
let mut a = test_clone.lock().unwrap();
|
||||||
a.clone_from(&data);
|
a.clone_from(&data);
|
||||||
println!("{:?}",a);
|
return update_timer
|
||||||
return config.update.ok_or(10).unwrap()*1000;
|
});
|
||||||
})
|
|
||||||
);
|
//callback is called because timer is fucked up ?
|
||||||
|
callback();
|
||||||
|
|
||||||
|
let _timer_cb = &timer.add_timer(1,callback);
|
||||||
|
|
||||||
|
|
||||||
canvas.set_draw_color(Color::RGB(0, 255, 255));
|
canvas.set_draw_color(Color::RGB(0, 255, 255));
|
||||||
canvas.clear();
|
canvas.clear();
|
||||||
canvas.present();
|
canvas.present();
|
||||||
|
println!("Start Rendering");
|
||||||
let mut event_pump = sdl_context.event_pump().unwrap();
|
let mut event_pump = sdl_context.event_pump().unwrap();
|
||||||
'running: loop {
|
'running: loop {
|
||||||
canvas.set_draw_color(Color::RGB(0,136,206));
|
canvas.set_draw_color(Color::RGB(0,136,206));
|
||||||
canvas.clear();
|
canvas.clear();
|
||||||
let test_c = Arc::clone(&test);
|
let test_c = Arc::clone(&test);
|
||||||
let a = test_c.lock().unwrap();
|
let a = test_c.lock().unwrap();
|
||||||
render(&mut canvas,&a,&font);
|
//println!("{:?}",&a);
|
||||||
//render(&mut canvas,&stream_queues,&font);
|
render(&mut canvas,&a,&font,&font_departure, &box_config);
|
||||||
timer.ticks();
|
|
||||||
for event in event_pump.poll_iter() {
|
for event in event_pump.poll_iter() {
|
||||||
match event {
|
match event {
|
||||||
Event::Quit {..} |
|
Event::Quit {..} |
|
||||||
@@ -210,7 +214,6 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The rest of the game loop goes here...
|
|
||||||
|
|
||||||
canvas.present();
|
canvas.present();
|
||||||
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60));
|
::std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60));
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ pub fn get_matches(tournament : &str, key : &str) -> Vec<SmashQueue> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if !(p1name.is_empty() & p2name.is_empty()){
|
if !(p1name.is_empty() || p2name.is_empty()){
|
||||||
|
|
||||||
let mat = Match { full_round_test : String::from(set.full_round_text.unwrap()) ,
|
let mat = Match { full_round_test : String::from(set.full_round_text.unwrap()) ,
|
||||||
player1: String::from(p1name),
|
player1: String::from(p1name),
|
||||||
|
|||||||
Reference in New Issue
Block a user