1use image::{Pixel, Rgb, RgbImage, Rgba, RgbaImage};
2use rand::{rngs::ThreadRng, seq::IndexedRandom, RngExt};
3
4pub type PlayerId = uuid::Uuid;
5
6#[inline]
7pub fn is_transparent(pixel: &Rgba<u8>, background: &Rgba<u8>) -> bool {
8 pixel[3] == 0 || pixel.to_rgb() == background.to_rgb()
9}
10
11pub const MAX_USERNAME_LEN: usize = 12;
12
13pub fn to_player_name(rng: &mut ThreadRng, name: &str) -> String {
14 format!(
15 "{}#{:03}",
16 name.chars().take(MAX_USERNAME_LEN).collect::<String>(),
17 rng.random_range(0..1000)
18 )
19}
20
21pub fn random_minotaur_name() -> String {
22 MINOTAUR_NAMES.choose(&mut rand::rng()).unwrap().to_string()
23}
24
25pub fn convert_rgb_to_rgba(rgb_image: &RgbImage, background: Rgb<u8>) -> RgbaImage {
26 let (width, height) = rgb_image.dimensions();
27 let mut rgba_image = RgbaImage::new(width, height);
28
29 for (x, y, rgb_pixel) in rgb_image.enumerate_pixels() {
30 let alpha = if rgb_pixel.to_rgb() == background {
31 0
32 } else {
33 255
34 };
35
36 let Rgba([r, g, b, a]) = Rgba([rgb_pixel[0], rgb_pixel[1], rgb_pixel[2], alpha]);
37 rgba_image.put_pixel(x, y, Rgba([r, g, b, a]));
38 }
39
40 rgba_image
41}
42
43pub struct GameColors {}
44
45impl GameColors {
46 pub const HERO: Rgba<u8> = Rgba([35, 35, 255, 255]);
47 pub const OTHER_HERO: Rgba<u8> = Rgba([3, 255, 3, 255]);
48 pub const MINOTAUR: Rgba<u8> = Rgba([225, 203, 3, 255]);
49 pub const CHASING_MINOTAUR: Rgba<u8> = Rgba([255, 15, 0, 255]);
50 pub const POWER_UP: Rgba<u8> = Rgba([255, 180, 244, 255]);
51}
52
53pub const MINOTAUR_NAMES: [&str; 7] = [
54 "Ἀστερίων",
55 "Μίνως",
56 "Σαρπηδών",
57 "Ῥαδάμανθυς",
58 "Ἀμφιτρύων",
59 "Πτερέλαος",
60 "Τάφος",
61];