handle msg/system/warn tokens
This commit is contained in:
parent
cc72fa1b31
commit
08ec42c043
46
src/chat.rs
46
src/chat.rs
|
@ -9,6 +9,7 @@ pub const CHATS: &[&str] = &[
|
||||||
];
|
];
|
||||||
|
|
||||||
pub const TOKEN_CHAT: &str = "chat";
|
pub const TOKEN_CHAT: &str = "chat";
|
||||||
|
pub const TOKEN_MSG: &str = "msg";
|
||||||
pub const TOKEN_SYSTEM: &str = "system";
|
pub const TOKEN_SYSTEM: &str = "system";
|
||||||
pub const TOKEN_WARN: &str = "warn";
|
pub const TOKEN_WARN: &str = "warn";
|
||||||
pub const TOKEN_SET: &str = "set";
|
pub const TOKEN_SET: &str = "set";
|
||||||
|
@ -26,6 +27,7 @@ pub const CHAT_SPEED_MIN_LEN: f32 = 40.0;
|
||||||
|
|
||||||
pub const NON_CHOICE_TOKENS: &[&str] = &[
|
pub const NON_CHOICE_TOKENS: &[&str] = &[
|
||||||
TOKEN_CHAT,
|
TOKEN_CHAT,
|
||||||
|
TOKEN_MSG,
|
||||||
TOKEN_SYSTEM,
|
TOKEN_SYSTEM,
|
||||||
TOKEN_WARN,
|
TOKEN_WARN,
|
||||||
TOKEN_SET,
|
TOKEN_SET,
|
||||||
|
@ -149,7 +151,6 @@ impl ChatDB {
|
||||||
dbg!(self.at(chat.id, &chat.position));
|
dbg!(self.at(chat.id, &chat.position));
|
||||||
match self.at(chat.id, &chat.position) {
|
match self.at(chat.id, &chat.position) {
|
||||||
None => {
|
None => {
|
||||||
dbg!("Pop.");
|
|
||||||
chat.position.pop();
|
chat.position.pop();
|
||||||
popped = true;
|
popped = true;
|
||||||
if chat.position.len() > 0 {
|
if chat.position.len() > 0 {
|
||||||
|
@ -219,16 +220,37 @@ impl ChatDB {
|
||||||
let mut add_choices = true;
|
let mut add_choices = true;
|
||||||
match current_item {
|
match current_item {
|
||||||
Some(Value::String(message)) => {
|
Some(Value::String(message)) => {
|
||||||
event.send(ChatEvent::SpawnMessage(message.to_string()));
|
event.send(ChatEvent::SpawnMessage(message.to_string(), hud::LogLevel::Chat));
|
||||||
}
|
}
|
||||||
Some(Value::Mapping(message)) => {
|
Some(Value::Mapping(map)) => {
|
||||||
if let Some(_) = self.search_choice(Some(&Value::Mapping(message))) {
|
if let Some(_) = self.search_choice(Some(&Value::Mapping(map.clone()))) {
|
||||||
add_choices = false;
|
add_choices = false;
|
||||||
}
|
}
|
||||||
|
for (key, value) in map {
|
||||||
|
let key = key.as_str();
|
||||||
|
match (key, value) {
|
||||||
|
(Some(TOKEN_CHAT), _) => {}
|
||||||
|
(Some(TOKEN_MSG), Value::String(message)) => {
|
||||||
|
event.send(ChatEvent::SpawnMessage(
|
||||||
|
message.to_string(), hud::LogLevel::Chat));
|
||||||
|
}
|
||||||
|
(Some(TOKEN_SYSTEM), Value::String(message)) => {
|
||||||
|
event.send(ChatEvent::SpawnMessage(
|
||||||
|
message.to_string(), hud::LogLevel::Info));
|
||||||
|
}
|
||||||
|
(Some(TOKEN_WARN), Value::String(message)) => {
|
||||||
|
event.send(ChatEvent::SpawnMessage(
|
||||||
|
message.to_string(), hud::LogLevel::Warning));
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if chat.position.len() == 0 {
|
if chat.position.len() == 0 {
|
||||||
event.send(ChatEvent::SpawnMessage("Disconnected.".to_string()));
|
event.send(ChatEvent::SpawnMessage(
|
||||||
|
"Disconnected.".to_string(), hud::LogLevel::Info));
|
||||||
event.send(ChatEvent::DespawnAllChats);
|
event.send(ChatEvent::DespawnAllChats);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -284,7 +306,7 @@ pub struct StartConversationEvent {
|
||||||
pub enum ChatEvent {
|
pub enum ChatEvent {
|
||||||
DespawnAllChoices,
|
DespawnAllChoices,
|
||||||
DespawnAllChats,
|
DespawnAllChats,
|
||||||
SpawnMessage(String),
|
SpawnMessage(String, hud::LogLevel),
|
||||||
SpawnChoice(String, usize, ChatPos),
|
SpawnChoice(String, usize, ChatPos),
|
||||||
//Script(String, String, String),
|
//Script(String, String, String),
|
||||||
}
|
}
|
||||||
|
@ -373,8 +395,18 @@ pub fn handle_chat_events(
|
||||||
ChatEvent::DespawnAllChats => {
|
ChatEvent::DespawnAllChats => {
|
||||||
commands.entity(chat_entity).despawn();
|
commands.entity(chat_entity).despawn();
|
||||||
}
|
}
|
||||||
ChatEvent::SpawnMessage(message) => {
|
ChatEvent::SpawnMessage(message, level) => {
|
||||||
|
match level {
|
||||||
|
hud::LogLevel::Chat => {
|
||||||
log.chat(message.into(), chat.talker.name.clone().unwrap_or(NAME_FALLBACK.to_string()));
|
log.chat(message.into(), chat.talker.name.clone().unwrap_or(NAME_FALLBACK.to_string()));
|
||||||
|
}
|
||||||
|
hud::LogLevel::Info | hud::LogLevel::Notice => {
|
||||||
|
log.info(message.into());
|
||||||
|
}
|
||||||
|
hud::LogLevel::Warning => {
|
||||||
|
log.warning(message.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
chat.timer = now + ((message.len() as f32).max(CHAT_SPEED_MIN_LEN) * TALKER_SPEED_FACTOR * chat.talker.talking_speed / settings.chat_speed) as f64;
|
chat.timer = now + ((message.len() as f32).max(CHAT_SPEED_MIN_LEN) * TALKER_SPEED_FACTOR * chat.talker.talking_speed / settings.chat_speed) as f64;
|
||||||
}
|
}
|
||||||
ChatEvent::SpawnChoice(replytext, key, goto) => {
|
ChatEvent::SpawnChoice(replytext, key, goto) => {
|
||||||
|
|
Loading…
Reference in a new issue