Move everything up, get rid of src/src
This commit is contained in:
68
storybook-godot/Cargo.lock
generated
Normal file
68
storybook-godot/Cargo.lock
generated
Normal file
@@ -0,0 +1,68 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "peg"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af728fe826811af3b38c37e93de6d104485953ea373d656eebae53d6987fcd2c"
|
||||
dependencies = [
|
||||
"peg-macros",
|
||||
"peg-runtime",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "peg-macros"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4536be147b770b824895cbad934fccce8e49f14b4c4946eaa46a6e4a12fcdc16"
|
||||
dependencies = [
|
||||
"peg-runtime",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "peg-runtime"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9b0efd3ba03c3a409d44d60425f279ec442bcf0b9e63ff4e410da31c8b0f69f"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "storybook"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"peg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "storybook-godot"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"storybook",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
11
storybook-godot/Cargo.toml
Normal file
11
storybook-godot/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "storybook-godot"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
storybook = { path = "../" }
|
||||
gdnative = "0.9"
|
||||
123
storybook-godot/src/lib.rs
Normal file
123
storybook-godot/src/lib.rs
Normal 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user