From 176e6bc6c4c29bea3be2aceca99743b997c76c97 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 6 Oct 2025 23:03:32 +0200 Subject: Move data code to own crate + general data refactor --- server/data/src/entities.rs | 99 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 server/data/src/entities.rs (limited to 'server/data/src/entities.rs') diff --git a/server/data/src/entities.rs b/server/data/src/entities.rs new file mode 100644 index 00000000..68dbe479 --- /dev/null +++ b/server/data/src/entities.rs @@ -0,0 +1,99 @@ +/* + Hurry Curry! - a game about cooking + Copyright (C) 2025 Hurry Curry! Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, version 3 of the License only. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +*/ + +use hurrycurry_protocol::glam::{IVec2, Vec2}; +use serde::{Deserialize, Serialize}; + +use crate::ItemTileRegistry; + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] +pub enum EntityDecl { + Conveyor { + from: IVec2, + to: IVec2, + speed: Option, + }, + ItemPortal { + from: IVec2, + to: IVec2, + }, + PlayerPortal { + from: Vec2, + to: Vec2, + }, + Customers { + scaling_factor: Option, + }, + Map { + name: String, + pos: Vec2, + }, + EnvironmentEffect(EnvironmentEffect), + Environment(Vec), + Gate { + condition: GateCondition, + pos: IVec2, + }, + Tram { + length: usize, + color: Option, + points: Vec, + spacing: f32, + smoothing: f32, + }, + Book { + pos: IVec2, + }, + Pedestrians { + spawn_delay: f32, + spawn_delay_stdev: Option, + speed: Option, + points: Vec, + }, +} + +impl EntityDecl { + pub(crate) fn run_register(&self, reg: &ItemTileRegistry) { + match self { + Self::Gate { .. } => drop(reg.register_tile("fence".into())), + Self::Customers { .. } => drop(reg.register_item("unknown-order".into())), + _ => (), + } + } +} + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub enum GateCondition { + All(Vec), + Any(Vec), + Stars(String, u8), +} + +#[derive(Clone, Debug, Deserialize, Serialize, Default)] +pub struct EnvironmentEffect { + pub name: String, + #[serde(default = "default_onoff")] + pub on: f32, + #[serde(default = "default_onoff")] + pub off: f32, +} +fn default_onoff() -> f32 { + 40. +} -- cgit v1.2.3-70-g09d2