WIP parser for world definitions file

This commit is contained in:
yuni 2024-03-20 04:34:09 +01:00
parent 2c7f2b2ab7
commit 4394905d17
3 changed files with 64 additions and 1 deletions

1
Cargo.lock generated
View file

@ -2661,6 +2661,7 @@ name = "outfly"
version = "0.1.3" version = "0.1.3"
dependencies = [ dependencies = [
"bevy", "bevy",
"regex",
] ]
[[package]] [[package]]

View file

@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
regex = "1"
bevy = { version = "0.13.0", features = ["jpeg", "minimp3", "dynamic_linking"] } bevy = { version = "0.13.0", features = ["jpeg", "minimp3", "dynamic_linking"] }
#bevy = { version = "0.13.0", features = ["jpeg", "minimp3"] } #bevy = { version = "0.13.0", features = ["jpeg", "minimp3"] }

View file

@ -1,4 +1,6 @@
extern crate regex;
use crate::{actor, camera, nature}; use crate::{actor, camera, nature};
use regex::Regex;
use bevy::prelude::*; use bevy::prelude::*;
//use bevy::core_pipeline::Skybox; //use bevy::core_pipeline::Skybox;
//use bevy::asset::LoadState; //use bevy::asset::LoadState;
@ -28,7 +30,7 @@ const ASSET_JUPITER: &str = "models/jupiter.glb#Scene0";
pub struct WorldPlugin; pub struct WorldPlugin;
impl Plugin for WorldPlugin { impl Plugin for WorldPlugin {
fn build(&self, app: &mut App) { 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, asset_loaded.after(load_cubemap_asset));
//app.add_systems(Update, swap_world_on_ar_toggle); //app.add_systems(Update, swap_world_on_ar_toggle);
app.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0))); 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( //pub fn swap_world_on_ar_toggle(
// asset_server: Res<AssetServer>, // asset_server: Res<AssetServer>,
// mut images: ResMut<Assets<Image>>, // mut images: ResMut<Assets<Image>>,