aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/Cargo.toml1
-rw-r--r--server/src/bin/graph.rs38
-rw-r--r--server/src/data.rs4
-rw-r--r--server/src/interaction.rs20
-rw-r--r--server/src/lib.rs17
-rw-r--r--server/src/main.rs11
6 files changed, 78 insertions, 13 deletions
diff --git a/server/Cargo.toml b/server/Cargo.toml
index 535d5a1e..23a34d99 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -2,6 +2,7 @@
name = "undercooked"
version = "0.1.0"
edition = "2021"
+default-run = "undercooked"
[dependencies]
glam = { version = "0.28.0", features = ["serde"] }
diff --git a/server/src/bin/graph.rs b/server/src/bin/graph.rs
new file mode 100644
index 00000000..9ff6f973
--- /dev/null
+++ b/server/src/bin/graph.rs
@@ -0,0 +1,38 @@
+use undercooked::{
+ interaction::Recipe,
+ load_gamedata,
+ protocol::{ItemIndex, RecipeIndex},
+};
+
+fn main() {
+ let data = load_gamedata();
+
+ println!("digraph {{");
+
+ for i in 0..data.item_names.len() {
+ println!("i{i} [label=\"{}\"]", data.item_name(ItemIndex(i)))
+ }
+ for (RecipeIndex(ri), recipe) in data.recipes() {
+ println!(
+ "r{ri} [label=\"{}\\non {}\" shape=box color=gray fillcolor=gray style=filled]",
+ match recipe {
+ Recipe::Passive { .. } => "Passive",
+ Recipe::Active { .. } => "Active",
+ Recipe::Instant { .. } => "Instant",
+ },
+ if let Some(tile) = recipe.tile() {
+ data.tile_name(tile)
+ } else {
+ "anything"
+ }
+ );
+ for ItemIndex(input) in recipe.inputs() {
+ println!("i{input} -> r{ri}")
+ }
+ for ItemIndex(output) in recipe.outputs() {
+ println!("r{ri} -> i{output}")
+ }
+ }
+
+ println!("}}");
+}
diff --git a/server/src/data.rs b/server/src/data.rs
index e59b8b35..fd268cb5 100644
--- a/server/src/data.rs
+++ b/server/src/data.rs
@@ -52,8 +52,8 @@ pub struct Demand {
pub struct Gamedata {
recipes: Vec<Recipe>,
pub demands: Vec<Demand>,
- item_names: Vec<String>,
- tile_names: Vec<String>,
+ pub item_names: Vec<String>,
+ pub tile_names: Vec<String>,
#[serde(skip)]
pub initial_map: HashMap<IVec2, TileIndex>,
pub chef_spawn: Vec2,
diff --git a/server/src/interaction.rs b/server/src/interaction.rs
index a4b79bd0..93f54b2d 100644
--- a/server/src/interaction.rs
+++ b/server/src/interaction.rs
@@ -42,6 +42,26 @@ impl Recipe {
_ => None,
}
}
+ pub fn inputs(&self) -> Vec<ItemIndex> {
+ match self {
+ Recipe::Passive { input, .. } => vec![*input],
+ Recipe::Active { input, .. } => vec![*input],
+ Recipe::Instant { inputs, .. } => {
+ inputs.into_iter().flat_map(|e| e.to_owned()).collect()
+ }
+ }
+ }
+ pub fn outputs(&self) -> Vec<ItemIndex> {
+ match self {
+ Recipe::Passive { output, .. } => output.to_owned().into_iter().collect(),
+ Recipe::Active { outputs, .. } => {
+ outputs.into_iter().flat_map(|e| e.to_owned()).collect()
+ }
+ Recipe::Instant { outputs, .. } => {
+ outputs.into_iter().flat_map(|e| e.to_owned()).collect()
+ }
+ }
+ }
pub fn supports_tile(&self, tile: TileIndex) -> bool {
if let Some(tile_constraint) = self.tile() {
if tile != tile_constraint {
diff --git a/server/src/lib.rs b/server/src/lib.rs
index a326190d..2f677d7c 100644
--- a/server/src/lib.rs
+++ b/server/src/lib.rs
@@ -1,5 +1,16 @@
-pub mod game;
-pub mod protocol;
+use data::{build_gamedata, Gamedata};
+use std::fs::File;
+
+pub mod customer;
pub mod data;
+pub mod game;
pub mod interaction;
-pub mod customer;
+pub mod protocol;
+
+pub fn load_gamedata() -> Gamedata {
+ build_gamedata(
+ serde_yaml::from_reader(File::open("data/recipes.yaml").unwrap()).unwrap(),
+ serde_yaml::from_reader(File::open("data/map.yaml").unwrap()).unwrap(),
+ serde_yaml::from_reader(File::open("data/demands.yaml").unwrap()).unwrap(),
+ )
+}
diff --git a/server/src/main.rs b/server/src/main.rs
index 3af71e17..0f0bac5e 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -1,7 +1,7 @@
use anyhow::Result;
use futures_util::{SinkExt, StreamExt};
use log::{debug, info, warn};
-use std::{fs::File, sync::Arc, time::Duration};
+use std::{sync::Arc, time::Duration};
use tokio::{
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
net::TcpListener,
@@ -12,8 +12,8 @@ use tokio::{
use tokio_tungstenite::tungstenite::Message;
use undercooked::{
customer::customer,
- data::build_gamedata,
game::Game,
+ load_gamedata,
protocol::{PacketC, PacketS, PlayerID},
};
@@ -28,12 +28,7 @@ async fn main() -> Result<()> {
);
info!("listening for websockets on {}", ws_listener.local_addr()?);
- let data = build_gamedata(
- serde_yaml::from_reader(File::open("data/recipes.yaml").unwrap()).unwrap(),
- serde_yaml::from_reader(File::open("data/map.yaml").unwrap()).unwrap(),
- serde_yaml::from_reader(File::open("data/demands.yaml").unwrap()).unwrap(),
- );
-
+ let data = load_gamedata();
let game = Arc::new(RwLock::new(Game::new(data.into())));
let (tx, rx) = broadcast::channel::<PacketC>(1024);