diff options
author | metamuffin <metamuffin@disroot.org> | 2024-08-11 13:35:15 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-08-11 13:35:15 +0200 |
commit | 52d99b16534631e293a23ddbc18c4ea70b71392f (patch) | |
tree | f596887a976540ab553e69105ab192cbbb2dd753 /server/src/interaction.rs | |
parent | 63d5a3ff37d1e3972d34ccc9e1d26c3b4bc05efb (diff) | |
download | hurrycurry-52d99b16534631e293a23ddbc18c4ea70b71392f.tar hurrycurry-52d99b16534631e293a23ddbc18c4ea70b71392f.tar.bz2 hurrycurry-52d99b16534631e293a23ddbc18c4ea70b71392f.tar.zst |
add recipes back to protocol
Diffstat (limited to 'server/src/interaction.rs')
-rw-r--r-- | server/src/interaction.rs | 83 |
1 files changed, 1 insertions, 82 deletions
diff --git a/server/src/interaction.rs b/server/src/interaction.rs index 71125ac4..4630b536 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -19,89 +19,8 @@ use crate::{ data::Gamedata, game::{Involvement, Item}, }; -use hurrycurry_protocol::{ItemIndex, Score, TileIndex}; +use hurrycurry_protocol::{Recipe, Score, TileIndex}; use log::info; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub enum Recipe { - Passive { - duration: f32, - revert_duration: Option<f32>, - tile: Option<TileIndex>, - input: ItemIndex, - output: Option<ItemIndex>, - warn: bool, - }, - Active { - duration: f32, - tile: Option<TileIndex>, - input: ItemIndex, - outputs: [Option<ItemIndex>; 2], - }, - Instant { - tile: Option<TileIndex>, - inputs: [Option<ItemIndex>; 2], - outputs: [Option<ItemIndex>; 2], - points: i64, - }, -} - -impl Recipe { - pub fn tile(&self) -> Option<TileIndex> { - match self { - Recipe::Passive { tile, .. } => *tile, - Recipe::Active { tile, .. } => *tile, - Recipe::Instant { tile, .. } => *tile, - } - } - pub fn duration(&self) -> Option<f32> { - match self { - Recipe::Passive { duration, .. } => Some(*duration), - Recipe::Active { duration, .. } => Some(*duration), - _ => None, - } - } - pub fn revert_duration(&self) -> Option<f32> { - match self { - Recipe::Passive { - revert_duration, .. - } => *revert_duration, - _ => None, - } - } - pub fn warn(&self) -> bool { - match self { - Recipe::Passive { warn, .. } => *warn, - _ => false, - } - } - pub fn inputs(&self) -> Vec<ItemIndex> { - match self { - Recipe::Passive { input, .. } => vec![*input], - Recipe::Active { input, .. } => vec![*input], - Recipe::Instant { inputs, .. } => inputs.iter().flat_map(|e| e.to_owned()).collect(), - } - } - pub fn outputs(&self) -> Vec<ItemIndex> { - match self { - Recipe::Passive { output, .. } => output.iter().copied().collect(), - Recipe::Active { outputs, .. } => outputs.iter().flat_map(|e| e.to_owned()).collect(), - Recipe::Instant { outputs, .. } => outputs.iter().flat_map(|e| e.to_owned()).collect(), - } - } - pub fn supports_tile(&self, tile: Option<TileIndex>) -> bool { - if let Some(tile_constraint) = self.tile() { - if let Some(tile) = tile { - tile == tile_constraint - } else { - false - } - } else { - true - } - } -} pub enum InteractEffect { Put, |