From 18534b727385c0a276682a20ce992766f2dc039f Mon Sep 17 00:00:00 2001 From: Patrick Owen Date: Sun, 23 Jun 2024 15:30:16 -0400 Subject: [PATCH] Hide gameplay features behind a flag Gameplay features, such as an inventory and the need to collect resources, can unnecessarily restrict creative freedom, so while gameplay features are being developed, it would be good to keep them behind a flag to avoid interrupting people who just want to build. --- client/src/graphics/gui.rs | 10 ++++++-- client/src/sim.rs | 2 +- common/src/sim_config.rs | 4 ++++ server/src/sim.rs | 48 ++++++++++++++++++++------------------ 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/client/src/graphics/gui.rs b/client/src/graphics/gui.rs index 99602ccc..00d45f03 100644 --- a/client/src/graphics/gui.rs +++ b/client/src/graphics/gui.rs @@ -32,11 +32,17 @@ impl GuiState { align(Alignment::TOP_LEFT, || { pad(Pad::all(8.0), || { colored_box_container(Color::BLACK.with_alpha(0.7), || { + let material_count_string = if sim.cfg.gameplay_enabled { + sim.inventory_contents_matching_material(sim.selected_material()) + .len() + .to_string() + } else { + "\u{221E}".to_string() // \u{221E} is the infinity synbol + }; label(format!( "Selected material: {:?} (\u{00D7}{})", // \u{00D7} is the multiplication synbol sim.selected_material(), - sim.inventory_contents_matching_material(sim.selected_material()) - .len() + material_count_string )); }); }); diff --git a/client/src/sim.rs b/client/src/sim.rs index 87c39fb4..de9cfa3b 100644 --- a/client/src/sim.rs +++ b/client/src/sim.rs @@ -559,7 +559,7 @@ impl Sim { Material::Void }; - let consumed_entity = if placing { + let consumed_entity = if placing && self.cfg.gameplay_enabled { Some( *self .inventory_contents_matching_material(material) diff --git a/common/src/sim_config.rs b/common/src/sim_config.rs index b1d98f40..f35c1abd 100644 --- a/common/src/sim_config.rs +++ b/common/src/sim_config.rs @@ -13,6 +13,8 @@ pub struct SimConfigRaw { /// Maximum distance at which anything can be seen in meters pub view_distance: Option, pub input_queue_size_ms: Option, + /// Whether gameplay-like restrictions exist, such as limited inventory + pub gameplay_enabled: Option, /// Number of voxels along the edge of a chunk pub chunk_size: Option, /// Approximate length of the edge of a voxel in meters @@ -37,6 +39,7 @@ pub struct SimConfig { pub view_distance: f32, pub input_queue_size: Duration, pub chunk_size: u8, + pub gameplay_enabled: bool, pub character: CharacterConfig, /// Scaling factor converting meters to absolute units pub meters_to_absolute: f32, @@ -52,6 +55,7 @@ impl SimConfig { view_distance: x.view_distance.unwrap_or(90.0) * meters_to_absolute, input_queue_size: Duration::from_millis(x.input_queue_size_ms.unwrap_or(50).into()), chunk_size, + gameplay_enabled: x.gameplay_enabled.unwrap_or(false), character: CharacterConfig::from_raw(&x.character, meters_to_absolute), meters_to_absolute, } diff --git a/server/src/sim.rs b/server/src/sim.rs index 19aae18b..b11c06c6 100644 --- a/server/src/sim.rs +++ b/server/src/sim.rs @@ -489,30 +489,32 @@ impl Sim { tracing::warn!("Block update received from ungenerated chunk"); return; }; - if block_update.new_material != Material::Void { - let Some(consumed_entity_id) = block_update.consumed_entity else { - tracing::warn!("Tried to place block without consuming any entities"); - return; - }; - if !self.is_in_inventory(subject, consumed_entity_id) { - tracing::warn!("Tried to consume entity not in player inventory"); - return; - }; - let consumed_entity = *self.entity_ids.get(&consumed_entity_id).unwrap(); - if !self - .world - .get::<&Material>(consumed_entity) - .is_ok_and(|m| *m == block_update.new_material) - { - tracing::warn!("Tried to consume wrong material"); - return; + if self.cfg.gameplay_enabled { + if block_update.new_material != Material::Void { + let Some(consumed_entity_id) = block_update.consumed_entity else { + tracing::warn!("Tried to place block without consuming any entities"); + return; + }; + if !self.is_in_inventory(subject, consumed_entity_id) { + tracing::warn!("Tried to consume entity not in player inventory"); + return; + }; + let consumed_entity = *self.entity_ids.get(&consumed_entity_id).unwrap(); + if !self + .world + .get::<&Material>(consumed_entity) + .is_ok_and(|m| *m == block_update.new_material) + { + tracing::warn!("Tried to consume wrong material"); + return; + } + self.remove_from_inventory(subject, consumed_entity_id); + self.destroy(consumed_entity); + } + if old_material != Material::Void { + let (produced_entity, _) = self.spawn((old_material,)); + self.add_to_inventory(subject, produced_entity); } - self.remove_from_inventory(subject, consumed_entity_id); - self.destroy(consumed_entity); - } - if old_material != Material::Void { - let (produced_entity, _) = self.spawn((old_material,)); - self.add_to_inventory(subject, produced_entity); } assert!(self.graph.update_block(&block_update)); self.modified_chunks.insert(block_update.chunk_id);