summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-09-26 00:05:03 +0200
committertroido <troido@protonmail.com>2020-09-26 00:05:03 +0200
commit345251f20401a71f7e7e00f4810b92af39ad4395 (patch)
tree4f1f64a4f09e81fb98bb786865d5164048440321
parent9e2aa0f98cb93ea79db023f1309e083e59192293 (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
-rw-r--r--content/encyclopediae/default_encyclopedia.json2
-rw-r--r--content/maps/_home.json2
-rw-r--r--content/maps/begin.json2
-rw-r--r--content/maps/broom.json2
-rw-r--r--src/parameterexpression.rs2
-rw-r--r--src/resources/mod.rs5
-rw-r--r--src/resources/roompermissions.rs8
-rw-r--r--src/room.rs6
-rw-r--r--src/roomtemplate.rs8
-rw-r--r--src/systems/useitem.rs14
10 files changed, 22 insertions, 29 deletions
diff --git a/content/encyclopediae/default_encyclopedia.json b/content/encyclopediae/default_encyclopedia.json
index 9de0470..2c88f45 100644
--- a/content/encyclopediae/default_encyclopedia.json
+++ b/content/encyclopediae/default_encyclopedia.json
@@ -155,7 +155,7 @@
},
"items": {
"pebble": {},
- "stone": {"action": {"build": ["builtwall", ["Floor"], ["Blocking"]]}},
+ "stone": {"action": {"build": ["builtwall", ["Floor", "Build"], ["Blocking"]]}},
"sword": {"action": {"equip": {
"slot": "hand",
"stats": {"strength": 5}
diff --git a/content/maps/_home.json b/content/maps/_home.json
index 10a43b0..7d67c85 100644
--- a/content/maps/_home.json
+++ b/content/maps/_home.json
@@ -2,7 +2,7 @@
"width": 64,
"height": 64,
"spawn": [0,0],
- "permissions": {"build": true},
+ "flags": ["Build"],
"places": {},
"field":[
"%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,",
diff --git a/content/maps/begin.json b/content/maps/begin.json
index 0a7e236..e01e866 100644
--- a/content/maps/begin.json
+++ b/content/maps/begin.json
@@ -2,7 +2,7 @@
"width": 126,
"height": 64,
"spawn": [15, 30],
- "permissions": {"build": true},
+ "flags": ["Build"],
"places": {
"stairdown": [37, 33],
"caveentrance": [31, 50],
diff --git a/content/maps/broom.json b/content/maps/broom.json
index ed7e7ca..6effa07 100644
--- a/content/maps/broom.json
+++ b/content/maps/broom.json
@@ -2,7 +2,7 @@
"width": 42,
"height": 23,
"spawn": [5, 15],
- "permissions": {"build": true},
+ "flags": ["Build"],
"places": {
"northentry": [6, 1]
},
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);
}