implement default colors

This commit is contained in:
Michael Zhang 2021-01-10 02:51:21 -06:00
parent 8cc1d578ab
commit 4abf19784e
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
4 changed files with 45 additions and 20 deletions

View file

@ -1,3 +1,4 @@
use ggez::graphics::Color;
use libosu::{beatmap::Beatmap, hitobject::HitObjectKind, math::Point};
use crate::hitobject::HitObjectExt;
@ -21,13 +22,13 @@ impl BeatmapExt {
BeatmapExt { inner, hit_objects }
}
pub fn compute_colors(&mut self) {
pub fn compute_colors(&mut self, colors: &[Color]) {
let mut color_idx = 0;
let mut number = 1;
for ho in self.hit_objects.iter_mut() {
if ho.inner.new_combo {
number = 1;
color_idx = (color_idx + 1) % self.inner.colors.len();
color_idx = (color_idx + 1) % colors.len();
}
ho.number = number;
@ -37,7 +38,9 @@ impl BeatmapExt {
}
pub fn compute_stacking(&mut self) {
self.compute_stacking_inner(0, self.hit_objects.len() - 1)
if self.inner.stack_leniency > 0.0 {
self.compute_stacking_inner(0, self.hit_objects.len() - 1)
}
}
fn compute_stacking_inner(&mut self, start_idx: usize, end_idx: usize) {

View file

@ -28,6 +28,12 @@ use crate::hitobject::HitObjectExt;
use crate::skin::Skin;
pub const PLAYFIELD_BOUNDS: Rect = Rect::new(112.0, 122.0, 800.0, 600.0);
pub const DEFAULT_COLORS: &[(f32, f32, f32)] = &[
(1.0, 0.75, 0.0),
(0.0, 0.8, 0.0),
(0.07, 0.5, 1.0),
(0.95, 0.1, 0.22),
];
pub type SliderCache = HashMap<Vec<Point<i32>>, Spline>;
@ -39,6 +45,7 @@ pub struct Game {
pub skin: Skin,
frame: usize,
slider_cache: SliderCache,
combo_colors: Vec<Color>,
keymap: HashSet<KeyCode>,
current_uninherited_timing_point: Option<TimingPoint>,
@ -61,6 +68,10 @@ impl Game {
skin,
frame: 0,
slider_cache: SliderCache::default(),
combo_colors: DEFAULT_COLORS
.iter()
.map(|(r, g, b)| Color::new(*r, *g, *b, 1.0))
.collect(),
keymap: HashSet::new(),
current_uninherited_timing_point: None,
@ -77,9 +88,32 @@ impl Game {
let beatmap = Beatmap::from_osz(&contents)?;
self.beatmap = BeatmapExt::new(beatmap);
self.beatmap.compute_colors();
self.beatmap.compute_stacking();
if self.beatmap.inner.colors.len() > 0 {
self.combo_colors.clear();
self.combo_colors = self
.beatmap
.inner
.colors
.iter()
.map(|color| {
Color::new(
color.red as f32 / 255.0,
color.green as f32 / 255.0,
color.blue as f32 / 255.0,
1.0,
)
})
.collect();
} else {
self.combo_colors = DEFAULT_COLORS
.iter()
.map(|(r, g, b)| Color::new(*r, *g, *b, 1.0))
.collect();
}
self.beatmap.compute_colors(&self.combo_colors);
let dir = path.parent().unwrap();
let song = Sound::create(dir.join(&self.beatmap.inner.audio_filename))?;
@ -134,13 +168,7 @@ impl Game {
// keeping track of the old index will probably be much faster
for ho in self.beatmap.hit_objects.iter().rev() {
let ho_time = (ho.inner.start_time.0 as f64) / 1000.0;
let color = self.beatmap.inner.colors[ho.color_idx];
let color = graphics::Color::new(
color.red as f32 / 256.0,
color.green as f32 / 256.0,
color.blue as f32 / 256.0,
1.0,
);
let color = self.combo_colors[ho.color_idx];
// draw in timeline
self.draw_hitobject_to_timeline(ctx, time, ho)?;

View file

@ -29,8 +29,8 @@ impl Game {
for timing_point in self.beatmap.inner.timing_points.iter() {
let color = match timing_point.kind {
TimingPointKind::Inherited(_) => Color::new(0.0, 1.0, 0.0, 0.5),
TimingPointKind::Uninherited(_) => Color::new(1.0, 0.0, 0.0, 0.5),
TimingPointKind::Inherited(_) => Color::new(0.0, 0.8, 0.0, 0.5),
TimingPointKind::Uninherited(_) => Color::new(0.8, 0.0, 0.0, 0.5),
};
let percent = timing_point.time.as_seconds() / len;

View file

@ -157,13 +157,7 @@ impl Game {
.get_hitobject_end_time(&ho.inner)
.as_seconds();
let color = self.beatmap.inner.colors[ho.color_idx];
let color = graphics::Color::new(
color.red as f32 / 256.0,
color.green as f32 / 256.0,
color.blue as f32 / 256.0,
1.0,
);
let color = self.combo_colors[ho.color_idx];
if end_time >= timeline_left && start_time <= timeline_right {
let timeline_percent = (start_time - timeline_left) / (timeline_right - timeline_left);