diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-18 10:17:40 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-23 19:20:50 +0200 |
commit | 20a978e4f91e03588bf89d2426ee215f176b1ac7 (patch) | |
tree | b99bd5b52dbd7cc31cec9bfcf79a197184f72a40 /server/src/interaction.rs | |
parent | 9bdb81bb34bd6a7e33c47d6fcb3dced1c5bda991 (diff) | |
download | hurrycurry-20a978e4f91e03588bf89d2426ee215f176b1ac7.tar hurrycurry-20a978e4f91e03588bf89d2426ee215f176b1ac7.tar.bz2 hurrycurry-20a978e4f91e03588bf89d2426ee215f176b1ac7.tar.zst |
passive recipes work
Diffstat (limited to 'server/src/interaction.rs')
-rw-r--r-- | server/src/interaction.rs | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/server/src/interaction.rs b/server/src/interaction.rs index fadfe8d9..f2d44dee 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -12,6 +12,7 @@ pub enum Out { Put, Produce(ItemIndex), Consume(usize), + SetActive(Option<f32>), } pub fn interact( @@ -38,16 +39,18 @@ pub fn interact( return; } - if !items.is_empty() && hand.is_none() { + if active.is_none() && !items.is_empty() && hand.is_none() { out(Take(items.len() - 1)); return; } - if let Some(hi) = hand { - if allowed.contains(&hi) { - out(Put); - items.push(hi); - hand = None; + if active.is_none() { + if let Some(hi) = hand { + if allowed.contains(&hi) { + out(Put); + items.push(hi); + hand = None; + } } } @@ -99,3 +102,29 @@ pub fn interact( } } } + +pub fn tick_tile( + dt: f32, + data: &Gamedata, + _tile: TileIndex, + active: &mut Option<ActiveRecipe>, + mut 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(); + if a.progress >= 1. { + for i in 0..items.len() { + out(Consume(i)) + } + for i in &r.outputs { + out(Produce(*i)); + } + out(SetActive(None)); + active.take(); + } else { + out(SetActive(Some(a.progress))); + } + } +} |