Just use a getter

This commit is contained in:
Dane Johnson 2022-01-21 16:32:58 -06:00
parent d99270d63b
commit 0a4484578b
2 changed files with 6 additions and 9 deletions

View File

@ -97,6 +97,8 @@ peg::parser! {
} }
} }
// Book is a collection of pages and utilities
pub struct Book { pub struct Book {
pages: HashMap<String, Page>, pages: HashMap<String, Page>,
current_page: Option<String> current_page: Option<String>
@ -437,3 +439,4 @@ THE END
assert_eq!(book.current_page, Some(String::from("START"))); assert_eq!(book.current_page, Some(String::from("START")));
} }
} }

View File

@ -9,7 +9,6 @@ godot_init!(init);
#[derive(NativeClass)] #[derive(NativeClass)]
#[inherit(Reference)] #[inherit(Reference)]
#[register_with(Self::register_properties)]
pub struct Book { pub struct Book {
_book: Option<storybook::Book>, _book: Option<storybook::Book>,
} }
@ -46,12 +45,6 @@ pub struct StatChange {
#[methods] #[methods]
impl Book { impl Book {
fn register_properties(builder: &ClassBuilder<Book>) {
builder
.add_property::<String>("body")
.with_getter(Self::body_getter)
.done();
}
fn new(_owner: &Reference) -> Self { fn new(_owner: &Reference) -> Self {
Book { Book {
_book: None, _book: None,
@ -75,13 +68,14 @@ impl Book {
None => (), None => (),
} }
} }
#[export]
fn body_getter(&self, _owner: TRef<Reference>) -> String { fn get_body(&self, _owner: &Reference) -> String {
match &self._book{ match &self._book{
Some(b) => b.get_current().body.clone(), Some(b) => b.get_current().body.clone(),
None => String::new(), None => String::new(),
} }
} }
#[export] #[export]
fn get_footer(&self, _owner: &Reference) -> Footer { fn get_footer(&self, _owner: &Reference) -> Footer {
match &self._book { match &self._book {