Start TEngine3.0

Start TEngine3.0
This commit is contained in:
ALEXTANG
2023-03-31 17:27:49 +08:00
parent 179765c43c
commit 36353294d6
1032 changed files with 21868 additions and 102407 deletions

View File

@@ -0,0 +1,56 @@
{{
name = x.rust_full_name
parent_def_type = x.parent_def_type
export_fields = x.export_fields
hierarchy_export_fields = x.hierarchy_export_fields
}}
{{~if x.comment != '' ~}}
/**
* {{x.escape_comment}}
*/
{{~end~}}
{{~if !x.is_abstract_type~}}
#[allow(non_camel_case_types)]
pub struct {{name}} {
{{~for field in hierarchy_export_fields~}}
pub {{field.convention_name}}: {{rust_define_type field.ctype}},
{{~end~}}
}
impl {{name}} {
#[allow(dead_code)]
pub fn new(__js: &json::JsonValue) -> Result<{{name}}, LoadError> {
let __b = {{name}} {
{{~for field in hierarchy_export_fields~}}
{{field.convention_name}}: {{rust_json_constructor ('__js["' + field.name + '"]') field.ctype}},
{{~end~}}
};
Ok(__b)
}
}
{{~else~}}
#[allow(non_camel_case_types)]
pub enum {{name}} {
{{~for child in x.hierarchy_not_abstract_children~}}
{{child.name}}(Box<{{child.rust_full_name}}>),
{{~end~}}
}
impl {{name}} {
#[allow(dead_code)]
pub fn new(__js: &json::JsonValue) -> Result<{{name}}, LoadError> {
let __b = match __js["{{x.json_type_name_key}}"].as_str() {
Some(type_name) => match type_name {
{{~for child in x.hierarchy_not_abstract_children~}}
"{{cs_impl_data_type child x}}" => {{name}}::{{child.name}}(Box::new({{child.rust_full_name + '::new(&__js)?'}})),
{{~end~}}
_ => return Err(LoadError{})
},
None => return Err(LoadError{})
};
Ok(__b)
}
}
{{~end~}}

View File

