diff options
| author | troido <troido@protonmail.com> | 2020-09-26 00:05:03 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-09-26 00:05:03 +0200 |
| commit | 345251f20401a71f7e7e00f4810b92af39ad4395 (patch) | |
| tree | 4f1f64a4f09e81fb98bb786865d5164048440321 /src | |
| parent | 9e2aa0f98cb93ea79db023f1309e083e59192293 (diff) | |
use flags for the whole room instead of room permissions
the flags on a tile are the union of the flags from the entity on that tile and the room flags
Diffstat (limited to 'src')
| -rw-r--r-- | src/parameterexpression.rs | 2 | ||||
| -rw-r--r-- | src/resources/mod.rs | 5 | ||||
| -rw-r--r-- | src/resources/roompermissions.rs | 8 | ||||
| -rw-r--r-- | src/room.rs | 6 | ||||
| -rw-r--r-- | src/roomtemplate.rs | 8 | ||||
| -rw-r--r-- | src/systems/useitem.rs | 14 |
6 files changed, 18 insertions, 25 deletions
diff --git a/src/parameterexpression.rs b/src/parameterexpression.rs index 0ad40b8..b8d1cba 100644 --- a/src/parameterexpression.rs +++ b/src/parameterexpression.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use rand::Rng; use serde_json::{Value, json}; -use serde::{Deserialize, Deserializer, de, Serialize}; +use serde::{Deserialize, Deserializer, de}; use crate::{ parameter::{Parameter, ParameterType}, Template, diff --git a/src/resources/mod.rs b/src/resources/mod.rs index 025bc6e..b65ca86 100644 --- a/src/resources/mod.rs +++ b/src/resources/mod.rs @@ -1,13 +1,12 @@ mod ground; mod newentities; -mod roompermissions; pub use ground::Ground; pub use newentities::NewEntities; -pub use roompermissions::RoomPermissions; use std::collections::{HashMap, HashSet}; +use serde::{Serialize, Deserialize}; use specs::{Entity}; use crate::{ @@ -59,6 +58,6 @@ pub struct Time { pub time: Timestamp } -#[derive(Default, Debug, Clone)] +#[derive(Default, Debug, Clone, Serialize, Deserialize)] pub struct RoomFlags(pub HashSet<Flag>); diff --git a/src/resources/roompermissions.rs b/src/resources/roompermissions.rs deleted file mode 100644 index e3646f3..0000000 --- a/src/resources/roompermissions.rs +++ /dev/null @@ -1,8 +0,0 @@ - -use serde::{Deserialize, Serialize}; - -#[derive(Default, Debug, Clone, Deserialize, Serialize)] -pub struct RoomPermissions { - #[serde(default)] - pub build: bool -} diff --git a/src/room.rs b/src/room.rs index 6100ce1..db2171a 100644 --- a/src/room.rs +++ b/src/room.rs @@ -23,7 +23,7 @@ use crate::{ Players, Emigration, Time, - RoomPermissions + RoomFlags }, components::{ Position, @@ -126,7 +126,7 @@ impl <'a, 'b>Room<'a, 'b> { register_insert!( world, (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, TriggerBox, Trap, Fighter, Healing, ControlCooldown, Autofight, MonsterAI, Home, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Timer, Equipment, TimeOffset, Flags, Ear, Build, Whitelist, Dedup, Minable, LootHolder, OnSpawn, Substitute), - (Ground, Input, Output, Size, Spawn, Players, Emigration, Time, RoomPermissions) + (Ground, Input, Output, Size, Spawn, Players, Emigration, Time, RoomFlags) ); Room { @@ -144,7 +144,7 @@ impl <'a, 'b>Room<'a, 'b> { self.world.fetch_mut::<Size>().height = height; self.world.fetch_mut::<SpawnPosition>().pos = template.spawn; - self.world.insert::<RoomPermissions>(template.permissions.clone()); + self.world.insert::<RoomFlags>(template.flags.clone()); for (idx, templates) in template.field.iter().enumerate() { let x = (idx as i64) % width; diff --git a/src/roomtemplate.rs b/src/roomtemplate.rs index b9bb0e1..1b920ac 100644 --- a/src/roomtemplate.rs +++ b/src/roomtemplate.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Deserializer, de, Serialize}; use crate::{ Pos, Template, - resources::RoomPermissions + resources::RoomFlags }; #[derive(Debug, Clone)] @@ -13,7 +13,7 @@ pub struct RoomTemplate { pub spawn: Pos, pub field: Vec<Vec<Template>>, pub places: HashMap<String, Pos>, - pub permissions: RoomPermissions + pub flags: RoomFlags } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -26,7 +26,7 @@ struct RoomTemplateSave { #[serde(default)] pub places: HashMap<String, Pos>, #[serde(default)] - pub permissions: RoomPermissions + pub flags: RoomFlags } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(untagged)] @@ -57,7 +57,7 @@ impl<'de> Deserialize<'de> for RoomTemplate { spawn: rts.spawn, field, places: rts.places, - permissions: rts.permissions + flags: rts.flags }) } } diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs index 4927636..5a12b7e 100644 --- a/src/systems/useitem.rs +++ b/src/systems/useitem.rs @@ -1,4 +1,5 @@ +use std::collections::HashSet; use specs::{ Entities, @@ -18,9 +19,10 @@ use crate::{ AttackInbox, AttackMessage, AttackType, - Flags + Flags, + Flag }, - resources::{NewEntities, Ground, RoomPermissions}, + resources::{NewEntities, Ground, RoomFlags}, item::ItemAction::{None, Build, Eat, Equip}, controls::Control, }; @@ -37,17 +39,17 @@ impl <'a> System<'a> for Use { WriteStorage<'a, AttackInbox>, Write<'a, Ground>, ReadStorage<'a, Flags>, - Read<'a, RoomPermissions> + Read<'a, RoomFlags> ); - fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked, mut ground, flags, roompermissions): Self::SystemData) { + fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked, mut ground, flags, roomflags): Self::SystemData) { for (ent, controller, position, inventory) in (&entities, &controllers, &positions, &mut inventories).join(){ if let Control::Use(rank) = &controller.control { if let Some(entry) = inventory.items.get_mut(*rank) { match &entry.item.action { Build(template, required_flags, blocking_flags) => { - let ground_flags = ground.flags_on(position.pos, &flags); - if roompermissions.build && required_flags.is_subset(&ground_flags) && blocking_flags.is_disjoint(&ground_flags){ + let ground_flags: HashSet<Flag> = ground.flags_on(position.pos, &flags).union(&roomflags.0).cloned().collect(); + if required_flags.is_subset(&ground_flags) && blocking_flags.is_disjoint(&ground_flags){ new.create(position.pos, &template).unwrap(); inventory.items.remove(*rank); } |
