From b06e54a0d90f8220149ba4288d73822a09db8d78 Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 13 Apr 2024 23:03:41 +0200 Subject: [PATCH] implement sleep token for chats --- src/chat.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/chat.rs b/src/chat.rs index 6cb3f0c..f3ad4d6 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -14,6 +14,7 @@ pub const TOKEN_CHAT: &str = "chat"; pub const TOKEN_MSG: &str = "msg"; pub const TOKEN_SYSTEM: &str = "system"; pub const TOKEN_WARN: &str = "warn"; +pub const TOKEN_SLEEP: &str = "sleep"; pub const TOKEN_SET: &str = "set"; pub const TOKEN_IF: &str = "if"; pub const TOKEN_GOTO: &str = "goto"; @@ -34,6 +35,7 @@ pub const NON_CHOICE_TOKENS: &[&str] = &[ TOKEN_MSG, TOKEN_SYSTEM, TOKEN_WARN, + TOKEN_SLEEP, TOKEN_SET, TOKEN_IF, TOKEN_GOTO, @@ -100,6 +102,7 @@ pub enum ChatEvent { SpawnMessage(String, hud::LogLevel), SpawnChoice(String, usize, ChatPos), RunScript(String), + Sleep(f64), //Script(String, String, String), } @@ -331,6 +334,11 @@ impl ChatDB { (Some(TOKEN_SCRIPT), Value::String(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) => { ew_chatscript.send(ChatScriptEvent(script.clone())); } + ChatEvent::Sleep(sleep_duration) => { + chat.timer = now + sleep_duration; + } } } }