@@ -0,0 +1,59 @@
pub struct LoadError {
}
impl std::fmt::Debug for LoadError {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> { Ok(()) }
}
#[allow(dead_code)]
pub struct Vector2 {
pub x:f32,
pub y:f32,
}
impl Vector2 {
pub fn new(__js:&json::JsonValue) -> Result<Vector2, LoadError> {
Ok(Vector2{
x: match __js["x"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
y: match __js["y"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
})
}
}
#[allow(dead_code)]
pub struct Vector3 {
pub x:f32,
pub y:f32,
pub z:f32,
}
impl Vector3 {
pub fn new(__js:&json::JsonValue) -> Result<Vector3, LoadError> {
Ok(Vector3{
x: match __js["x"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
y: match __js["y"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
z: match __js["z"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
})
}
}
#[allow(dead_code)]
pub struct Vector4 {
pub x:f32,
pub y:f32,
pub z:f32,
pub w:f32,
}
impl Vector4 {
pub fn new(__js:&json::JsonValue) -> Result<Vector4, LoadError> {
Ok(Vector4{
x: match __js["x"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
y: match __js["y"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
z: match __js["z"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
w: match __js["w"].as_f32() { Some(__x__) => __x__, None => return Err(LoadError{})},
})
}
}

View File

@@ -0,0 +1,99 @@
{{
name = x.rust_full_name
key_type = x.key_ttype
value_type = x.value_ttype
}}
{{~if x.comment != '' ~}}
/**
* {{x.escape_comment}}
*/
{{~end~}}
#[allow(non_camel_case_types)]
pub struct {{name}} {
{{~if x.is_map_table ~}}
data_list: Vec<std::rc::Rc<{{rust_define_type value_type}}>>,
data_map: std::collections::HashMap<{{rust_define_type key_type}}, std::rc::Rc<{{rust_define_type value_type}}>>,
{{~else if x.is_list_table ~}}
data_list: Vec<std::rc::Rc<{{rust_define_type value_type}}>>,
{{~else~}}
data: {{rust_class_name value_type}},
{{~end~}}
}
impl {{name}}{
pub fn new(__js: &json::JsonValue) -> Result<{{name}}, LoadError> {
{{~if x.is_map_table ~}}
if !__js.is_array() {
return Err(LoadError{});
}
let mut t = {{name}} {
data_list : Vec::new(),
data_map: std::collections::HashMap::new(),
};
for __e in __js.members() {
let __v = std::rc::Rc::new(match {{rust_class_name value_type}}::new(__e) {
Ok(x) => x,
Err(err) => return Err(err),
});
let __v2 = std::rc::Rc::clone(&__v);
t.data_list.push(__v);
{{~if !value_type.bean.is_abstract_type~}}
t.data_map.insert(__v2.{{x.index_field.convention_name}}.clone(), __v2);
{{~else~}}
match &*__v2 {
{{~for child in value_type.bean.hierarchy_not_abstract_children~}}
{{rust_class_name value_type}}::{{child.name}}(__w__) => t.data_map.insert(__w__.{{x.index_field.convention_name}}.clone(), __v2),
{{~end~}}
};
{{~end~}}
}
Ok(t)
}
#[allow(dead_code)]
pub fn get_data_map(self:&{{name}}) -> &std::collections::HashMap<{{rust_define_type key_type}}, std::rc::Rc<{{rust_define_type value_type}}>> { &self.data_map }
#[allow(dead_code)]
pub fn get_data_list(self:&{{name}}) -> &Vec<std::rc::Rc<{{rust_define_type value_type}}>> { &self.data_list }
#[allow(dead_code)]
pub fn get(self:&{{name}}, key: &{{rust_define_type key_type}}) -> std::option::Option<&std::rc::Rc<{{rust_define_type value_type}}>> { self.data_map.get(key) }
{{~else if x.is_list_table ~}}
if !__js.is_array() {
return Err(LoadError{});
}
let mut t = {{name}} {
data_list : Vec::new(),
};
for __e in __js.members() {
let __v = std::rc::Rc::new(match {{rust_class_name value_type}}::new(__e) {
Ok(x) => x,
Err(err) => return Err(err),
});
let __v2 = std::rc::Rc::clone(&__v);
t.data_list.push(__v);
}
Ok(t)
}
#[allow(dead_code)]
pub fn get_data_list(self:&{{name}}) -> &Vec<std::rc::Rc<{{rust_define_type value_type}}>> { &self.data_list }
#[allow(dead_code)]
pub fn get(self:&{{name}}, index: usize) -> &std::rc::Rc<{{rust_define_type value_type}}> { &self.data_list[index] }
{{~else~}}
if !__js.is_array() || __js.len() != 1 {
return Err(LoadError{});
}
let __v = match {{rust_class_name value_type}}::new(&__js[0]) {
Ok(x) => x,
Err(err) => return Err(err),
};
let t = {{name}} {
data: __v,
};
Ok(t)
}
#[allow(dead_code)]
pub fn get_data(self:&{{name}}) -> &{{rust_define_type value_type}} { &self.data }
{{~end~}}
}

View File

@@ -0,0 +1,32 @@
{{
name = x.name
namespace = x.namespace
tables = x.tables
}}
type JsonLoader = fn(&str) -> Result<json::JsonValue, LoadError>;
#[allow(non_camel_case_types)]
pub struct {{name}} {
{{~ for table in tables ~}}
{{~if table.comment != '' ~}}
/**
* {{table.escape_comment}}
*/
{{~end~}}
pub {{string.downcase table.name}}: {{table.rust_full_name}},
{{~end~}}
}
impl {{name}} {
#[allow(dead_code)]
pub fn new(loader: JsonLoader) -> std::result::Result<Tables, LoadError> {
let tables = Tables {
{{~for table in tables ~}}
{{string.downcase table.name}}: {{table.rust_full_name}}::new(&loader("{{table.output_data_file}}")?)?,
{{~end~}}
};
return Ok(tables);
}
}