summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-05-19 10:40:22 +0200
committertroido <troido@protonmail.com>2020-05-19 10:40:22 +0200
commit0d382ea19f8f964c35761f6a3ff80bc9bfc25375 (patch)
tree051abe24e22edd6aa0c6b9a9efbd03b8c47ce260
parent78b079df5a26ce94142737605ec36ddde8310336 (diff)
add room build permissions to rooms
-rw-r--r--content/maps/_home.json1
-rw-r--r--content/maps/begin.json2
-rw-r--r--content/maps/broom.json1
-rw-r--r--content/maps/right.json1
-rw-r--r--src/resources/mod.rs3
-rw-r--r--src/resources/roompermissions.rs8
-rw-r--r--src/room.rs6
-rw-r--r--src/roomtemplate.rs18
-rw-r--r--src/systems/useitem.rs9
9 files changed, 38 insertions, 11 deletions
diff --git a/content/maps/_home.json b/content/maps/_home.json
index 13bbeb2..10a43b0 100644
--- a/content/maps/_home.json
+++ b/content/maps/_home.json
@@ -2,6 +2,7 @@
"width": 64,
"height": 64,
"spawn": [0,0],
+ "permissions": {"build": true},
"places": {},
"field":[
"%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,",
diff --git a/content/maps/begin.json b/content/maps/begin.json
index 7dc0856..10c68b6 100644
--- a/content/maps/begin.json
+++ b/content/maps/begin.json
@@ -2,6 +2,7 @@
"width": 64,
"height": 64,
"spawn": [15, 30],
+ "permissions": {"build": true},
"places": {
"stairdown": [37, 33],
"caveentrance": [31, 50],
@@ -16,7 +17,6 @@
-
",,,,,,,,,,,,,,,,,,,,,,,,,,,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ",
",,,,,,,,,,,,,,,,,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ",
",,,,,,,,,,,,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ",
diff --git a/content/maps/broom.json b/content/maps/broom.json
index c9f3762..38520d2 100644
--- a/content/maps/broom.json
+++ b/content/maps/broom.json
@@ -2,6 +2,7 @@
"width": 42,
"height": 23,
"spawn": [5, 15],
+ "permissions": {"build": true},
"places": {
"northentry": [6, 1]
},
diff --git a/content/maps/right.json b/content/maps/right.json
index 21cf1a0..27f13c0 100644
--- a/content/maps/right.json
+++ b/content/maps/right.json
@@ -2,6 +2,7 @@
"width": 64,
"height": 64,
"spawn": [10, 10],
+ "permissions": {"build": true},
"places": {
"left": [1, 12],
"bottomleft": [1, 39],
diff --git a/src/resources/mod.rs b/src/resources/mod.rs
index ae3f4e2..627a396 100644
--- a/src/resources/mod.rs
+++ b/src/resources/mod.rs
@@ -1,9 +1,11 @@
mod ground;
mod newentities;
+mod roompermissions;
pub use ground::Ground;
pub use newentities::NewEntities;
+pub use roompermissions::RoomPermissions;
use std::collections::{HashMap};
use specs::{Entity};
@@ -55,3 +57,4 @@ pub struct Emigration {
pub struct Time {
pub time: Timestamp
}
+
diff --git a/src/resources/roompermissions.rs b/src/resources/roompermissions.rs
new file mode 100644
index 0000000..e3646f3
--- /dev/null
+++ b/src/resources/roompermissions.rs
@@ -0,0 +1,8 @@
+
+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 d0f22df..0b8ee3b 100644
--- a/src/room.rs
+++ b/src/room.rs
@@ -22,7 +22,8 @@ use crate::{
Spawn as SpawnPosition,
Players,
Emigration,
- Time
+ Time,
+ RoomPermissions
},
components::{
Position,
@@ -125,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)
+ (Ground, Input, Output, Size, Spawn, Players, Emigration, Time, RoomPermissions)
);
Room {
@@ -143,6 +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());
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 d853b20..2614441 100644
--- a/src/roomtemplate.rs
+++ b/src/roomtemplate.rs
@@ -1,11 +1,12 @@
use std::collections::HashMap;
-use serde_json::{json, Value};
+use serde_json::{json, Value, value};
use crate::{
Pos,
Template,
PResult,
- perr
+ perr,
+ resources::RoomPermissions
};
#[derive(Debug, Clone)]
@@ -13,7 +14,8 @@ pub struct RoomTemplate {
pub size: (i64, i64),
pub spawn: Pos,
pub field: Vec<Vec<Template>>,
- pub places: HashMap<String, Pos>
+ pub places: HashMap<String, Pos>,
+ pub permissions: RoomPermissions
}
impl RoomTemplate {
@@ -54,11 +56,19 @@ impl RoomTemplate {
places.insert(name.to_string(), Pos::from_json(jsonpos).ok_or(perr!("pos of places invalid"))?);
}
+ let permissions: RoomPermissions = value::from_value::<RoomPermissions>(
+ jsonroom
+ .get("permissions")
+ .unwrap_or(&json!({}))
+ .clone()
+ ).map_err(|e| perr!("can't deserialise permissions: {:?}", e))?;
+
Ok(RoomTemplate {
size,
spawn,
field,
- places
+ places,
+ permissions
})
}
}
diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs
index 485b1da..a560c18 100644
--- a/src/systems/useitem.rs
+++ b/src/systems/useitem.rs
@@ -20,7 +20,7 @@ use crate::{
AttackType,
Flags
},
- resources::{NewEntities, Ground},
+ resources::{NewEntities, Ground, RoomPermissions},
item::ItemAction::{None, Build, Eat, Equip},
controls::Control,
};
@@ -36,10 +36,11 @@ impl <'a> System<'a> for Use {
Write<'a, NewEntities>,
WriteStorage<'a, AttackInbox>,
Read<'a, Ground>,
- ReadStorage<'a, Flags>
+ ReadStorage<'a, Flags>,
+ Read<'a, RoomPermissions>
);
- fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked, ground, flags): Self::SystemData) {
+ fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked, ground, flags, roompermissions): Self::SystemData) {
for (ent, controller, position, inventory) in (&entities, &controllers, &positions, &mut inventories).join(){
match &controller.control {
Control::Use(rank) => {
@@ -47,7 +48,7 @@ impl <'a> System<'a> for Use {
match &entry.item.action {
Build(template, required_flags, blocking_flags) => {
let ground_flags = ground.flags_on(position.pos, &flags);
- if required_flags.is_subset(&ground_flags) && blocking_flags.is_disjoint(&ground_flags){
+ if roompermissions.build && required_flags.is_subset(&ground_flags) && blocking_flags.is_disjoint(&ground_flags){
new.create(position.pos, &template).unwrap();
inventory.items.remove(*rank);
}