aboutsummaryrefslogtreecommitdiff
path: root/server/src/interaction.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/interaction.rs')
-rw-r--r--server/src/interaction.rs83
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,