diff options
| author | metamuffin <metamuffin@disroot.org> | 2024-06-18 11:21:23 +0200 | 
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2024-06-23 19:20:50 +0200 | 
| commit | 3e8c24375f064487365a66c20fba20bea8e1f860 (patch) | |
| tree | 590f03a6fed22ae3abfba3ae1aecb5a1d18a2b13 /server/src/interaction.rs | |
| parent | 20a978e4f91e03588bf89d2426ee215f176b1ac7 (diff) | |
| download | hurrycurry-3e8c24375f064487365a66c20fba20bea8e1f860.tar hurrycurry-3e8c24375f064487365a66c20fba20bea8e1f860.tar.bz2 hurrycurry-3e8c24375f064487365a66c20fba20bea8e1f860.tar.zst | |
active recipes work
Diffstat (limited to 'server/src/interaction.rs')
| -rw-r--r-- | server/src/interaction.rs | 42 | 
1 files changed, 31 insertions, 11 deletions
| diff --git a/server/src/interaction.rs b/server/src/interaction.rs index f2d44dee..11409b10 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -31,14 +31,26 @@ pub fn interact(          }      }      if !edge { +        debug!("falling edge");          if let Some(ac) = active {              if matches!(data.recipes[ac.recipe].action, Action::Active(_)) { +                debug!("workers--");                  ac.working -= 1;              }          }          return;      } +    if hand.is_none() { +        debug!("rising edge"); +        if let Some(active) = active { +            if matches!(data.recipes[active.recipe].action, Action::Active(_)) { +                debug!("workers++"); +                active.working += 1; +            } +        } +    } +      if active.is_none() && !items.is_empty() && hand.is_none() {          out(Take(items.len() - 1));          return; @@ -54,7 +66,7 @@ pub fn interact(          }      } -    if hand.is_none() { +    if hand.is_none() && active.is_none() {          'rloop: for (ri, r) in data.recipes.iter().enumerate() {              if tile != r.tile {                  continue; @@ -74,19 +86,27 @@ pub fn interact(              match r.action {                  Action::Passive(_) => { -                    info!("use recipe {r:?}"); +                    info!("use passive recipe {ri}");                      *active = Some(ActiveRecipe {                          recipe: ri,                          progress: 0., -                        working: 0, +                        working: 1, +                    }); +                    break 'rloop; +                } +                Action::Active(_) => { +                    info!("use active recipe {ri}"); +                    *active = Some(ActiveRecipe { +                        recipe: ri, +                        progress: 0., +                        working: 1,                      });                      break 'rloop;                  } -                Action::Active(_) => {}                  Action::Instant => { -                    info!("use recipe {r:?}"); -                    for i in 0..items.len() { -                        out(Consume(i)) +                    info!("use instant recipe {ri}"); +                    for _ in 0..items.len() { +                        out(Consume(0))                      }                      for i in &r.outputs {                          out(Produce(*i)); @@ -108,15 +128,15 @@ pub fn tick_tile(      data: &Gamedata,      _tile: TileIndex,      active: &mut Option<ActiveRecipe>, -    mut items: Vec<ItemIndex>, +    items: Vec<ItemIndex>,      mut out: impl FnMut(Out),  ) {      if let Some(a) = active {          let r = &data.recipes[a.recipe]; -        a.progress += dt / r.action.duration(); +        a.progress += a.working as f32 * dt / r.action.duration();          if a.progress >= 1. { -            for i in 0..items.len() { -                out(Consume(i)) +            for _ in 0..items.len() { +                out(Consume(0))              }              for i in &r.outputs {                  out(Produce(*i)); | 
