diff --git a/src/rust-base/Cargo.lock b/src/rust-base/Cargo.lock index 5e6b4a2..f25ee0d 100644 --- a/src/rust-base/Cargo.lock +++ b/src/rust-base/Cargo.lock @@ -2,6 +2,362 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "approx" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278" +dependencies = [ + "num-traits", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bindgen" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da379dbebc0b76ef63ca68d8fc6e71c0f13e59432e0987e508c1820e6ab5239" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cexpr" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clang-sys" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa66045b9cb23c2e9c1520732030608b02ee07e5cfaa5a521ec15ded7fa24c90" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "euclid" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da96828553a086d7b18dcebfc579bd9628b016f86590d7453c115e490fa74b80" +dependencies = [ + "num-traits", +] + +[[package]] +name = "gdnative" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ff5b6474bfe306c35ecb0cae47291e9af8af2f72e98d65cba7b76b2a52bf82b" +dependencies = [ + "gdnative-bindings", + "gdnative-core", + "gdnative-derive", +] + +[[package]] +name = "gdnative-bindings" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56b520f9b48e89d45852907b1acf0f25bc4bc8e8ee31148d351070096d00c761" +dependencies = [ + "bitflags", + "gdnative-core", + "gdnative-sys", + "gdnative_bindings_generator", + "heck", + "libc", +] + +[[package]] +name = "gdnative-core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d26a9076a40e568e6a29180985a111290e060f33581f37cb7695b1187d3bb7" +dependencies = [ + "ahash", + "approx", + "bitflags", + "euclid", + "gdnative-impl-proc-macros", + "gdnative-sys", + "indexmap", + "libc", + "parking_lot", +] + +[[package]] +name = "gdnative-derive" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82a0fc3c7dcadb3d2c2df567f80b12d872363bf3298a97f1b7a668150cd2f1cd" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "gdnative-impl-proc-macros" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2483f2b4038c2efb4fb22742a779201eb0bb1d4fb1d5dca3666e124281af86" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "gdnative-sys" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97911fe633877345ce7788cf19febb322dc7a7ffd585098fea7e5cef11edf7f2" +dependencies = [ + "bindgen", + "libc", + "miniserde", + "proc-macro2", + "quote", +] + +[[package]] +name = "gdnative_bindings_generator" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef6014ab49e58445894633f8a01b321ed86337150b6f1024ffea923e4499b91" +dependencies = [ + "heck", + "miniserde", + "proc-macro2", + "quote", + "roxmltree", + "syn", + "unindent", +] + +[[package]] +name = "getrandom" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "indexmap" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.113" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eef78b64d87775463c549fbd80e19249ef436ea3bf1de2a1eb7e717ec7fab1e9" + +[[package]] +name = "libloading" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "lock_api" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "mini-internal" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b3fb39c72c84ffbed14f8ee8b1a0e52ecd323df2ee69499fd3400a95d7269aa" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "miniserde" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e021d8031f6e224438f402d4c59d26c997e6e13498bd34da1aa1f858bd3b2f43" +dependencies = [ + "itoa", + "mini-internal", + "ryu", +] + +[[package]] +name = "nom" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +dependencies = [ + "memchr", + "version_check", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + [[package]] name = "peg" version = "0.8.0" @@ -47,6 +403,69 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "roxmltree" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "921904a62e410e37e215c40381b7117f830d9d89ba60ab5236170541dd25646b" +dependencies = [ + "xmlparser", +] + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "ryu" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "shlex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" + +[[package]] +name = "smallvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" + [[package]] name = "storybook" version = "0.1.0" @@ -54,8 +473,79 @@ dependencies = [ "peg", ] +[[package]] +name = "storybook-godot" +version = "0.1.0" +dependencies = [ + "gdnative", + "storybook", +] + +[[package]] +name = "syn" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "unicode-segmentation" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" + [[package]] name = "unicode-xid" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "unindent" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "xmlparser" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "114ba2b24d2167ef6d67d7d04c8cc86522b87f490025f39f0303b7db5bf5e3d8" diff --git a/src/rust-base/Cargo.toml b/src/rust-base/Cargo.toml index 53cf25c..be0c771 100644 --- a/src/rust-base/Cargo.toml +++ b/src/rust-base/Cargo.toml @@ -4,10 +4,10 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["staticlib"] - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +crate-type = ["rlib", "staticlib"] +[workspace] +members = ["storybook-godot"] [dependencies] diff --git a/src/rust-base/src/lib.rs b/src/rust-base/src/lib.rs index 75d427d..5ecc69e 100644 --- a/src/rust-base/src/lib.rs +++ b/src/rust-base/src/lib.rs @@ -5,8 +5,8 @@ use std::collections::HashMap; #[derive(Debug, PartialEq)] pub struct Page { id: String, - body: String, - footer: Footer, + pub body: String, + pub footer: Footer, } #[derive(Debug, PartialEq)] @@ -19,23 +19,23 @@ pub enum Footer { #[derive(Debug, PartialEq)] pub struct Choice { option: usize, - flavor: String, + pub flavor: String, redirect: String, - stat_check: Option, - stat_change: Option + pub stat_check: Option, + pub stat_change: Option } #[derive(Debug, PartialEq)] pub struct StatCheck { - stat: String, - value: i32, - rel: char, + pub stat: String, + pub value: i32, + pub rel: char, } #[derive(Debug, PartialEq)] pub struct StatChange { - stat: String, - addend: i32, + pub stat: String, + pub addend: i32, } peg::parser! { @@ -103,6 +103,10 @@ pub struct Book { } impl Book { + pub fn new (story: &str) -> Self { + let pages = storybook_parser::story(story).unwrap(); + Book::from(pages) + } pub fn find (&mut self, id: &str) { if self.pages.contains_key(id) { self.current_page = Some(String::from(id)); diff --git a/src/rust-base/storybook-godot/Cargo.lock b/src/rust-base/storybook-godot/Cargo.lock new file mode 100644 index 0000000..f127f26 --- /dev/null +++ b/src/rust-base/storybook-godot/Cargo.lock @@ -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" diff --git a/src/rust-base/storybook-godot/Cargo.toml b/src/rust-base/storybook-godot/Cargo.toml new file mode 100644 index 0000000..1d80232 --- /dev/null +++ b/src/rust-base/storybook-godot/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "storybook-godot" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +storybook = { path = "../" } +gdnative = "0.9" \ No newline at end of file diff --git a/src/rust-base/storybook-godot/src/lib.rs b/src/rust-base/storybook-godot/src/lib.rs new file mode 100644 index 0000000..f05ee22 --- /dev/null +++ b/src/rust-base/storybook-godot/src/lib.rs @@ -0,0 +1,129 @@ +use storybook; +use gdnative::prelude::*; + +fn init(handle: InitHandle){ + handle.add_class::(); +} + +godot_init!(init); + +#[derive(NativeClass)] +#[inherit(Reference)] +#[register_with(Self::register_properties)] +pub struct Book { + _book: Option, +} + +#[derive(ToVariant)] +pub enum Footer { + None, + Ending, + Goto, + Choices(Vec), +} + +#[derive(ToVariant)] +pub struct Choice { + option: usize, + flavor: String, + stat_check: Option, + stat_change: Option, +} + +#[derive(ToVariant)] +pub struct StatCheck { + stat: String, + value: i32, + rel: String, +} + +#[derive(ToVariant)] +pub struct StatChange { + stat: String, + addend: i32, +} + + +#[methods] +impl Book { + fn register_properties(builder: &ClassBuilder) { + builder + .add_property::("body") + .with_getter(Self::body_getter) + .done(); + } + 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 => (), + } + } + + fn body_getter(&self, _owner: TRef) -> 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, + } + } +}