fix death
This commit is contained in:
@@ -348,9 +348,10 @@ impl LobbyCommand {
|
|||||||
let team1_rank = team1.average_rating(&players);
|
let team1_rank = team1.average_rating(&players);
|
||||||
let team2_rank = team2.average_rating(&players);
|
let team2_rank = team2.average_rating(&players);
|
||||||
|
|
||||||
image_gen.draw_teams_to_png(
|
image_gen.draw_teams_to_vec(
|
||||||
player_names,
|
player_names,
|
||||||
[team1_rank.value as i32, team2_rank.value as i32],
|
[team1_rank.value as i32, team2_rank.value as i32],
|
||||||
|
image::ImageOutputFormat::Png
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use image::{codecs::png, ImageEncoder};
|
use image::ImageOutputFormat;
|
||||||
use imageproc::drawing::text_size;
|
use imageproc::drawing::text_size;
|
||||||
use rusttype::{Font, Scale};
|
use rusttype::{Font, Scale};
|
||||||
use serenity::prelude::TypeMapKey;
|
use serenity::prelude::TypeMapKey;
|
||||||
use std::{io::BufWriter, sync::Arc};
|
use std::{io::Cursor, sync::Arc};
|
||||||
|
|
||||||
pub struct ImageGenerator<'a> {
|
pub struct ImageGenerator<'a> {
|
||||||
pub player_font: Font<'a>,
|
pub player_font: Font<'a>,
|
||||||
@@ -11,7 +11,7 @@ pub struct ImageGenerator<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ImageGenerator<'a> {
|
impl<'a> ImageGenerator<'a> {
|
||||||
pub fn draw_teams_to_png(&self, player_names: Vec<String>, teams_rating: [i32; 2]) -> Vec<u8> {
|
pub fn draw_teams_to_vec(&self, player_names: Vec<String>, teams_rating: [i32; 2], format: ImageOutputFormat) -> Vec<u8> {
|
||||||
let mut image: image::ImageBuffer<image::Rgb<u8>, Vec<u8>> = self.teams_image.clone();
|
let mut image: image::ImageBuffer<image::Rgb<u8>, Vec<u8>> = self.teams_image.clone();
|
||||||
|
|
||||||
let player_text_scale = Scale::uniform(60.0);
|
let player_text_scale = Scale::uniform(60.0);
|
||||||
@@ -47,8 +47,8 @@ impl<'a> ImageGenerator<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let rating_text_scale = Scale::uniform(86.5);
|
let rating_text_scale = Scale::uniform(86.5);
|
||||||
for i in 0..2 {
|
for (i, rating) in teams_rating.iter().enumerate() {
|
||||||
let rating = teams_rating[i].to_string();
|
let rating = rating.to_string();
|
||||||
|
|
||||||
let size = text_size(rating_text_scale, &self.player_font, &rating);
|
let size = text_size(rating_text_scale, &self.player_font, &rating);
|
||||||
imageproc::drawing::draw_text_mut(
|
imageproc::drawing::draw_text_mut(
|
||||||
@@ -62,16 +62,11 @@ impl<'a> ImageGenerator<'a> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buf = BufWriter::new(Vec::new());
|
|
||||||
png::PngEncoder::new(&mut buf)
|
let mut buf = Cursor::new(Vec::new());
|
||||||
.write_image(
|
image.write_to(&mut buf, format).unwrap();
|
||||||
image.as_raw(),
|
|
||||||
image.width(),
|
buf.into_inner()
|
||||||
image.height(),
|
|
||||||
image::ColorType::Rgb8,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
buf.into_inner().unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ impl Player {
|
|||||||
|
|
||||||
for (i, role) in self.priority_roles.iter().enumerate() {
|
for (i, role) in self.priority_roles.iter().enumerate() {
|
||||||
if let Some(role) = role {
|
if let Some(role) = role {
|
||||||
priorities.insert(role.clone(), priority_points / (i + 1) as f32);
|
priorities.insert(*role, priority_points / (i + 1) as f32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ impl Team {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn count_role(&self, role: &Role) -> usize {
|
pub fn count_role(&self, role: &Role) -> usize {
|
||||||
self.count_role.get(role).unwrap().clone()
|
*self.count_role.get(role).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn full_rating(&self, players: &[Player]) -> Rating {
|
pub fn full_rating(&self, players: &[Player]) -> Rating {
|
||||||
@@ -55,7 +55,7 @@ impl Team {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|((role, _), index)| {
|
.map(|((role, _), index)| {
|
||||||
if let Some(index) = index {
|
if let Some(index) = index {
|
||||||
players[*index].ranks.get(role).unwrap().clone()
|
*players[*index].ranks.get(role).unwrap()
|
||||||
} else {
|
} else {
|
||||||
Rating::zero()
|
Rating::zero()
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ impl Team {
|
|||||||
.filter(|((r, _), _)| r == role)
|
.filter(|((r, _), _)| r == role)
|
||||||
.map(|((_, _), index)| {
|
.map(|((_, _), index)| {
|
||||||
if let Some(index) = index {
|
if let Some(index) = index {
|
||||||
players[*index].ranks.get(&role).unwrap().clone()
|
*players[*index].ranks.get(role).unwrap()
|
||||||
} else {
|
} else {
|
||||||
Rating::zero()
|
Rating::zero()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user