progress bars
This commit is contained in:
parent
5817fea9ad
commit
fe4543ae41
6 changed files with 142 additions and 68 deletions
95
src/game.rs
Normal file
95
src/game.rs
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
use crate::bar::Bar;
|
||||
use crate::queue::PacketQueue;
|
||||
use crate::label::Label;
|
||||
use crate::{Currency, GenerateCommands, Progressable};
|
||||
use servicepoint::{Origin, TILE_WIDTH};
|
||||
use std::time::Duration;
|
||||
|
||||
const STEP_COUNT: usize = 11;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Game {
|
||||
pub(crate) currency: Currency,
|
||||
pub(crate) bars: [Bar; STEP_COUNT],
|
||||
pub(crate) names: [&'static str; STEP_COUNT],
|
||||
}
|
||||
|
||||
impl Game {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
currency: 0f64,
|
||||
bars: [
|
||||
Bar::new(1f64, Origin::new(0, 1)).add_speed(1.0),
|
||||
Bar::new(2f64, Origin::new(0, 2)).add_speed(0.5),
|
||||
Bar::new(4f64, Origin::new(0, 3)).add_speed(0.25),
|
||||
Bar::new(8f64, Origin::new(0, 4)).add_speed(0.125),
|
||||
Bar::new(16f64, Origin::new(0, 5)).add_speed(0.0625),
|
||||
Bar::new(32f64, Origin::new(0, 6)).add_speed(0.03125),
|
||||
Bar::new(64f64, Origin::new(0, 7)).add_speed(0.015625),
|
||||
Bar::new(128f64, Origin::new(0, 8)).add_speed(0.0078125),
|
||||
Bar::new(256f64, Origin::new(0, 9)).add_speed(0.00390625),
|
||||
Bar::new(512f64, Origin::new(0, 10)).add_speed(0.001953125),
|
||||
Bar::new(1024f64, Origin::new(0, 11)).add_speed(0.000976562),
|
||||
],
|
||||
names: [
|
||||
"Powering infrastructure",
|
||||
"Dusting ServicePoint",
|
||||
"Activating colorful lights",
|
||||
"Dimming darkroom",
|
||||
"Refilling Matemat",
|
||||
"Pre-heating convectiomat",
|
||||
"Resetting chair heights",
|
||||
"Cleaning 'block chain'",
|
||||
"Refilling sticker box",
|
||||
"Setting room to public",
|
||||
"Welcoming creatures",
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Progressable for Game {
|
||||
fn progress(&self, delta: Duration) -> (Self, Currency) {
|
||||
let mut currency = self.currency;
|
||||
let bars = self.bars.clone().map(|bar| {
|
||||
let (bar, curr) = bar.progress(delta);
|
||||
currency += curr;
|
||||
bar
|
||||
});
|
||||
|
||||
(
|
||||
Self {
|
||||
currency,
|
||||
bars,
|
||||
names: self.names,
|
||||
},
|
||||
0f64,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl GenerateCommands for Game {
|
||||
fn generate_commands(&self, queue: &mut impl PacketQueue) {
|
||||
Label::new(Origin::ZERO, TILE_WIDTH / 2, "Discordia Boot Procedure")
|
||||
.generate_commands(queue);
|
||||
Label::new(
|
||||
Origin::new(TILE_WIDTH / 2 + 1, 0),
|
||||
TILE_WIDTH / 2,
|
||||
format!("Cycles: {}", self.currency.floor()),
|
||||
)
|
||||
.generate_commands(queue);
|
||||
|
||||
for (index, bar) in self.bars.iter().enumerate() {
|
||||
if !bar.is_enabled() {
|
||||
continue;
|
||||
}
|
||||
bar.generate_commands(queue);
|
||||
Label::new(
|
||||
Origin::new(TILE_WIDTH / 2 + 1, 1 + index),
|
||||
TILE_WIDTH / 2 - 1,
|
||||
self.names[index],
|
||||
)
|
||||
.generate_commands(queue);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue