diff --git a/godot/mhjnr/menu.tscn b/godot/mhjnr/menu.tscn index 76430d6..78470fc 100644 --- a/godot/mhjnr/menu.tscn +++ b/godot/mhjnr/menu.tscn @@ -30,8 +30,8 @@ func set_menu(name: String) -> void: button.connect(\"pressed\", callable.bindv(action.args)) for node in menu.find_children(\"*\"): - if node.has_method(\"set_text\"): - node.text = translations.tr(node.text) + if \"text\" in node: + node.text = translations.get_message(node.text) func _on_close_pressed() -> void: get_tree().quit() @@ -41,6 +41,9 @@ func _on_action_SetMenu(name: String) -> void: func _on_action_CheckStartGame() -> void: print(\"CheckStartGame\") + +func _on_action_DisplayEndscreen() -> void: + get_tree().quit() " [node name="Root" type="MarginContainer"] diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 944fc4f..7448e98 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -156,6 +156,15 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +[[package]] +name = "encoding_rs" +version = "0.8.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +dependencies = [ + "cfg-if", +] + [[package]] name = "exr" version = "1.6.3" @@ -425,6 +434,7 @@ version = "0.1.0" dependencies = [ "base64", "binrw", + "encoding_rs", "godot", "image", "itertools", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index fb136b0..62fe4bc 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -14,6 +14,7 @@ crate-type = ["cdylib", "lib"] [dependencies] itertools = "0.10.5" unicode-segmentation = "1.10.1" +encoding_rs = "0.8.32" binrw = "0.11.1" serde = {version = "1.0.160", features = ["derive"]} serde-xml-rs = "0.6.0" diff --git a/rust/src/formats/mod.rs b/rust/src/formats/mod.rs index 7fc1c69..d1911dc 100644 --- a/rust/src/formats/mod.rs +++ b/rust/src/formats/mod.rs @@ -5,6 +5,7 @@ use crate::formats::sprites::Sprites; use crate::formats::txt::{decrypt_txt, DecryptError}; use crate::formats::ui_xml::UiTag; use binrw::BinRead; +use encoding_rs::WINDOWS_1252; use itertools::Itertools; use std::collections::HashMap; use std::ffi::OsStr; @@ -82,7 +83,7 @@ where .file_stem() .and_then(OsStr::to_str) .ok_or(Error::Custom("Stem".to_string()))?; - let decr = decrypt_txt(data.into_iter()).map_err(|e| Error::DecryptError(e))?; + let decr = decrypt_txt(data.into_iter()).map_err(Error::DecryptError)?; if stem.starts_with("tile_collision") { Ok(DatafileFile::TileCollision(decr)) } else if stem == "sprites" { @@ -94,8 +95,9 @@ where } } "csv" => Ok(DatafileFile::Translations( - String::from_utf8(data) - .unwrap() + WINDOWS_1252 + .decode(data.as_slice()) + .0 .split('\n') .map(|l| l.trim()) .filter(|l| !l.is_empty()) diff --git a/rust/src/godot/datafile.rs b/rust/src/godot/datafile.rs index 2191a21..f42c199 100644 --- a/rust/src/godot/datafile.rs +++ b/rust/src/godot/datafile.rs @@ -187,8 +187,16 @@ impl ResourceFormatLoaderVirtual for DatafileLoader { Ok(DatafileFile::Translations(translations)) => { let mut translation = Translation::new(); for (key, message) in translations { - translation.add_message(key.into(), message.join("\n").into(), "".into()); + translation.add_message( + format!("%{}%", key).into(), + message.join("\n").into(), + "".into(), + ); } + self.save_to_cache( + translation.share().upcast(), + format!("{}.res", datafile_path), + ); translation.to_variant() } Ok(DatafileFile::Vorbis(vorbis)) => {