diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-26 13:25:28 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-26 13:26:09 +0200 |
commit | af1221c3e3ba55f99d3a5dc0983c67f3bdda525f (patch) | |
tree | ca072538361807738397e0a8cb4f1e2cb1b23098 | |
parent | cf24bc076e9d3746210e507875a7178df19b51b1 (diff) | |
download | hurrycurry-af1221c3e3ba55f99d3a5dc0983c67f3bdda525f.tar hurrycurry-af1221c3e3ba55f99d3a5dc0983c67f3bdda525f.tar.bz2 hurrycurry-af1221c3e3ba55f99d3a5dc0983c67f3bdda525f.tar.zst |
reverse instant recipe output when input is reversed
-rw-r--r-- | server/src/interaction.rs | 13 | ||||
-rw-r--r-- | test-client/main.ts | 2 |
2 files changed, 9 insertions, 6 deletions
diff --git a/server/src/interaction.rs b/server/src/interaction.rs index 615d2aab..e3dccfba 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -192,12 +192,13 @@ pub fn interact( } => { let on_tile = this.as_ref().map(|i| i.kind); let in_hand = other.as_ref().map(|i| i.kind); - let ok = (inputs[0] == on_tile && inputs[1] == in_hand) - || (inputs[1] == on_tile && inputs[0] == in_hand); - if ok { - info!("instant recipe {ri:?}"); - *other = outputs[0].map(|kind| Item { kind, active: None }); - *this = outputs[1].map(|kind| Item { kind, active: None }); + let ok = inputs[0] == on_tile && inputs[1] == in_hand; + let ok_rev = inputs[1] == on_tile && inputs[0] == in_hand; + if ok || ok_rev { + info!("instant recipe {ri:?} reversed={ok_rev}"); + let ok_rev = ok_rev as usize; + *other = outputs[1 - ok_rev].map(|kind| Item { kind, active: None }); + *this = outputs[ok_rev].map(|kind| Item { kind, active: None }); return Some(InteractEffect::Produce); } } diff --git a/test-client/main.ts b/test-client/main.ts index 04cd2331..42c1a3e0 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -201,6 +201,8 @@ function keyboard(ev: KeyboardEvent, down: boolean) { if (HANDLED_KEYS.includes(ev.code)) ev.preventDefault() if (!keys_down.has("Space") && ev.code == "Space" && down) set_interact(true) if (keys_down.has("Space") && ev.code == "Space" && !down) set_interact(false) + if (down && !ev.shiftKey && ev.code == "KeyK") send({ type: "communicate", message: { text: "/start" } }) + if (down && ev.shiftKey && ev.code == "KeyK") send({ type: "communicate", message: { text: "/end" } }) if (down) keys_down.add(ev.code) else keys_down.delete(ev.code) } |