From 21f794f84cdb5a5a11da093fad8729ff640096d4 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Fri, 26 Mar 2021 07:06:20 -0600 Subject: [PATCH] Use Depot instead of Store for BuildArea --- CHANGELOG.md | 3 +++ common/src/comp/inputs.rs | 2 +- common/src/depot.rs | 2 ++ common/sys/src/state.rs | 6 +++--- server/src/cmd.rs | 4 ++-- server/src/sys/msg/in_game.rs | 10 ++++------ 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36a1ad083b..649cd0c3f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,9 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - You can now jump out of rolls for a slight jump boost - Dungeons now have multiple kinds of stairs. - Trades now display item prices in tooltips. +- Admin designated build areas ### Changed +- Permission to build is no longer tied to being an admin + ### Removed ### Fixed diff --git a/common/src/comp/inputs.rs b/common/src/comp/inputs.rs index 541a45e502..822f8d5c9e 100644 --- a/common/src/comp/inputs.rs +++ b/common/src/comp/inputs.rs @@ -1,8 +1,8 @@ +use crate::depot::Id; use serde::{Deserialize, Serialize}; use specs::{Component, DerefFlaggedStorage}; use specs_idvs::IdvStorage; use vek::geom::Aabb; -use crate::store::Id; #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct CanBuild { diff --git a/common/src/depot.rs b/common/src/depot.rs index be828aa665..8ad8cd1707 100644 --- a/common/src/depot.rs +++ b/common/src/depot.rs @@ -1,3 +1,4 @@ +use serde::{Deserialize, Serialize}; use std::{ cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd}, fmt, hash, @@ -6,6 +7,7 @@ use std::{ }; /// Type safe index into Depot +#[derive(Deserialize, Serialize)] pub struct Id { idx: u32, gen: u32, diff --git a/common/sys/src/state.rs b/common/sys/src/state.rs index 74cea99be3..5f09492481 100644 --- a/common/sys/src/state.rs +++ b/common/sys/src/state.rs @@ -6,11 +6,11 @@ use crate::plugin::PluginMgr; use common::uid::UidAllocator; use common::{ comp, + depot::{Depot, Id}, event::{EventBus, LocalEvent, ServerEvent}, region::RegionMap, resources::{DeltaTime, GameMode, PlayerEntity, Time, TimeOfDay}, slowjob::SlowJobPool, - store::{Id, Store}, terrain::{Block, TerrainChunk, TerrainGrid}, time::DayPeriod, trade::Trades, @@ -42,14 +42,14 @@ const MAX_DELTA_TIME: f32 = 1.0; #[derive(Default)] pub struct BuildAreas { - pub areas: Store>, + pub areas: Depot>, pub area_names: HashMap>>, } impl BuildAreas { pub fn new() -> Self { Self { - areas: Store::default(), + areas: Depot::default(), area_names: HashMap::new(), } } diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 1c2fac7aeb..3f56194afa 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -1404,8 +1404,8 @@ fn handle_build_area_remove( let ecs = server.state.ecs(); let mut build_areas = ecs.write_resource::(); - let bb_id = match &build_areas.area_names.get(&area_name) { - Some(x) => *x.clone(), + let bb_id = match build_areas.area_names.get(&area_name) { + Some(x) => *x, None => { server.notify_client( client, diff --git a/server/src/sys/msg/in_game.rs b/server/src/sys/msg/in_game.rs index d6fe2f6366..01135133a5 100644 --- a/server/src/sys/msg/in_game.rs +++ b/server/src/sys/msg/in_game.rs @@ -106,10 +106,8 @@ impl Sys { if let Some(comp_can_build) = can_build.get(entity) { if comp_can_build.building_is_on { for area in comp_can_build.build_areas.iter() { - if build_areas.areas.contains(*area) { - println!("build area exists!"); - if build_areas.areas.get(*area).contains_point(pos) { - println!("got build area!"); + if let Some(aabb) = build_areas.areas.get(*area) { + if aabb.contains_point(pos) { if let Ok(block) = terrain.get(pos) { block_changes.set(pos, block.into_vacant()); } @@ -123,8 +121,8 @@ impl Sys { if let Some(comp_can_build) = can_build.get(entity) { if comp_can_build.building_is_on { for area in comp_can_build.build_areas.iter() { - if build_areas.areas.contains(*area) { - if build_areas.areas.get(*area).contains_point(pos) { + if let Some(aabb) = build_areas.areas.get(*area) { + if aabb.contains_point(pos) { block_changes.try_set(pos, block); } }