From 1c7dba07c07ad07078bb3a6ce1cb34e52520be9e Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Sat, 12 Jul 2025 20:52:04 -0700 Subject: [PATCH] Load all monologues in wasm build (hopefully) by loading each one by one --- .gitignore | 3 ++ Cargo.lock | 1 + Cargo.toml | 1 + build.rs | 93 ++++++++++++++++++++++++++----------------- src/bin/trees/main.rs | 16 +++----- 5 files changed, 66 insertions(+), 48 deletions(-) diff --git a/.gitignore b/.gitignore index 51d78b1..5432161 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ dist/* # Generated VERSION file for builds VERSION + +# Generated MONOLOGUES list for wasm build +assets/trees/MONOLOGUES diff --git a/Cargo.lock b/Cargo.lock index 6516517..e1810b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2228,6 +2228,7 @@ dependencies = [ "chrono", "serde", "thiserror 2.0.12", + "walkdir", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 9bcf9db..791a326 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,4 @@ features = ["wayland", "dynamic_linking"] [build-dependencies] chrono = "*" +walkdir = "*" diff --git a/build.rs b/build.rs index c9c82fb..f40b036 100644 --- a/build.rs +++ b/build.rs @@ -1,40 +1,59 @@ +use std::fs::File; +use std::io::Write; + fn main() { - { - use chrono::prelude::*; - use std::fs::File; - use std::io::Write; - use std::process::Command; - - // Date of build - let now = Utc::now().format("%Y%m%d%H%M%S"); - - // Latest commit ID - let git_sha = String::from_utf8( - Command::new("git") - .arg("rev-parse") - .arg("--short") - .arg("HEAD") - .output() - .expect("Failed to get git sha") - .stdout, - ) - .expect("Read stdout from git sha command"); - - // If the workspace is dirty or clean - let clean = Command::new("git") - .arg("diff") - .arg("--quiet") - .status() - .expect("Failed to run git diff") - .success(); - - let mut file = File::create("VERSION").expect("Create VERSION file"); - - if clean { - write!(file, "0.0.0-{now}+{}", git_sha.trim()).expect("Write version to VERSION file"); - } else { - write!(file, "0.0.0-{now}+{}-dirty", git_sha.trim()) - .expect("Write version to VERSION file"); - } + write_version_file(); + + write_monologues_file(); +} + +fn write_version_file() { + use chrono::prelude::*; + use std::process::Command; + + // Date of build + let now = Utc::now().format("%Y%m%d%H%M%S"); + + // Latest commit ID + let git_sha = String::from_utf8( + Command::new("git") + .arg("rev-parse") + .arg("--short") + .arg("HEAD") + .output() + .expect("Failed to get git sha") + .stdout, + ) + .expect("Read stdout from git sha command"); + + // If the workspace is dirty or clean + let clean = Command::new("git") + .arg("diff") + .arg("--quiet") + .status() + .expect("Failed to run git diff") + .success(); + + let mut file = File::create("VERSION").expect("Create VERSION file"); + + if clean { + write!(file, "0.0.0-{now}+{}", git_sha.trim()).expect("Write version to VERSION file"); + } else { + write!(file, "0.0.0-{now}+{}-dirty", git_sha.trim()) + .expect("Write version to VERSION file"); } } + +fn write_monologues_file() { + let mut file = File::create("assets/trees/MONOLOGUES").expect("Create MONOLOGUES file"); + + walkdir::WalkDir::new("assets/trees") + .into_iter() + .filter_map(|entry| entry.ok()) + .filter(|entry| { + entry.path().extension() == Some(std::ffi::OsStr::new("mono")) + }) + .for_each(|entry| { + let _ = writeln!(file, "{}", entry.path().to_string_lossy().strip_prefix("assets/").unwrap()); + }); +} diff --git a/src/bin/trees/main.rs b/src/bin/trees/main.rs index 979ede6..775ec52 100644 --- a/src/bin/trees/main.rs +++ b/src/bin/trees/main.rs @@ -528,17 +528,11 @@ fn delete_tree(trigger: Trigger>, mut commands: Commands) { /// Load all monologues so they are in the asset store and trigger on-load events fn load_monologues( server: ResMut, - mut loaded_folder: Local>, mut loaded_assets: Local>>, ) { - // TODO: Figure out a programatic way to load all assets in the web version... - // Likely a mega asset that points to all sub-assets or something silly - *loaded_folder = server.load_folder("trees"); - *loaded_assets = vec![ - server.load("trees/red.mono"), - server.load("trees/green.mono"), - server.load("trees/blue.mono"), - ]; + *loaded_assets = include_str!("../../../assets/trees/MONOLOGUES").split("\n").map(|path| { + server.load(path) + }).collect(); } fn spawn_debug_buttons( @@ -667,7 +661,7 @@ fn populate_tree( let y: f32 = b.cast_signed().wrapping_div(4).into(); // Avoid mesh clipping by offsetting each on the z axis let z = trees.iter().len() as f32; - info!("Coordiantes: {x} {y}"); + debug!("Coordiantes: {x} {y}"); Transform::from_xyz(x, z, y).with_scale(Vec3::splat(10.0)) }; @@ -680,7 +674,7 @@ fn populate_tree( let mesh = Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.0)))); - info!("Fleshing out monologuing tree"); + debug!("Fleshing out monologuing tree"); commands .entity(trigger.target())