diff options
| author | troido <troido@protonmail.com> | 2020-05-21 12:45:44 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-06-05 22:27:53 +0200 |
| commit | f47034bdf86e7ddc831ecb8f50689b9b07a0f6ca (patch) | |
| tree | 4a2f4f5bee8541c66b6ce6b53b08ef354d59472e | |
| parent | bd1da23cf18960b36f8683c09899044d64b4bd83 (diff) | |
actually added talk system and removed reply interaction
| -rw-r--r-- | content/encyclopediae/npcs.json | 2 | ||||
| -rw-r--r-- | content/maps/room.json | 3 | ||||
| -rw-r--r-- | src/components/interactable.rs | 6 | ||||
| -rw-r--r-- | src/systems/interact.rs | 6 | ||||
| -rw-r--r-- | src/systems/talk.rs | 56 |
5 files changed, 58 insertions, 15 deletions
diff --git a/content/encyclopediae/npcs.json b/content/encyclopediae/npcs.json index bfaa6fe..4b8fd39 100644 --- a/content/encyclopediae/npcs.json +++ b/content/encyclopediae/npcs.json @@ -79,7 +79,7 @@ "height": 1.5, "flags": ["Occupied"], "components": [ - ["Interactable", {"action": ["interaction", ["reply", "did you say '{}'?"]]}] + ["Talkable", {"text": "Hey there, welcome to Asciifarm"}] ] }, "trader": { diff --git a/content/maps/room.json b/content/maps/room.json index 74cfcc0..173f79e 100644 --- a/content/maps/room.json +++ b/content/maps/room.json @@ -13,7 +13,7 @@ " ~~,,,,.,,,,,,,,,,,~~~,,,,,,,,,,,,,,,,,,,,X", " X,,,,,.,,,,,,,,,,,~~~~,,,,,,T,,,,,,,,,,,,X", " X,,,,,.,,,,,,,,,,,,~~~,,,,,,,,,,,,,,,,,,,X", - " X,,,,,.,,,,,,,,,,,,~~~,,,,,T,,,,######,,,X", + " X,,,,,.,u,,,,,,,,,,~~~,,,,,T,,,,######,,,X", " X,,,,,.,,,,,,,,,,,,bbb,,,,,,,,,,#++++#,,,X", " X,,,t..............bbb..........D++++#,,,X", " X,,,,,.,,,,,,,,,,,,bbb,,,,,,,,,,#++++#,,,X", @@ -52,7 +52,6 @@ "u": ["ground", "dude"], "t": ["ground", "trader"], "P": ["ground", "pickaxe"], - "u": ["ground", "radishes"], "Q": "quarry", " ": [] } diff --git a/src/components/interactable.rs b/src/components/interactable.rs index 636953f..ab1ac29 100644 --- a/src/components/interactable.rs +++ b/src/components/interactable.rs @@ -17,8 +17,6 @@ use crate::{ #[storage(HashMapStorage)] pub enum Interactable { Trigger(Trigger), - Say(String), - Reply(String), Exchange(String, HashMap<String, Exchange>), Visit(RoomId), Mine(Stat) @@ -32,8 +30,6 @@ impl Interactable { let arg = val.get(1)?; Some(match typ.as_str()? { "trigger" => Trigger(Trigger::from_str(arg.as_str()?)?), - "say" => Say(arg.as_str()?.to_string()), - "reply" => Reply(arg.as_str()?.to_string()), "exchange" => { let (prefix, change) = serde_json::value::from_value::< (String, HashMap<String, (Vec<ItemId>, Vec<ItemId>)>) @@ -54,8 +50,6 @@ impl Interactable { pub fn accepts_arg(&self, arg: &Option<String>) -> bool { match self { Trigger(_) => arg.is_none(), - Say(_) => arg.is_none(), - Reply(_) => arg.is_some(), Exchange(prefix, _exchanges) => { if let Some(txt) = arg { txt.starts_with(prefix) diff --git a/src/systems/interact.rs b/src/systems/interact.rs index b377a7a..2090f6f 100644 --- a/src/systems/interact.rs +++ b/src/systems/interact.rs @@ -82,12 +82,6 @@ impl <'a> System<'a> for Interact { Interactable::Trigger(trigger) => { TriggerBox::add_message(&mut triggerbox, ent, *trigger); } - Interactable::Say(text) => { - say(ear, text.clone(), name); - } - Interactable::Reply(text) => { - say(ear, text.replace("{}", &arg.unwrap()), name); - } Interactable::Exchange(prefix, exchanges) => { if let Some(txt) = arg { if let (Some(inventory), Some(action)) = (inventories.get_mut(actor), strip_prefix(&txt, prefix)) { diff --git a/src/systems/talk.rs b/src/systems/talk.rs new file mode 100644 index 0000000..4bb898a --- /dev/null +++ b/src/systems/talk.rs @@ -0,0 +1,56 @@ + +use std::collections::HashSet; + +use specs::{ + ReadStorage, + WriteStorage, + System, + Join, + Read +}; + +use crate::{ + components::{ + Controller, + Position, + Talkable, + Notification, + Ear, + Visible + }, + controls::{Control}, + resources::{Ground}, +}; + +pub struct Talk; +impl <'a> System<'a> for Talk { + type SystemData = ( + ReadStorage<'a, Controller>, + ReadStorage<'a, Position>, + Read<'a, Ground>, + ReadStorage<'a, Talkable>, + WriteStorage<'a, Ear>, + ReadStorage<'a, Visible> + ); + + fn run(&mut self, (controllers, positions, ground, talkables, mut ears, visibles): Self::SystemData) { + for (controller, position, ear) in (&controllers, &positions, &mut ears).join(){ + match &controller.control { + Control::Interact(directions, None) => { + 'targets: for direction in directions { + let pos = position.pos + direction.to_position(); + for ent in ground.cells.get(&pos).unwrap_or(&HashSet::new()) { + if let Some(Talkable{text}) = talkables.get(*ent) { + let name = visibles.get(*ent).map(|v| v.name.clone()); + ear.sounds.push(Notification::Sound{text: text.clone(), source: name}); + break 'targets; + } + } + } + } + _ => {} + } + } + } +} + |
