Move everything up, get rid of src/src

This commit is contained in:
2022-01-24 11:32:24 -06:00
parent d5ec750c7f
commit 7c528368a4
9 changed files with 3 additions and 4 deletions

123
storybook-godot/src/lib.rs Normal file
View File

@@ -0,0 +1,123 @@
use storybook;
use gdnative::prelude::*;
fn init(handle: InitHandle){
handle.add_class::<Book>();
}
godot_init!(init);
#[derive(NativeClass)]
#[inherit(Reference)]
pub struct Book {
_book: Option<storybook::Book>,
}
#[derive(ToVariant)]
pub enum Footer {
None,
Ending,
Goto,
Choices(Vec<Choice>),
}
#[derive(ToVariant)]
pub struct Choice {
option: usize,
flavor: String,
stat_check: Option<StatCheck>,
stat_change: Option<StatChange>,
}
#[derive(ToVariant)]
pub struct StatCheck {
stat: String,
value: i32,
rel: String,
}
#[derive(ToVariant)]
pub struct StatChange {
stat: String,
addend: i32,
}
#[methods]
impl Book {
fn new(_owner: &Reference) -> Self {
Book {
_book: None,
}
}
#[export]
fn parse(&mut self, _owner: &Reference, text: String) {
self._book = Some(storybook::Book::new(text.as_str()));
}
#[export]
fn advance(&mut self, _owner: &Reference) {
match &mut self._book {
Some(b) => b.advance_nooption(),
None => (),
}
}
#[export]
fn advance_option(&mut self, _owner: &Reference, option: usize) {
match &mut self._book {
Some(b) => b.advance_option(option),
None => (),
}
}
#[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 {
Some(b) => match &b.get_current().footer {
storybook::Footer::Ending => Footer::Ending,
storybook::Footer::Goto(_) => Footer::Goto,
storybook::Footer::Choices(choices) => {
Footer::Choices(choices.iter().map(|(o, c)| Choice {
option: o.clone(),
flavor: c.flavor.clone(),
stat_check: match &c.stat_check {
Some(c) => Some(StatCheck::new(c)),
None => None,
},
stat_change: match &c.stat_change {
Some(c) => Some(StatChange::new(c)),
None => None,
},
}).collect())
},
},
None => Footer::None,
}
}
}
impl StatCheck {
fn new(sk: &storybook::StatCheck) -> Self {
StatCheck {
stat: sk.stat.clone(),
value: sk.value,
rel: String::from(sk.rel),
}
}
}
impl StatChange {
fn new(sg: &storybook::StatChange) -> Self {
StatChange {
stat: sg.stat.clone(),
addend: sg.addend,
}
}
}