From 88fd7e02f1f03c461093664481e20d62b6683710 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Wed, 23 Jul 2025 22:04:20 +0800 Subject: [PATCH] Add support to select text --- src/scripts/artemis/ast/mod.rs | 64 ++++++++++++++++++++++++++++++-- src/scripts/artemis/ast/types.rs | 4 ++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/scripts/artemis/ast/mod.rs b/src/scripts/artemis/ast/mod.rs index 45659dd..b0ba89d 100644 --- a/src/scripts/artemis/ast/mod.rs +++ b/src/scripts/artemis/ast/mod.rs @@ -114,16 +114,32 @@ impl Script for AstScript { for l in text.kv_keys() { if l != "vo" { lang = Some(l); + break; } } match lang { Some(l) => l, // No text found, continue to next block - None => continue, + None => { + block_name = match block["linknext"].as_str() { + Some(name) => name, + None => break, + }; + block = &ast[block_name]; + continue; + } } } }; - let tex = &text[lan]; + let mut tex = &text[lan]; + if tex.is_null() { + for l in text.kv_keys() { + if l != "vo" { + tex = &text[l]; + break; + } + } + } for item in tex.members() { let name = item["name"].last_member().as_string(); let message = text::TextGenerator::new().generate(item)?; @@ -137,7 +153,49 @@ impl Script for AstScript { }); } } - // #TODO: SELECTS + let select = &block["select"]; + if select.is_array() { + let lan = match lang { + Some(l) => l, + None => { + for l in select.kv_keys() { + if l != "vo" { + lang = Some(l); + break; + } + } + match lang { + Some(l) => l, + // No select text found, continue to next block + None => { + block_name = match block["linknext"].as_str() { + Some(name) => name, + None => break, + }; + block = &ast[block_name]; + continue; + } + } + } + }; + let mut select_text = &select[lan]; + if select_text.is_null() { + for l in select.kv_keys() { + if l != "vo" { + select_text = &select[l]; + break; + } + } + } + for item in select_text.members() { + if let Some(select) = item.as_str() { + messages.push(Message { + name: None, + message: select.to_string(), + }); + } + } + } block_name = match block["linknext"].as_str() { Some(name) => name, None => break, diff --git a/src/scripts/artemis/ast/types.rs b/src/scripts/artemis/ast/types.rs index ae66a5e..5d22365 100644 --- a/src/scripts/artemis/ast/types.rs +++ b/src/scripts/artemis/ast/types.rs @@ -75,6 +75,10 @@ impl Value { matches!(self, Value::KeyVal(_)) } + pub fn is_null(&self) -> bool { + matches!(self, Value::Null) + } + pub fn kv_key(&self) -> Option<&str> { if let Value::KeyVal((k, _)) = self { Some(k)