Skip to content

Commit ed0b2b5

Browse files
committed
Add new game info
1 parent cbf7ba2 commit ed0b2b5

22 files changed

Lines changed: 2116 additions & 178 deletions

Cargo.lock

Lines changed: 22 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ all = "warn"
1818
crate-type = ["cdylib"]
1919

2020
[dependencies]
21-
pyo3 = "0.28.0"
21+
pyo3 = "0.29.0"
2222
planus = { git = "https://github.com/swz-git/planus", rev = "a0b1fbf" }
2323

2424
[build-dependencies]

codegen/table.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ impl<'a> TableBindGenerator<'a> {
241241
TypeKind::SimpleType(SimpleType::Integer(IntegerType::U8)) => {
242242
format!("PyBytes::new(py, &flat_t.{field_name}).unbind()")
243243
}
244+
TypeKind::SimpleType(SimpleType::Enum(_)) => {
245+
format!(
246+
"PyList::new(py, flat_t.{field_name}.iter().copied()).unwrap().unbind()"
247+
)
248+
}
244249
TypeKind::Table(idx) | TypeKind::SimpleType(SimpleType::Struct(idx)) => {
245250
let (path, _) = self.all_items.get_index(idx.0).unwrap();
246251
let type_name = path.0.last().unwrap();
@@ -353,6 +358,11 @@ impl<'a> TableBindGenerator<'a> {
353358
TypeKind::SimpleType(SimpleType::Integer(IntegerType::U8)) => {
354359
format!("py_type.{field_name}.as_bytes(py).to_vec()")
355360
}
361+
TypeKind::SimpleType(SimpleType::Enum(_)) => {
362+
format!(
363+
"py_type.{field_name}.bind_borrowed(py).iter().map(|x| x.extract::<u8>().unwrap().try_into().unwrap()).collect()"
364+
)
365+
}
356366
TypeKind::Table(_) | TypeKind::SimpleType(SimpleType::Struct(_)) => {
357367
format!(
358368
"py_type.{field_name}.bind_borrowed(py).iter().map(|x| crate::from_pyany_into(py, x)).collect()"
@@ -460,7 +470,12 @@ impl<'a> TableBindGenerator<'a> {
460470
SimpleType::Enum(idx) => {
461471
let (path, _) = self.all_items.get_index(idx.0).unwrap();
462472
let name = path.0.last().unwrap();
463-
Cow::Owned(format!("super::{name}"))
473+
474+
Cow::Owned(if matches!(field_info.assign_mode, AssignMode::Optional) {
475+
format!("Option<super::{name}>")
476+
} else {
477+
format!("super::{name}")
478+
})
464479
}
465480
SimpleType::Struct(idx) => {
466481
let (path, _) = self.all_items.get_index(idx.0).unwrap();
@@ -684,7 +699,15 @@ impl<'a> TableBindGenerator<'a> {
684699
write_fmt!(self, " self.{field_name},");
685700
}
686701
SimpleType::Enum(_) => {
687-
write_fmt!(self, " self.{field_name}.__repr__(),")
702+
if matches!(field_info.assign_mode, AssignMode::Optional) {
703+
write_fmt!(self, " self.{field_name}.as_ref()");
704+
write_str!(
705+
self,
706+
" .map_or_else(crate::none_str, |x| x.__repr__()),"
707+
);
708+
} else {
709+
write_fmt!(self, " self.{field_name}.__repr__(),");
710+
}
688711
}
689712
},
690713
TypeKind::String => {
@@ -708,9 +731,9 @@ impl<'a> TableBindGenerator<'a> {
708731
AssignMode::Optional => {
709732
write_fmt!(self, " self.{field_name}");
710733
write_str!(self, " .as_ref()");
711-
write_str!(self, " .map_or_else(crate::none_str, |x| {");
734+
write_str!(self, " .map_or_else(crate::none_str, |x| ");
712735
write_str!(self, " x.borrow(py).__repr__(py)");
713-
write_str!(self, " }),");
736+
write_str!(self, " ),");
714737
}
715738
_ => {
716739
write_fmt!(
@@ -765,6 +788,14 @@ impl<'a> TableBindGenerator<'a> {
765788
" .map(|x| x.cast_into::<super::{name}>().unwrap().borrow().__repr__(py))"
766789
);
767790
}
791+
SimpleType::Enum(idx) => {
792+
let (path, _) = self.all_items.get_index(idx.0).unwrap();
793+
let name = path.0.last().unwrap();
794+
write_str!(self, ".bind_borrowed(py).iter()");
795+
write_str!(self, ".map(|x| x.extract::<u8>().unwrap())");
796+
write_fmt!(self, ".map(|x| super::{name}::try_from(x).unwrap())");
797+
write_str!(self, ".map(|x| x.__repr__())");
798+
}
768799
_ => {
769800
write_str!(self, " .iter()");
770801
write_str!(self, " .map(ToString::to_string)");

flatbuffers-schema

0 commit comments

Comments
 (0)