add rust part
This commit is contained in:
parent
77e143bf77
commit
53fbb9c98c
@ -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::*;
|
||||
|
||||
|
@ -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<String>) -> 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::<String>().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<PyAny>,
|
||||
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::<PyDict>();
|
||||
Self {
|
||||
data: data.into_py(py_),
|
||||
get_list: Vec::new(),
|
||||
config: PyTranslateConfig::new(py_, false, false, None),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod console {
|
||||
|
17
mods/dr_game/Difficult_Rocket_rs/src/src/translate.rs
Normal file
17
mods/dr_game/Difficult_Rocket_rs/src/src/translate.rs
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* -------------------------------
|
||||
* Difficult Rocket
|
||||
* Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com
|
||||
* All rights reserved
|
||||
* -------------------------------
|
||||
*/
|
||||
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
type TranslateMapper = HashMap<String, HashMap<String, HashMap<String, String>>>;
|
||||
|
||||
pub struct Translater {
|
||||
pub data: TranslateMapper,
|
||||
pub language: String,
|
||||
}
|
Loading…
Reference in New Issue
Block a user