Add the ownership system #96

Merged
raphael merged 8 commits from ownership-system into main 2024-04-03 15:44:19 +00:00
2 changed files with 7 additions and 6 deletions
Showing only changes of commit 3f679665d9 - Show all commits

View file

@ -28,6 +28,7 @@ fn setup_ownership_resources(mut commands: Commands) {
commands.insert_resource(OwnershipColorContrast(0.4));
}
/// Render the ownership of the tiles by applying colors.
fn render_ownership(
mut query: Query<(&mut Sprite, &Owner), Changed<Owner>>,
contrast: Res<OwnershipColorContrast>,
@ -40,12 +41,12 @@ fn render_ownership(
}
}
// Mixes two colors.
/// Mixes two colors.
fn mix_colors(color1: Color, color2: Color, alpha: f32) -> Color {
let [r1, g1, b1, _] = color1.as_rgba_u8();
let [r2, g2, b2, _] = color2.as_rgba_u8();
let mixed_r = ((1.0 - alpha) * r1 as f32 + alpha * r2 as f32).round() as u8;
let mixed_g = ((1.0 - alpha) * g1 as f32 + alpha * g2 as f32).round() as u8;
let mixed_b = ((1.0 - alpha) * b1 as f32 + alpha * b2 as f32).round() as u8;
let mixed_r = (1.0 - alpha).mul_add(r1 as f32, alpha * r2 as f32).round() as u8;
let mixed_g = (1.0 - alpha).mul_add(g1 as f32, alpha * g2 as f32).round() as u8;
let mixed_b = (1.0 - alpha).mul_add(b1 as f32, alpha * b2 as f32).round() as u8;
Color::rgb_u8(mixed_r, mixed_g, mixed_b)
}

View file

@ -58,7 +58,7 @@ fn menu_ui(
name: name.clone(),
rank: PlayerRank::Player,
uuid,
color: (0, 0, 0),
color: rand::random::<(u8, u8, u8)>(),
}),
));
}
@ -72,7 +72,7 @@ fn menu_ui(
name: name.clone(),
rank: PlayerRank::Admin,
uuid,
color: (255, 255, 255),
color: rand::random::<(u8, u8, u8)>(),
});
}
});