diff options
| -rw-r--r-- | content/encyclopediae/default_encyclopedia.json | 4 | ||||
| -rw-r--r-- | src/componentparameter.rs | 1 | ||||
| -rw-r--r-- | src/components/interactable.rs | 6 | ||||
| -rw-r--r-- | src/components/mod.rs | 2 | ||||
| -rw-r--r-- | src/componentwrapper.rs | 12 | ||||
| -rw-r--r-- | src/room.rs | 8 | ||||
| -rw-r--r-- | src/systems/mod.rs | 4 |
7 files changed, 25 insertions, 12 deletions
diff --git a/content/encyclopediae/default_encyclopedia.json b/content/encyclopediae/default_encyclopedia.json index 18cf967..fdaa42f 100644 --- a/content/encyclopediae/default_encyclopedia.json +++ b/content/encyclopediae/default_encyclopedia.json @@ -22,7 +22,7 @@ "arguments": [["health", "int", 100]], "components": [ ["Health", {"health": ["arg", "health"], "maxhealth": 100}], - ["Loot", {"loot": ["list", [{"type": "stone"}]]}] + ["Loot", {"loot": ["list", [["list", [{"type": "stone"}, 1.0]]]]}] ], "sprite": "builtwall", "height": 2, @@ -87,7 +87,7 @@ "height": 1, "flags": ["Occupied"], "components": [ - ["Interactable", {"action": ["interaction", ["say", "Good morning there, World"]]}] + ["Talkable", {"text": "Good morning there, World"}] ] }, "quarry": { diff --git a/src/componentparameter.rs b/src/componentparameter.rs index 333c6e1..30a7d91 100644 --- a/src/componentparameter.rs +++ b/src/componentparameter.rs @@ -120,6 +120,7 @@ impl ComponentParameter { } } + #[allow(dead_code)] pub fn get_type(&self, arguments: &[(String, ParameterType, Option<Parameter>)]) -> Result<ParameterType>{ Ok(match self { Self::Constant(param) => param.paramtype(), diff --git a/src/components/interactable.rs b/src/components/interactable.rs index d97b742..636953f 100644 --- a/src/components/interactable.rs +++ b/src/components/interactable.rs @@ -74,3 +74,9 @@ impl Interactable { } } } + +#[derive(Component, Debug, Clone, PartialEq)] +#[storage(HashMapStorage)] +pub struct Talkable { + pub text: String +} diff --git a/src/components/mod.rs b/src/components/mod.rs index ee5176e..23f5488 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; +pub use interactable::{Interactable, Talkable}; pub use equipment::Equipment; pub use inventory::Inventory; pub use serialise::Serialise; diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index 2619d9c..e1b5bb8 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -50,12 +50,13 @@ macro_rules! components { ComponentType::$comp => Ok(Self::$comp({ use crate::components::$comp; $( - let $paramname = <$paramtype>::from_parameter( - parameters + let $paramname = { + let param = parameters .remove(stringify!($paramname)) - .ok_or(aerr!("required parameter '{}'not found", stringify!($paramname)))? - ) - .ok_or(aerr!("parameter {} is invalid type", stringify!($paramname)))?; + .ok_or(aerr!("required parameter '{}'not found", stringify!($paramname)))?; + <$paramtype>::from_parameter(param.clone()) + .ok_or(aerr!("parameter {} is invalid type: {:?} is not of type {}", stringify!($paramname), param, stringify!($paramtype)))? + }; )* $creation @@ -233,6 +234,7 @@ components!(all: } }; Substitute (into: Template); + Talkable (text: String); ); diff --git a/src/room.rs b/src/room.rs index 0b8ee3b..d39bdb1 100644 --- a/src/room.rs +++ b/src/room.rs @@ -70,7 +70,8 @@ use crate::{ Building, Deduplicate, SpawnTrigger, - Replace + Replace, + Talk } }; @@ -86,12 +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(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", "spawntrigger"]) + .with(Attacking, "attacking", &["use", "trapping", "fight", "heal", "interact", "talk", "spawntrigger"]) .with(Die, "die", &["attacking"]) .with(DropLoot, "droploot", &["attacking"]) .with(Building, "building", &["attacking"]) @@ -125,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), + (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), (Ground, Input, Output, Size, Spawn, Players, Emigration, Time, RoomPermissions) ); diff --git a/src/systems/mod.rs b/src/systems/mod.rs index 7323dee..56606e7 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -24,6 +24,7 @@ mod building; mod deduplicate; mod spawntrigger; mod replace; +mod talk; pub use self::{ controlinput::ControlInput, @@ -50,5 +51,6 @@ pub use self::{ building::Building, deduplicate::Deduplicate, spawntrigger::SpawnTrigger, - replace::Replace + replace::Replace, + talk::Talk }; |
