From 1ef03302aae10fc48e228c4189949c329aaa11f2 Mon Sep 17 00:00:00 2001 From: Melody Madeline Lyons Date: Mon, 14 Oct 2024 11:15:08 -0700 Subject: [PATCH] add jank command parser --- Cargo.lock | 166 +++++++++++++++++++----------- Cargo.toml | 5 +- crates/command_parser/Cargo.toml | 6 ++ crates/command_parser/src/main.rs | 67 ++++++++++++ crates/data/src/shared/event.rs | 8 +- 5 files changed, 185 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 936ea3df..ebf7462d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,7 +102,7 @@ dependencies = [ "macroific", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -203,7 +203,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -305,7 +305,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -572,7 +572,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -633,7 +633,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -782,7 +782,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -934,7 +934,7 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -1158,10 +1158,12 @@ dependencies = [ name = "command_parser" version = "0.4.0" dependencies = [ + "indextree", "luminol-config", "luminol-core", "luminol-data", "luminol-filesystem", + "poll-promise", ] [[package]] @@ -1424,7 +1426,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -1435,7 +1437,7 @@ checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" dependencies = [ "darling_core", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -1478,7 +1480,7 @@ dependencies = [ "macroific", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -1577,7 +1579,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de78e66ac9061e030587b2a2e75cc88f22304913c907b11307bca737141230cb" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro-error", ] @@ -1676,9 +1678,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "emath" @@ -1711,10 +1713,10 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ffccbb6966c05b32ef8fbac435df276c4ae4d3dc55a8cd0eb9745e6c12f546a" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -1735,7 +1737,7 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -1756,7 +1758,7 @@ checksum = "5c785274071b1b420972453b306eeca06acf4633829db4223b58a2a8c5953bc4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -1767,7 +1769,7 @@ checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -1914,7 +1916,7 @@ dependencies = [ "macroific", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -2007,7 +2009,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -2121,7 +2123,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -2243,7 +2245,7 @@ checksum = "53010ccb100b96a67bc32c0175f0ed1426b31b655d562898e57325f81c023ac0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -2473,6 +2475,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.8" @@ -2703,9 +2711,27 @@ dependencies = [ [[package]] name = "indextree" -version = "4.6.0" +version = "4.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c40411d0e5c63ef1323c3d09ce5ec6d84d71531e18daed0743fccea279d7deb6" +checksum = "0d6f1b8dbc8f1e5a0f45e05b9293c42cbab79086baeb3e914d3936f8149edc4f" +dependencies = [ + "indextree-macros", +] + +[[package]] +name = "indextree-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357230c23ee6024223892ce0de19888a04139ca5bb94f5becb04d38b75a4bccf" +dependencies = [ + "either", + "itertools 0.13.0", + "proc-macro2", + "quote", + "strum 0.26.3", + "syn 2.0.79", + "thiserror", +] [[package]] name = "instant" @@ -2724,7 +2750,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -3083,7 +3109,7 @@ dependencies = [ "rfd", "shadow-rs", "steamworks", - "strum", + "strum 0.25.0", "tempfile", "tokio", "tracing", @@ -3114,7 +3140,7 @@ dependencies = [ "rodio", "rustysynth", "slab", - "strum", + "strum 0.25.0", "thiserror", "wasm-bindgen-futures", "web-sys", @@ -3133,7 +3159,7 @@ dependencies = [ "ron", "rust-ini", "serde", - "strum", + "strum 0.25.0", ] [[package]] @@ -3160,7 +3186,7 @@ dependencies = [ "serde", "serde_json", "serde_path_to_error", - "strum", + "strum 0.25.0", "tracing", ] @@ -3178,7 +3204,7 @@ dependencies = [ "paste", "rand", "serde", - "strum", + "strum 0.25.0", ] [[package]] @@ -3316,7 +3342,7 @@ name = "luminol-proc-macros" version = "0.4.0" dependencies = [ "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -3344,7 +3370,7 @@ dependencies = [ "luminol-core", "luminol-macros", "serde", - "strum", + "strum 0.25.0", ] [[package]] @@ -3387,7 +3413,7 @@ dependencies = [ "serde_json", "serde_yml", "strip-ansi-escapes", - "strum", + "strum 0.25.0", "syntect", "target-triple", "wgpu", @@ -3434,7 +3460,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -3445,7 +3471,7 @@ checksum = "13198c120864097a565ccb3ff947672d969932b7975ebd4085732c9f09435e55" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -3458,7 +3484,7 @@ dependencies = [ "macroific_core", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -3782,7 +3808,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -3842,7 +3868,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -4103,7 +4129,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -4257,7 +4283,7 @@ checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -4443,9 +4469,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -4466,7 +4492,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8021cf59c8ec9c432cfc2526ac6b8aa508ecaf29cd415f271b8406c1b851c3fd" dependencies = [ "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -4518,9 +4544,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -5047,7 +5073,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -5080,7 +5106,7 @@ checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -5369,7 +5395,16 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" dependencies = [ - "strum_macros", + "strum_macros 0.25.3", +] + +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros 0.26.4", ] [[package]] @@ -5378,11 +5413,24 @@ version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" dependencies = [ - "heck", + "heck 0.4.1", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.79", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck 0.5.0", "proc-macro2", "quote", "rustversion", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -5457,9 +5505,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.51" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -5522,7 +5570,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a2d580ff6a20c55dfb86be5f9c238f67835d0e81cbdea8bf5680e0897320331" dependencies = [ "cfg-expr", - "heck", + "heck 0.4.1", "pkg-config", "toml 0.8.10", "version-compare", @@ -5578,7 +5626,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -5721,7 +5769,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -5838,7 +5886,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] @@ -6218,7 +6266,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", "wasm-bindgen-shared", ] @@ -6252,7 +6300,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -7192,7 +7240,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.51", + "syn 2.0.79", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index fcb6164d..e8ab21fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,9 @@ categories = ["games"] # Shared dependencies [workspace.dependencies] # * Window management, graphical user interface and 3D rendering * # -egui = "0.28.1" # Real-time stateless graphical user interface framework +egui = { version = "0.28.1", features = [ + "serde", +] } # Real-time stateless graphical user interface framework egui_extras = { version = "0.28.1", features = [ "svg", "image", @@ -216,6 +218,7 @@ opt-level = 3 [profile.dev.package.glam] opt-level = 3 + # See why config is set up this way. # https://bevy-cheatbook.github.io/pitfalls/performance.html#why-not-use---release diff --git a/crates/command_parser/Cargo.toml b/crates/command_parser/Cargo.toml index 579639b3..3af520c7 100644 --- a/crates/command_parser/Cargo.toml +++ b/crates/command_parser/Cargo.toml @@ -21,3 +21,9 @@ luminol-filesystem.workspace = true luminol-config.workspace = true luminol-data.workspace = true luminol-core.workspace = true + +indextree = "4.7.2" + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.poll-promise] +workspace = true +features = ["tokio"] diff --git a/crates/command_parser/src/main.rs b/crates/command_parser/src/main.rs index ec833d8d..ecce1b76 100644 --- a/crates/command_parser/src/main.rs +++ b/crates/command_parser/src/main.rs @@ -1,3 +1,57 @@ +use luminol_data::rpg; + +use std::fmt::Write; +use std::iter::Peekable; + +fn parse_command_under( + node: indextree::NodeId, + command: rpg::EventCommand, + arena: &mut indextree::Arena, + iter: &mut Peekable>, + config: &luminol_config::project::Config, +) { + if command.code == 0 { + return; + } + + let desc = config.command_db.get(command.code); + let mut child = node.append_value(command, arena); + if let Some(desc) = desc { + match &desc.kind { + luminol_data::commands::CommandKind::Branch { + parameters, + branches, + terminator, + command_contains_branch, + } => loop { + let next = iter.next().unwrap(); + + if next.code == terminator.code { + break; + } + + if branches.iter().any(|branch| branch.code == next.code) { + child = node.append_value(next, arena); + continue; + } + + parse_command_under(child, next, arena, iter, config); + }, + luminol_data::commands::CommandKind::Multi(cont) => { + let command = arena[child].get_mut(); + let text = command.parameters[0].as_string_mut().unwrap(); + while let Some(next) = iter.next_if(|next| next.code == *cont) { + let next_line = next.parameters[0].as_string().unwrap(); + write!(text, "\n{next_line}").unwrap(); + } + } + luminol_data::commands::CommandKind::Regular { parameters } => todo!(), + luminol_data::commands::CommandKind::MoveRoute(_) => todo!(), + luminol_data::commands::CommandKind::Blank => todo!(), + } + } +} + fn main() { let mut filesystem = luminol_filesystem::project::FileSystem::new(); // hardcoding the path for now @@ -20,4 +74,17 @@ fn main() { let mut map = data_cache.get_or_load_map(1, &filesystem, &config); let event = map.events.remove(1); + for page in event.pages { + let mut arena = indextree::Arena::::new(); + + let root = arena.new_node(rpg::EventCommand::default()); + + let mut iter = page.list.into_iter().peekable(); + while let Some(command) = iter.next() { + parse_command_under(root, command, &mut arena, &mut iter, &config); + } + + let printable = root.debug_pretty_print(&arena); + println!("{printable:?}") + } } diff --git a/crates/data/src/shared/event.rs b/crates/data/src/shared/event.rs index cea6dc31..d9b9cec9 100644 --- a/crates/data/src/shared/event.rs +++ b/crates/data/src/shared/event.rs @@ -284,7 +284,7 @@ impl From for String { } } -#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)] +#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, Default)] #[derive(alox_48::Deserialize, alox_48::Serialize)] #[allow(missing_docs)] #[marshal(class = "RPG::EventCommand")] @@ -292,10 +292,4 @@ pub struct EventCommand { pub code: u16, pub indent: usize, pub parameters: Vec, - - #[marshal(default = "rand::random")] - #[marshal(skip)] - #[serde(default = "rand::random")] - #[serde(skip)] - pub guid: u16, }