Added command on client side

This commit is contained in:
ccgauche
2021-01-23 19:42:42 +01:00
parent 1dfe4af916
commit 457026a48e
4 changed files with 44 additions and 13 deletions

3
Cargo.lock generated
View File

@ -328,7 +328,7 @@ source = "git+https://gitlab.com/veloren/auth.git?rev=bffb5181a35c19ddfd33ee0b4a
dependencies = [
"auth-common",
"fxhash",
"hex 0.3.2",
"hex",
"reqwest",
"rust-argon2",
"serde",
@ -5976,6 +5976,7 @@ dependencies = [
"veloren-common",
"veloren-common-net",
"veloren-common-sys",
"veloren-plugin-api",
"veloren_network",
]

View File

@ -31,6 +31,10 @@ vek = { version = "0.12.0", features = ["serde"] }
hashbrown = { version = "0.9", features = ["rayon", "serde", "nightly"] }
authc = { git = "https://gitlab.com/veloren/auth.git", rev = "bffb5181a35c19ddfd33ee0b4aedba741aafb68d" }
# Plugins
plugin-api = { package = "veloren-plugin-api", path = "../plugin/api"}
[dev-dependencies]
tracing-subscriber = { version = "0.2.3", default-features = false, features = ["fmt", "chrono", "ansi", "smallvec"] }

View File

@ -5,6 +5,9 @@
pub mod cmd;
pub mod error;
#[cfg(feature = "plugins")]
pub use plugin_api::*;
// Reexports
pub use crate::error::Error;
pub use authc::AuthClientError;

View File

@ -20,6 +20,7 @@ mod social;
mod spell;
mod util;
use common_sys::plugin::PluginMgr;
pub use hotbar::{SlotContents as HotbarSlotContents, State as HotbarState};
pub use settings_window::ScaleChange;
@ -53,19 +54,11 @@ use crate::{
window::{Event as WinEvent, FullScreenSettings, GameInput},
GlobalState,
};
use client::Client;
use common::{
comp,
comp::{
use client::{Client, event::{ChatCommandEvent, Player}};
use common::{cmd::ChatCommand, comp, comp::{
item::{ItemDesc, Quality},
BuffKind,
},
span,
terrain::TerrainChunk,
uid::Uid,
util::srgba_to_linear,
vol::RectRasterableVol,
};
}, span, terrain::TerrainChunk, uid::Uid, util::srgba_to_linear, vol::RectRasterableVol};
use common_net::msg::{Notification, PresenceKind};
use conrod_core::{
text::cursor::Index,
@ -2018,7 +2011,37 @@ impl Hud {
self.tab_complete = Some(input);
},
Some(chat::Event::SendMessage(message)) => {
events.push(Event::SendMessage(message));
println!("ROLLER 1: {}",message);
let manager = ecs.read_resource::<PluginMgr>();
if message.starts_with("/") {
let mut cmd_iter = message.split(' ');
let command_tag = &cmd_iter.next().unwrap()[1..];
let event = ChatCommandEvent {
command: message.clone(),
command_args: cmd_iter.map(|x| x.to_owned()).collect(),
player: Player {
id: ecs.read_storage::<Uid>().get(entity).unwrap().clone(),
}
};
match manager.execute_event(&format!("on_command_{}",command_tag), &event) {
Ok(e) => {
if e.is_empty() {
events.push(Event::SendMessage(message));
} else {
println!("Send this message to the chat:");
for i in &e {
println!("{:?}",i);
}
}
},
Err(e) => {
println!("Error while hooking commands with plugins");
println!("{:?}",e);
}
}
} else {
events.push(Event::SendMessage(message));
}
},
Some(chat::Event::Focus(focus_id)) => {
self.to_focus = Some(Some(focus_id));