mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-08 05:48:46 +08:00
feat(artemis): add support for ぱんみみそふと TXT scripts
- Updated main.rs to include new configuration options for artemis-panmimisoft. - Modified asb.rs to handle both .asb and .iet file extensions. - Introduced new module for panmimisoft scripts and implemented TxtBuilder for parsing. - Enhanced the parser to support new tag structures and attributes specific to ぱんみみそふと scripts. - Updated types.rs to reflect changes in configuration options and script types. - Adjusted mod.rs to register the new TxtBuilder for panmimisoft.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//! Artemis Engine ASB file (.asb)
|
||||
//! Artemis Engine ASB file (.asb/.iet)
|
||||
use crate::ext::io::*;
|
||||
use crate::scripts::base::*;
|
||||
use crate::types::*;
|
||||
@@ -30,17 +30,17 @@ impl ScriptBuilder for ArtemisAsbBuilder {
|
||||
fn build_script(
|
||||
&self,
|
||||
buf: Vec<u8>,
|
||||
_filename: &str,
|
||||
filename: &str,
|
||||
encoding: Encoding,
|
||||
_archive_encoding: Encoding,
|
||||
config: &ExtraConfig,
|
||||
_archive: Option<&Box<dyn Script>>,
|
||||
) -> Result<Box<dyn Script>> {
|
||||
Ok(Box::new(Asb::new(buf, encoding, config)?))
|
||||
Ok(Box::new(Asb::new(buf, encoding, config, filename)?))
|
||||
}
|
||||
|
||||
fn extensions(&self) -> &'static [&'static str] {
|
||||
&["asb"]
|
||||
&["asb", "iet"]
|
||||
}
|
||||
|
||||
fn script_type(&self) -> &'static ScriptType {
|
||||
@@ -421,6 +421,7 @@ impl<'a> TextParser<'a> {
|
||||
pub struct Asb {
|
||||
items: Vec<Item>,
|
||||
custom_yaml: bool,
|
||||
is_iet: bool,
|
||||
}
|
||||
|
||||
impl Asb {
|
||||
@@ -429,7 +430,12 @@ impl Asb {
|
||||
/// * `buf` - The buffer containing the ASB data.
|
||||
/// * `encoding` - The encoding used for the ASB data.
|
||||
/// * `config` - Extra configuration options.
|
||||
pub fn new(buf: Vec<u8>, encoding: Encoding, config: &ExtraConfig) -> Result<Self> {
|
||||
pub fn new(
|
||||
buf: Vec<u8>,
|
||||
encoding: Encoding,
|
||||
config: &ExtraConfig,
|
||||
filename: &str,
|
||||
) -> Result<Self> {
|
||||
let mut data = MemReader::new(buf);
|
||||
let mut magic = [0; 5];
|
||||
data.read_exact(&mut magic)?;
|
||||
@@ -444,17 +450,28 @@ impl Asb {
|
||||
Ok(Asb {
|
||||
items,
|
||||
custom_yaml: config.custom_yaml,
|
||||
is_iet: std::path::Path::new(filename)
|
||||
.extension()
|
||||
.map_or(false, |ext| ext.eq_ignore_ascii_case("iet")),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Script for Asb {
|
||||
fn default_output_script_type(&self) -> OutputScriptType {
|
||||
OutputScriptType::Json
|
||||
if self.is_iet {
|
||||
OutputScriptType::Custom
|
||||
} else {
|
||||
OutputScriptType::Json
|
||||
}
|
||||
}
|
||||
|
||||
fn is_output_supported(&self, _: OutputScriptType) -> bool {
|
||||
true
|
||||
fn is_output_supported(&self, out: OutputScriptType) -> bool {
|
||||
if self.is_iet {
|
||||
matches!(out, OutputScriptType::Custom)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fn default_format_type(&self) -> FormatOptions {
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
pub mod archive;
|
||||
pub mod asb;
|
||||
pub mod ast;
|
||||
pub mod txt;
|
||||
#[cfg(feature = "artemis-panmimisoft")]
|
||||
pub mod panmimisoft;
|
||||
|
||||
2
src/scripts/artemis/panmimisoft/mod.rs
Normal file
2
src/scripts/artemis/panmimisoft/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
//! Special parsers for [ぱんみみそふと](https://pannomimi.net/panmimisoft) games using the Artemis Engine.
|
||||
pub mod txt;
|
||||
@@ -41,7 +41,7 @@ impl ScriptBuilder for TxtBuilder {
|
||||
}
|
||||
|
||||
fn script_type(&self) -> &'static ScriptType {
|
||||
&ScriptType::ArtemisTxt
|
||||
&ScriptType::ArtemisPanmimisoftTxt
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ impl TagNode {
|
||||
|
||||
/// Returns true if the tag is not suitable for name.
|
||||
pub fn is_blocked_name(&self, set: &HashSet<String>) -> bool {
|
||||
set.contains(&self.name)
|
||||
self.name.is_ascii() || set.contains(&self.name)
|
||||
}
|
||||
|
||||
/// Checks if the tag has a specific attribute.
|
||||
@@ -814,8 +814,8 @@ impl TxtScript {
|
||||
let tree = parser.parse(true)?;
|
||||
Ok(Self {
|
||||
tree,
|
||||
blacklist_names: config.artemis_txt_blacklist_names.clone(),
|
||||
lang: config.artemis_txt_lang.clone(),
|
||||
blacklist_names: config.artemis_panmimisoft_txt_blacklist_names.clone(),
|
||||
lang: config.artemis_panmimisoft_txt_lang.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -873,23 +873,13 @@ impl Script for TxtScript {
|
||||
let mes = message.to_xml();
|
||||
message.clear();
|
||||
if !mes.is_empty() {
|
||||
let name = if mes.starts_with("「") {
|
||||
match &last_tag_block {
|
||||
Some(block) => {
|
||||
Some(if let Some(name) = block.get_attr("name") {
|
||||
name.to_string()
|
||||
} else {
|
||||
block.name.clone()
|
||||
})
|
||||
}
|
||||
_ => {
|
||||
eprintln!("Warn: Name block not found.");
|
||||
crate::COUNTER.inc_warning();
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
let name = match &last_tag_block {
|
||||
Some(block) => Some(if let Some(name) = block.get_attr("name") {
|
||||
name.to_string()
|
||||
} else {
|
||||
block.name.clone()
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
messages.push(Message { name, message: mes });
|
||||
}
|
||||
@@ -1177,6 +1167,17 @@ impl Script for TxtScript {
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads tags list from tag.ini file.
|
||||
pub fn read_tags_from_ini<P: AsRef<std::path::Path>>(path: P) -> Result<HashSet<String>> {
|
||||
let conf = ini::Ini::load_from_file(path)?;
|
||||
let set = HashSet::from_iter(conf.sections().flat_map(|s| s.map(|s| s.to_string())));
|
||||
eprintln!(
|
||||
"Read tags from ini: {}",
|
||||
set.iter().map(|s| s.as_str()).collect::<Vec<_>>().join(",")
|
||||
);
|
||||
Ok(set)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_xml_parser() {
|
||||
let data = "测试文本\nok<r a=\"b\">测试<b o=\"文本\n换行\">";
|
||||
Reference in New Issue
Block a user