diff --git a/Cargo.lock b/Cargo.lock index 09ae1af..70a53b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2661,6 +2661,7 @@ name = "outfly" version = "0.1.3" dependencies = [ "bevy", + "regex", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ad91adc..c6d0a02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +regex = "1" bevy = { version = "0.13.0", features = ["jpeg", "minimp3", "dynamic_linking"] } #bevy = { version = "0.13.0", features = ["jpeg", "minimp3"] } diff --git a/src/world.rs b/src/world.rs index a2dc5e7..d23bb65 100644 --- a/src/world.rs +++ b/src/world.rs @@ -1,4 +1,6 @@ +extern crate regex; use crate::{actor, camera, nature}; +use regex::Regex; use bevy::prelude::*; //use bevy::core_pipeline::Skybox; //use bevy::asset::LoadState; @@ -28,7 +30,7 @@ const ASSET_JUPITER: &str = "models/jupiter.glb#Scene0"; pub struct WorldPlugin; impl Plugin for WorldPlugin { fn build(&self, app: &mut App) { - app.add_systems(Startup, setup); + app.add_systems(Startup, (setup, load_defs)); //app.add_systems(Update, asset_loaded.after(load_cubemap_asset)); //app.add_systems(Update, swap_world_on_ar_toggle); app.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0))); @@ -312,6 +314,65 @@ pub fn setup( }); } +pub fn load_defs( +) { + let re1 = Regex::new(r"^\s*([a-z]+)\s+(.*)$").unwrap(); + let re2 = Regex::new("\"([^\"]*)\"|([0-9]+(?:\\.[0-9]+)?)").unwrap(); + let defs_string = include_str!("defs.txt"); + let mut lines = defs_string.lines(); + let mut line_nr = -1; + while let Some(line) = lines.next() { + line_nr += 1; + let caps = re1.captures(line); + if caps.is_none() { + if line.trim() != "" { + info!("Syntax Error in definitions line {}: `{}`", line_nr, line); + } + continue; + } + let command = caps.unwrap().get(1).unwrap().as_str(); + info!(command); + + let mut parts: Vec<&str> = Vec::new(); + parts.push(command); + for caps in re2.captures_iter(line) { + if let Some(part) = caps.get(1) { + parts.push(&part.as_str()); + } + if let Some(part) = caps.get(2) { + parts.push(&part.as_str()); + } + } + + match parts.as_slice() { + ["chat", chat_name] => { + info!("Registering chat: {}", chat_name); + } + ["msg", sleep, text] => { + info!("Registering message (sleep={}): {}", sleep, text); + } + ["choice", sleep, text] => { + info!("Registering choice (sleep={}): {}", sleep, text); + } + ["goto", label] => { + info!("Registering goto: {}", label); + } + ["label", label] => { + info!("Registering label: {}", label); + } + ["name", name] => { + info!("Registering name: {}", name); + } + ["lvl", level] => { + info!("Registering level: {}", level); + } + _ => { + error!("No match for [{}]", parts.join(",")); + } + } + } +} + //pub fn swap_world_on_ar_toggle( // asset_server: Res, // mut images: ResMut>,