Commit dc2ba21f authored by Rahix's avatar Rahix 🦀
Browse files

Add angel_shifts module

A new module to contain the "logic" for all angel shifts.  As an
example/first shift, introduce a "Bottle Angel Shift".

Shifts are abstracted as a trait object which contains the actual shift
logic and is dynamically selected based on RNG.
parent 5e992bcb
pub struct BottleAngelShift {
hours: usize,
}
impl BottleAngelShift {
pub fn generate(rng: &mut impl rand::Rng) -> BottleAngelShift {
BottleAngelShift {
hours: rng.gen_range(1, 3),
}
}
}
impl super::AngelShiftImpl for BottleAngelShift {
fn metadata(&self) -> super::ShiftMetadata {
super::ShiftMetadata {
title: "Bottle Angel".to_owned(),
description: "Collect bottles from all bottle drop points in the designated area."
.to_owned(),
hours: self.hours,
}
}
}
pub trait AngelShiftImpl {
/// Return metadata about this shift.
///
/// Used in heaven to display what task is up next.
fn metadata(&self) -> ShiftMetadata;
}
pub struct ShiftMetadata {
/// Short name of this shift/task.
pub title: String,
/// Longer description of what needs to be done.
pub description: String,
/// Amount of hours that would be gained from working this shift.
pub hours: usize,
}
pub struct AngelShift(pub Box<dyn AngelShiftImpl>);
impl AngelShift {
pub fn metadata(&self) -> ShiftMetadata {
self.0.metadata()
}
}
mod bottle_angel;
mod definitions;
pub use definitions::AngelShift;
pub use definitions::AngelShiftImpl;
pub use definitions::ShiftMetadata;
pub fn generate_random_shift(rng: &mut impl rand::Rng) -> AngelShift {
AngelShift(match rng.gen_range(0usize, 1) {
0 => Box::new(bottle_angel::BottleAngelShift::generate(rng)),
_ => unreachable!(),
})
}
use wasm_bindgen::prelude::*;
pub mod angel_shifts;
pub mod colliders;
pub mod colors;
pub mod components;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment