summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-09-24 15:21:22 +0200
committermetamuffin <metamuffin@disroot.org>2024-09-24 15:21:22 +0200
commit277e87c244d003bee9374d71e678049c41e61e5b (patch)
tree3127d57c13ed40c007a870dba37e3d9faf4d5c99
parent75b3c33ed130eaacc2e962846d951ea6472c2ed7 (diff)
downloadhurrycurry-277e87c244d003bee9374d71e678049c41e61e5b.tar
hurrycurry-277e87c244d003bee9374d71e678049c41e61e5b.tar.bz2
hurrycurry-277e87c244d003bee9374d71e678049c41e61e5b.tar.zst
change some stuff regarding default timer for games
-rw-r--r--server/src/commands.rs5
-rw-r--r--server/src/data/mod.rs57
-rw-r--r--server/src/server.rs10
-rw-r--r--test-client/main.ts1
4 files changed, 36 insertions, 37 deletions
diff --git a/server/src/commands.rs b/server/src/commands.rs
index 6fd95eac..9d34c28c 100644
--- a/server/src/commands.rs
+++ b/server/src/commands.rs
@@ -35,8 +35,7 @@ enum Command {
#[arg(default_value = "junior")]
spec: String,
/// Duration in seconds
- #[arg(default_value = "420")]
- timer: u64,
+ timer: Option<u64>,
},
/// Shows the best entries of the scoreboard for this map.
#[clap(alias = "top5")]
@@ -146,7 +145,7 @@ impl Server {
.ok();
}
let data = self.index.generate(&spec).await?;
- self.load(data, Some(Duration::from_secs(timer)));
+ self.load(data, timer.map(Duration::from_secs));
}
Command::End => {
self.tx
diff --git a/server/src/data/mod.rs b/server/src/data/mod.rs
index 91b32a42..39684c6f 100644
--- a/server/src/data/mod.rs
+++ b/server/src/data/mod.rs
@@ -34,6 +34,7 @@ use std::{
path::PathBuf,
str::FromStr,
sync::{Mutex, RwLock},
+ time::Duration,
};
use tokio::fs::read_to_string;
@@ -48,44 +49,34 @@ pub enum RecipeDeclAction {
Demand,
}
+#[rustfmt::skip]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct RecipeDecl {
- #[serde(default)]
- tile: Option<String>,
- #[serde(default)]
- inputs: Vec<String>,
- #[serde(default)]
- outputs: Vec<String>,
- #[serde(default)]
- action: RecipeDeclAction,
- #[serde(default)]
- warn: bool,
- #[serde(default)]
- revert_duration: Option<f32>,
- #[serde(default)]
- duration: Option<f32>,
- #[serde(default)]
- points: Option<i64>,
+ #[serde(default)] tile: Option<String>,
+ #[serde(default)] inputs: Vec<String>,
+ #[serde(default)] outputs: Vec<String>,
+ #[serde(default)] action: RecipeDeclAction,
+ #[serde(default)] warn: bool,
+ #[serde(default)] revert_duration: Option<f32>,
+ #[serde(default)] duration: Option<f32>,
+ #[serde(default)] points: Option<i64>,
}
+#[rustfmt::skip]
#[derive(Debug, Clone, Deserialize)]
pub struct MapDecl {
- #[serde(default)]
- recipes: Option<String>,
+ #[serde(default)] recipes: Option<String>,
map: Vec<String>,
tiles: HashMap<char, String>,
- #[serde(default)]
- items: HashMap<char, String>,
+ #[serde(default)] items: HashMap<char, String>,
collider: Vec<String>,
walkable: Vec<String>,
chef_spawn: char,
customer_spawn: char,
- #[serde(default)]
- entities: Vec<EntityDecl>,
- #[serde(default)]
- tile_entities: HashMap<char, EntityDecl>,
- #[serde(default)]
- score_baseline: i64,
+ #[serde(default)] entities: Vec<EntityDecl>,
+ #[serde(default)] tile_entities: HashMap<char, EntityDecl>,
+ #[serde(default)] score_baseline: i64,
+ #[serde(default)] default_timer: Option<u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -103,6 +94,7 @@ pub struct Serverdata {
pub chef_spawn: Vec2,
pub customer_spawn: Vec2,
pub score_baseline: i64,
+ pub default_timer: Option<Duration>
}
#[derive(Debug, Deserialize, Default)]
@@ -150,11 +142,7 @@ impl DataIndex {
let map_in: MapDecl = serde_yml::from_str(&self.read_map(map).await?)?;
let recipes_in = serde_yml::from_str(
&self
- .read_recipes(
- map_in
- .recipes.as_deref()
- .unwrap_or("default"),
- )
+ .read_recipes(map_in.recipes.as_deref().unwrap_or("default"))
.await?,
)?;
build_data(&self.maps, map.to_string(), map_in, recipes_in)
@@ -293,6 +281,12 @@ pub fn build_data(
.map(|i| !map_in.collider.contains(i) && !map_in.walkable.contains(i))
.collect();
+ let default_timer = if map_name.ends_with("lobby") {
+ None
+ } else {
+ Some(Duration::from_secs(map_in.default_timer.unwrap_or(420)))
+ };
+
Ok((
Gamedata {
bot_algos,
@@ -309,6 +303,7 @@ pub fn build_data(
initial_map,
chef_spawn,
customer_spawn,
+ default_timer,
score_baseline: map_in.score_baseline,
},
entities,
diff --git a/server/src/server.rs b/server/src/server.rs
index 9ee98b97..5efddaa1 100644
--- a/server/src/server.rs
+++ b/server/src/server.rs
@@ -336,8 +336,12 @@ impl Server {
load_map: &mut None,
});
}
- self.game
- .load(gamedata, &serverdata, timer, &mut self.packet_out);
+ self.game.load(
+ gamedata,
+ &serverdata,
+ timer.or(serverdata.default_timer),
+ &mut self.packet_out,
+ );
self.gamedata_index.update(&self.game.data);
self.data = serverdata.into();
self.entities = entities;
@@ -697,7 +701,7 @@ impl Server {
});
if let Some(map) = load_map {
- return Some((map, Some(Duration::from_secs(300))));
+ return Some((map, None));
}
while let Some(p) = self.packet_loopback.pop_front() {
diff --git a/test-client/main.ts b/test-client/main.ts
index 605bca5e..a0386631 100644
--- a/test-client/main.ts
+++ b/test-client/main.ts
@@ -330,6 +330,7 @@ function keyboard(ev: KeyboardEvent, down: boolean) {
if (down && ev.code == "Numpad3") send({ player: my_id, type: "communicate", message: { text: "/start sophomore" } })
if (down && ev.code == "Numpad4") send({ player: my_id, type: "communicate", message: { text: "/start debug" } })
if (down && ev.code == "Numpad5") send({ player: my_id, type: "communicate", message: { text: "/start 5star" } })
+ if (down && ev.code == "Numpad6") send({ player: my_id, type: "communicate", message: { text: "/start campaign/lobby" } })
if (down && ev.code == "Numpad8") send({ player: my_id, type: "communicate", message: { text: "/start-tutorial plate:seared-patty,sliced-bun" } })
if (down && ev.code == "Numpad9") send({ player: my_id, type: "communicate", message: { text: "/start-tutorial plate:bun" } })
if (down && ev.code == "Numpad7") send({ player: my_id, type: "communicate", message: { text: "/end-tutorial" } })