implement sleep token for chats

This commit is contained in:
yuni 2024-04-13 23:03:41 +02:00
parent fbc6dea13e
commit b06e54a0d9

View file

@ -14,6 +14,7 @@ pub const TOKEN_CHAT: &str = "chat";
pub const TOKEN_MSG: &str = "msg"; 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_SLEEP: &str = "sleep";
pub const TOKEN_SET: &str = "set"; pub const TOKEN_SET: &str = "set";
pub const TOKEN_IF: &str = "if"; pub const TOKEN_IF: &str = "if";
pub const TOKEN_GOTO: &str = "goto"; pub const TOKEN_GOTO: &str = "goto";
@ -34,6 +35,7 @@ pub const NON_CHOICE_TOKENS: &[&str] = &[
TOKEN_MSG, TOKEN_MSG,
TOKEN_SYSTEM, TOKEN_SYSTEM,
TOKEN_WARN, TOKEN_WARN,
TOKEN_SLEEP,
TOKEN_SET, TOKEN_SET,
TOKEN_IF, TOKEN_IF,
TOKEN_GOTO, TOKEN_GOTO,
@ -100,6 +102,7 @@ pub enum ChatEvent {
SpawnMessage(String, hud::LogLevel), SpawnMessage(String, hud::LogLevel),
SpawnChoice(String, usize, ChatPos), SpawnChoice(String, usize, ChatPos),
RunScript(String), RunScript(String),
Sleep(f64),
//Script(String, String, String), //Script(String, String, String),
} }
@ -331,6 +334,11 @@ impl ChatDB {
(Some(TOKEN_SCRIPT), Value::String(script)) => { (Some(TOKEN_SCRIPT), Value::String(script)) => {
event.send(ChatEvent::RunScript(script)); event.send(ChatEvent::RunScript(script));
} }
(Some(TOKEN_SLEEP), Value::Number(time)) => {
if let Some(time_f64) = time.as_f64() {
event.send(ChatEvent::Sleep(time_f64));
}
}
_ => { _ => {
} }
} }
@ -490,6 +498,9 @@ pub fn handle_chat_events(
ChatEvent::RunScript(script) => { ChatEvent::RunScript(script) => {
ew_chatscript.send(ChatScriptEvent(script.clone())); ew_chatscript.send(ChatScriptEvent(script.clone()));
} }
ChatEvent::Sleep(sleep_duration) => {
chat.timer = now + sleep_duration;
}
} }
} }
} }