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 {
pages: HashMap<String, Page>,
current_page: Option<String>
@ -437,3 +439,4 @@ THE END
assert_eq!(book.current_page, Some(String::from("START")));
}
}

View File

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