From 53fbb9c98cb09773b62536d8e369859bb8ea1663 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Thu, 22 Jun 2023 01:44:46 +0800 Subject: [PATCH] add rust part --- .../Difficult_Rocket_rs/src/src/lib.rs | 5 +- .../Difficult_Rocket_rs/src/src/python.rs | 58 +------------------ .../Difficult_Rocket_rs/src/src/translate.rs | 17 ++++++ 3 files changed, 21 insertions(+), 59 deletions(-) create mode 100644 mods/dr_game/Difficult_Rocket_rs/src/src/translate.rs diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs index c077576..b7e673d 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs @@ -6,13 +6,14 @@ * ------------------------------- */ +mod types; mod logger; mod plugin; mod python; mod render; -mod simulator; mod sr1_data; -mod types; +mod simulator; +mod translate; use pyo3::prelude::*; diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs index f745414..56ebf25 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs @@ -166,64 +166,8 @@ pub mod data { } pub mod translate { - use pyo3::prelude::*; - use pyo3::types::PyDict; + use crate::translate; - #[pyclass] - #[pyo3(name = "TranslateConfig_rs")] - #[pyo3(text_signature = "(language, raise_error = False, replace_normal = False, add_error = False, is_result = False, keep_get = False)")] - pub struct PyTranslateConfig { - pub raise_error: bool, - pub replace_normal: bool, - pub add_error: bool, - pub is_result: bool, - pub keep_get: bool, - pub language: String, - } - - #[pymethods] - impl PyTranslateConfig { - #[new] - fn new(py_: Python, raise_error: bool, replace_normal: bool, language: Option) -> Self { - let dr_runtime = PyModule::import(py_, "Difficult_Rocket").unwrap().get_item("DR_runtime").unwrap(); - let default_language = dr_runtime.get_item("language").unwrap().extract::().unwrap(); - Self { - raise_error, - replace_normal, - add_error: false, - is_result: false, - keep_get: false, - language: language.unwrap_or(default_language), - } - } - - // fn set(&self, py_: Python, item: String, value: BoolString) -> &Self { - // match item.as_str() { - // "raise_error" => self, - // _ => self, - // } - // } - } - - #[pyclass] - pub struct PyTranslate { - pub data: Py, - pub get_list: Vec<(String, bool)>, - pub config: PyTranslateConfig, - } - - #[pymethods] - impl PyTranslate { - #[new] - fn py_new(py_: Python, data: &PyAny) -> Self { - let _ = data.is_instance_of::(); - Self { - data: data.into_py(py_), - get_list: Vec::new(), - config: PyTranslateConfig::new(py_, false, false, None), - } - } - } } pub mod console { diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/translate.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/translate.rs new file mode 100644 index 0000000..36840c2 --- /dev/null +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/translate.rs @@ -0,0 +1,17 @@ +/* + * ------------------------------- + * Difficult Rocket + * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com + * All rights reserved + * ------------------------------- + */ + + +use std::collections::HashMap; + +type TranslateMapper = HashMap>>; + +pub struct Translater { + pub data: TranslateMapper, + pub language: String, +}