From 92e437e50498f7705e33a556535ba39a2b918f9d Mon Sep 17 00:00:00 2001 From: troido Date: Mon, 21 Sep 2020 00:59:38 +0200 Subject: made talk and reply a form of interact again --- content/encyclopediae/default_encyclopedia.json | 2 +- content/encyclopediae/npcs.json | 2 +- src/components/interactable.rs | 16 ++++++++-------- src/components/mod.rs | 2 +- src/componentwrapper.rs | 1 - src/room.rs | 6 ++---- src/systems/interact.rs | 6 ++++++ src/systems/mod.rs | 2 -- 8 files changed, 19 insertions(+), 18 deletions(-) diff --git a/content/encyclopediae/default_encyclopedia.json b/content/encyclopediae/default_encyclopedia.json index 9a9b526..d4f7094 100644 --- a/content/encyclopediae/default_encyclopedia.json +++ b/content/encyclopediae/default_encyclopedia.json @@ -87,7 +87,7 @@ "height": 1, "flags": ["Occupied"], "components": [ - ["Talkable", {"text": "Good morning there, World"}] + ["Interactable", {"typ": "say", "arg": "Good morning there, World"}] ] }, "quarry": { diff --git a/content/encyclopediae/npcs.json b/content/encyclopediae/npcs.json index 78dda29..661c80d 100644 --- a/content/encyclopediae/npcs.json +++ b/content/encyclopediae/npcs.json @@ -79,7 +79,7 @@ "height": 1.5, "flags": ["Occupied"], "components": [ - ["Talkable", {"text": "Hey there, welcome to Asciifarm"}] + ["Interactable", {"typ": "say", "arg": "Hey there, welcome to Asciifarm"}] ] }, "trader": { diff --git a/src/components/interactable.rs b/src/components/interactable.rs index ec8c1db..2e286cf 100644 --- a/src/components/interactable.rs +++ b/src/components/interactable.rs @@ -16,7 +16,9 @@ use crate::{ pub enum Interactable { Trigger(Trigger), Visit(RoomId), - Mine(Stat) + Mine(Stat), + Say(String), + Reply(String) } use Interactable::*; @@ -28,6 +30,8 @@ impl Interactable { ("trigger", Parameter::String(s)) => Trigger(Trigger::from_str(s)?), ("visit", Parameter::String(s)) => Visit(RoomId::from_str(s)), ("mine", Parameter::String(s)) => Mine(Stat::from_str(s)?), + ("say", Parameter::String(s)) => Say(s.clone()), + ("reply", Parameter::String(s)) => Reply(s.clone()), _ => None? }) } @@ -42,17 +46,13 @@ impl Interactable { true } } - Mine(_) => arg.is_none() + Mine(_) => arg.is_none(), + Say(_) => arg.is_none(), + Reply(_) => arg.is_some(), } } } -#[derive(Component, Debug, Clone, PartialEq)] -#[storage(HashMapStorage)] -pub struct Talkable { - pub text: String -} - #[derive(Component, Debug, Clone, PartialEq)] #[storage(HashMapStorage)] diff --git a/src/components/mod.rs b/src/components/mod.rs index 68e666c..f315060 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -16,7 +16,7 @@ pub use messages::{ TriggerBox }; pub use faction::Faction; -pub use interactable::{Interactable, Talkable, Exchanger}; +pub use interactable::{Interactable, Exchanger}; pub use equipment::Equipment; pub use inventory::Inventory; pub use serialise::Serialise; diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index 62e090e..96cedd3 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -234,7 +234,6 @@ components!(all: } }; Substitute (into: Template); - Talkable (text: String); Exchanger (prefix: String, exchanges: Vec<(String, Vec, Vec)>) { Exchanger { prefix, diff --git a/src/room.rs b/src/room.rs index 9034e9e..04e3044 100644 --- a/src/room.rs +++ b/src/room.rs @@ -71,7 +71,6 @@ use crate::{ Deduplicate, SpawnTrigger, Replace, - Talk, Exchange } }; @@ -88,14 +87,13 @@ pub fn default_dispatcher<'a, 'b>() -> Dispatcher<'a, 'b> { .with(Take, "take", &["controlinput", "controlai"]) .with(Use, "use", &["controlinput", "controlai"]) .with(Interact, "interact", &["controlinput", "controlai"]) - .with(Talk, "talk", &["controlinput", "controlai"]) .with(Exchange, "exchange", &["controlinput", "controlai"]) .with(SpawnTrigger, "spawntrigger", &["spawn", "deduplicate", "replace"]) .with(Move, "move", &["controlinput", "controlai"]) .with(Trapping, "trapping", &["move"]) .with(Fight, "fight", &["move"]) .with(Heal, "heal", &[]) - .with(Attacking, "attacking", &["use", "trapping", "fight", "heal", "interact", "talk", "exchange", "spawntrigger"]) + .with(Attacking, "attacking", &["use", "trapping", "fight", "heal", "interact", "exchange", "spawntrigger"]) .with(Die, "die", &["attacking"]) .with(DropLoot, "droploot", &["attacking"]) .with(Building, "building", &["attacking"]) @@ -129,7 +127,7 @@ impl <'a, 'b>Room<'a, 'b> { 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, Home, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Timer, Equipment, TimeOffset, Flags, Ear, Build, Whitelist, Dedup, Minable, LootHolder, OnSpawn, Substitute, Talkable, Exchanger), + (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, Exchanger), (Ground, Input, Output, Size, Spawn, Players, Emigration, Time, RoomPermissions) ); diff --git a/src/systems/interact.rs b/src/systems/interact.rs index bce2afc..35c30b6 100644 --- a/src/systems/interact.rs +++ b/src/systems/interact.rs @@ -73,6 +73,12 @@ impl <'a> System<'a> for Interact { let mut cooldown = 2; let name = visibles.get(ent).map(|v| v.name.as_str()); match interactable { + Interactable::Say(text) => { + say(ear, text.clone(), name); + } + Interactable::Reply(text) => { + say(ear, text.replace("{}", &arg.unwrap()), name); + } Interactable::Trigger(trigger) => { TriggerBox::add_message(&mut triggerbox, ent, *trigger); } diff --git a/src/systems/mod.rs b/src/systems/mod.rs index 76e39ce..963cfa6 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -24,7 +24,6 @@ mod building; mod deduplicate; mod spawntrigger; mod replace; -mod talk; mod exchange; pub use self::{ @@ -53,6 +52,5 @@ pub use self::{ deduplicate::Deduplicate, spawntrigger::SpawnTrigger, replace::Replace, - talk::Talk, exchange::Exchange }; -- cgit