aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-08-11 13:35:15 +0200
committermetamuffin <metamuffin@disroot.org>2024-08-11 13:35:15 +0200
commit52d99b16534631e293a23ddbc18c4ea70b71392f (patch)
treef596887a976540ab553e69105ab192cbbb2dd753 /server/src
parent63d5a3ff37d1e3972d34ccc9e1d26c3b4bc05efb (diff)
downloadhurrycurry-52d99b16534631e293a23ddbc18c4ea70b71392f.tar
hurrycurry-52d99b16534631e293a23ddbc18c4ea70b71392f.tar.bz2
hurrycurry-52d99b16534631e293a23ddbc18c4ea70b71392f.tar.zst
add recipes back to protocol
Diffstat (limited to 'server/src')
-rw-r--r--server/src/bin/graph.rs4
-rw-r--r--server/src/data.rs7
-rw-r--r--server/src/entity/customers/demands.rs3
-rw-r--r--server/src/entity/mod.rs4
-rw-r--r--server/src/game.rs1
-rw-r--r--server/src/interaction.rs83
6 files changed, 9 insertions, 93 deletions
diff --git a/server/src/bin/graph.rs b/server/src/bin/graph.rs
index 58cc1763..03a59e37 100644
--- a/server/src/bin/graph.rs
+++ b/server/src/bin/graph.rs
@@ -16,8 +16,8 @@
*/
use anyhow::{anyhow, Result};
-use hurrycurry_protocol::{ItemIndex, RecipeIndex};
-use hurrycurry_server::{data::DataIndex, interaction::Recipe};
+use hurrycurry_protocol::{ItemIndex, Recipe, RecipeIndex};
+use hurrycurry_server::data::DataIndex;
#[tokio::main]
async fn main() -> Result<()> {
diff --git a/server/src/data.rs b/server/src/data.rs
index 522df916..99cbaf9f 100644
--- a/server/src/data.rs
+++ b/server/src/data.rs
@@ -16,14 +16,11 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-use crate::{
- entity::{construct_entity, Entity, EntityDecl},
- interaction::Recipe,
-};
+use crate::entity::{construct_entity, Entity, EntityDecl};
use anyhow::{anyhow, bail, Result};
use hurrycurry_protocol::{
glam::{IVec2, Vec2},
- ItemIndex, MapMetadata, RecipeIndex, TileIndex,
+ ItemIndex, MapMetadata, Recipe, RecipeIndex, TileIndex,
};
use serde::{Deserialize, Serialize};
use std::{
diff --git a/server/src/entity/customers/demands.rs b/server/src/entity/customers/demands.rs
index 33557b50..176ca232 100644
--- a/server/src/entity/customers/demands.rs
+++ b/server/src/entity/customers/demands.rs
@@ -16,8 +16,7 @@
*/
use super::Demand;
-use crate::interaction::Recipe;
-use hurrycurry_protocol::{ItemIndex, TileIndex};
+use hurrycurry_protocol::{ItemIndex, Recipe, TileIndex};
use std::collections::{HashMap, HashSet};
pub fn generate_demands(
diff --git a/server/src/entity/mod.rs b/server/src/entity/mod.rs
index 81061bb5..94718dd1 100644
--- a/server/src/entity/mod.rs
+++ b/server/src/entity/mod.rs
@@ -21,14 +21,14 @@ pub mod environment_effect;
pub mod item_portal;
pub mod player_portal;
-use crate::{data::ItemTileRegistry, game::Game, interaction::Recipe};
+use crate::{data::ItemTileRegistry, game::Game};
use anyhow::{anyhow, Result};
use conveyor::Conveyor;
use customers::{demands::generate_demands, Customers};
use environment_effect::{EnvironmentController, EnvironmentEffect, EnvironmentEffectController};
use hurrycurry_protocol::{
glam::{IVec2, Vec2},
- ItemIndex, PacketC, TileIndex,
+ ItemIndex, PacketC, Recipe, TileIndex,
};
use item_portal::ItemPortal;
use player_portal::PlayerPortal;
diff --git a/server/src/game.rs b/server/src/game.rs
index 5af9658e..39cd61dc 100644
--- a/server/src/game.rs
+++ b/server/src/game.rs
@@ -199,6 +199,7 @@ impl Game {
let mut out = Vec::new();
out.push(PacketC::Data {
data: ClientGamedata {
+ recipes: self.data.recipes.clone(),
item_names: self.data.item_names.clone(),
tile_names: self.data.tile_names.clone(),
tile_collide: self.data.tile_collide.clone(),
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,