summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2021-12-30 21:20:46 +0100
committertroido <troido@protonmail.com>2021-12-30 21:20:46 +0100
commit755ae8512bfe3ff39a55c22a958e15399e886c5f (patch)
tree167b34f51071ee6ec915b787094c8dadef2d4dde
parentd10d3e0368bd1178085ab8abd2ea24afe912b26f (diff)
entities can now have descriptions
-rw-r--r--content/encyclopediae/base.json13
-rw-r--r--src/components/ear.rs11
-rw-r--r--src/components/mod.rs5
-rw-r--r--src/componentwrapper.rs3
-rw-r--r--src/controls.rs8
-rw-r--r--src/playerstate.rs6
-rw-r--r--src/room.rs4
-rw-r--r--src/systems/describe.rs50
-rw-r--r--src/systems/mod.rs4
9 files changed, 95 insertions, 9 deletions
diff --git a/content/encyclopediae/base.json b/content/encyclopediae/base.json
index 8052eb6..f022b82 100644
--- a/content/encyclopediae/base.json
+++ b/content/encyclopediae/base.json
@@ -34,7 +34,8 @@
]},
"height": 0.1,
"name": "grass"
- }]
+ }],
+ ["Description", {"description": "grassy grass"}]
],
"flags": ["Floor", "Soil"]
},
@@ -55,12 +56,18 @@
"ground": {
"sprite": "ground",
"height": 0.1,
- "flags": ["Floor", "Soil"]
+ "flags": ["Floor", "Soil"],
+ "components": [
+ ["Description", {"description": "Dirt ground"}]
+ ]
},
"floor": {
"sprite": "floor",
"height": 0.1,
- "flags": ["Floor"]
+ "flags": ["Floor"],
+ "components": [
+ ["Description", {"description": "Stone floor"}]
+ ]
},
"bridge": {
"sprite": "bridge",
diff --git a/src/components/ear.rs b/src/components/ear.rs
index 6b723b0..6e832aa 100644
--- a/src/components/ear.rs
+++ b/src/components/ear.rs
@@ -40,6 +40,10 @@ pub enum Notification {
Options {
description: String,
options: Vec<(String, String)>
+ },
+ Describe{
+ name: String,
+ description: String
}
}
@@ -59,7 +63,8 @@ impl Notification {
},
Kill{actor: _, target: _} => "kill",
Die{actor: _, target: _} => "die",
- Options{description: _, options: _} => "options"
+ Options{description: _, options: _} => "options",
+ Describe{name: _, description: _} => "describe",
}).to_string()
}
@@ -91,6 +96,10 @@ impl Notification {
Options{description, options} => {(
format!("{}. Options: {}", description, options.iter().map(|(command, desc)| format!("'{}': {};", command, desc)).collect::<Vec<String>>().join(" ")),
json!({"description": description.clone(), "options": options.clone()})
+ )},
+ Describe{name, description} => {(
+ format!("{} - {}", name, description),
+ json!({"description": description.clone(), "name": name.clone()})
)}
};
(self.type_name(), body, payload)
diff --git a/src/components/mod.rs b/src/components/mod.rs
index d462fef..4c2ccf4 100644
--- a/src/components/mod.rs
+++ b/src/components/mod.rs
@@ -264,3 +264,8 @@ pub struct Requirements {
pub required_flags: HashSet<Flag>,
pub blocking_flags: HashSet<Flag>
}
+
+#[derive(Component, Debug, Clone)]
+pub struct Description {
+ pub description: String
+}
diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs
index a45f3c0..af24c7b 100644
--- a/src/componentwrapper.rs
+++ b/src/componentwrapper.rs
@@ -46,7 +46,7 @@ macro_rules! components {
}
}
pub fn load_component(comptype: ComponentType, mut parameters: HashMap<&str, Parameter>) -> Result<Self> {
- #[allow(unused_imports, unreachable_code)]
+ #[allow(unused_imports, unreachable_code, unused_braces)]
match comptype {
$(
ComponentType::$comp => Ok(Self::$comp({
@@ -213,6 +213,7 @@ components!(all:
};
Stats (skills: HashMap<Stat, i64>);
Requirements (required_flags: HashSet<Flag>, blocking_flags: HashSet<Flag>);
+ Description (description: String);
);
diff --git a/src/controls.rs b/src/controls.rs
index ca1ed8e..38611aa 100644
--- a/src/controls.rs
+++ b/src/controls.rs
@@ -8,9 +8,13 @@ use crate::{PlayerId, Pos};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all="lowercase")]
pub enum Direction {
+ #[serde(alias="n")]
North,
+ #[serde(alias="s")]
South,
+ #[serde(alias="e")]
East,
+ #[serde(alias="w")]
West,
#[serde(alias="")]
None
@@ -38,6 +42,7 @@ pub enum Control {
Attack(Vec<Direction>),
AttackTarget(Entity),
Interact(Vec<Direction>, Option<String>),
+ Describe(Direction)
}
@@ -85,6 +90,9 @@ impl Control {
None
}
)),
+ "describe" => Some(Control::Describe(
+ Direction::deserialize(val.get(1)?).ok()?
+ )),
_ => None
}
} else {None}
diff --git a/src/playerstate.rs b/src/playerstate.rs
index 2bc0456..0d5505a 100644
--- a/src/playerstate.rs
+++ b/src/playerstate.rs
@@ -21,7 +21,8 @@ use crate::{
Slot,
Ear,
Stats,
- Stat
+ Stat,
+ Description
},
Result,
aerr,
@@ -99,7 +100,8 @@ impl PlayerState {
ComponentWrapper::Autofight(Autofight::default()),
ComponentWrapper::Faction(Faction::Good),
ComponentWrapper::Ear(Ear::default()),
- ComponentWrapper::Stats(Stats{skills: hashmap!{Stat::Gathering => 10}})
+ ComponentWrapper::Stats(Stats{skills: hashmap!{Stat::Gathering => 10}}),
+ ComponentWrapper::Description(Description{description: format!("a player named {}", self.id.0)})
])
}
}
diff --git a/src/room.rs b/src/room.rs
index e629791..f6e2613 100644
--- a/src/room.rs
+++ b/src/room.rs
@@ -70,6 +70,7 @@ use crate::{
SpawnTrigger,
Replace,
SpawnCheck,
+ Describe
}
};
@@ -106,7 +107,7 @@ impl Room {
world.insert(NewEntities::new(encyclopedia));
register_insert!(
world,
- (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, TriggerBox, Trap, Fighter, Healing, ControlCooldown, Autofight, MonsterAI, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Timer, TimeOffset, Flags, Ear, Build, Whitelist, Minable, LootHolder, OnSpawn, Substitute, Stats, Requirements),
+ (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, TriggerBox, Trap, Fighter, Healing, ControlCooldown, Autofight, MonsterAI, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Timer, TimeOffset, Flags, Ear, Build, Whitelist, Minable, LootHolder, OnSpawn, Substitute, Stats, Requirements, Description),
(Ground, Input, Output, Size, Spawn, Players, Emigration, Time, RoomFlags)
);
@@ -156,6 +157,7 @@ impl Room {
SpawnCheck.run_now(&self.world);
ControlInput.run_now(&self.world);
ControlAI.run_now(&self.world);
+ Describe.run_now(&self.world);
Take.run_now(&self.world);
Use.run_now(&self.world);
Interact.run_now(&self.world);
diff --git a/src/systems/describe.rs b/src/systems/describe.rs
new file mode 100644
index 0000000..7ebb34f
--- /dev/null
+++ b/src/systems/describe.rs
@@ -0,0 +1,50 @@
+
+use specs::{
+ ReadStorage,
+ WriteStorage,
+ System,
+ Join,
+ Read
+};
+
+use crate::components::{
+ Controller,
+ Position,
+ Description,
+ Visible,
+ Ear,
+ ear::Notification,
+};
+
+use crate::controls::{Control};
+use crate::resources::{Ground};
+
+
+
+pub struct Describe;
+impl <'a> System<'a> for Describe {
+ type SystemData = (
+ ReadStorage<'a, Controller>,
+ ReadStorage<'a, Position>,
+ ReadStorage<'a, Visible>,
+ ReadStorage<'a, Description>,
+ Read<'a, Ground>,
+ WriteStorage<'a, Ear>,
+ );
+
+ fn run(&mut self, (controllers, positions, visibles, descriptions, ground, mut ears): Self::SystemData) {
+ for (controller, position, ear) in (&controllers, &positions, &mut ears).join(){
+ match &controller.control {
+ Control::Describe(direction) => {
+ for entity in ground.by_height(&(position.pos + direction.to_position()), &visibles) {
+ let name = visibles.get(entity).unwrap().name.clone();
+ let description = descriptions.get(entity).map(|d| d.description.clone()).unwrap_or("".to_string());
+ ear.sounds.push(Notification::Describe{name, description});
+ }
+ }
+ _ => {}
+ }
+ }
+ }
+
+}
diff --git a/src/systems/mod.rs b/src/systems/mod.rs
index 598feaa..66258a4 100644
--- a/src/systems/mod.rs
+++ b/src/systems/mod.rs
@@ -24,6 +24,7 @@ mod building;
mod spawntrigger;
mod replace;
mod spawncheck;
+mod describe;
pub use self::{
controlinput::ControlInput,
@@ -50,5 +51,6 @@ pub use self::{
building::Building,
spawntrigger::SpawnTrigger,
replace::Replace,
- spawncheck::SpawnCheck
+ spawncheck::SpawnCheck,
+ describe::Describe
};