Techtree

<
>
September 11, 2021

I addded a very basic TechTree implementation to hide some Structures behind research.
There’s currently only one Tech:

pub enum Tech {
    BetterBelts,
}

A Tech might require other technologies to be researched first:

impl Tech {
    pub fn dependencies(&self) -> &'static [Tech] {
        match self {
            Self::BetterBelts => &[],
        }
    }
    ...

There’s also a trait for everything that requires a Tech:

pub trait RequiresTech {
    fn requires_tech(&self) -> Option<Tech>;
}

Which can then be implemented for Item:

impl RequiresTech for Item {
    fn requires_tech(&self) -> Option<Tech> {
        match self {
            Self::Material(_) => None,
            Self::Structure(x) => x.requires_tech(),
        }
    }
}

...

impl RequiresTech for SimpleStructure {
    fn requires_tech(&self) -> Option<Tech> {
        match self {
            Self::Belt => None,
            ...
            Self::Splitter => Some(Tech::BetterBelts),
            Self::Swapper => Some(Tech::BetterBelts),
            ...
        }
    }
}

I also added a TechTree manages what has been researched and could be researched next.
It’s also rendered, but not that interesting due to the single Tech so far: