summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/teleia/src/state.rs9
-rw-r--r--crates/teleia_macros/Cargo.toml4
-rw-r--r--crates/teleia_macros/src/lib.rs23
3 files changed, 20 insertions, 16 deletions
diff --git a/crates/teleia/src/state.rs b/crates/teleia/src/state.rs
index 3df5d7c..4031421 100644
--- a/crates/teleia/src/state.rs
+++ b/crates/teleia/src/state.rs
@@ -6,7 +6,7 @@ use serde::{Serialize, Deserialize};
use crate::{audio, context, framebuffer, mesh, shader, utils};
-const DELTA_TIME: f64 = 1.0 / 61.0; // todo
+const DELTA_TIME: f64 = 0.016; // todo
pub struct WinitWaker {}
impl WinitWaker {
@@ -25,9 +25,10 @@ pub struct Response {
pub trait Game {
fn initialize(&self, ctx: &context::Context, st: &State) -> utils::Erm<()> { Ok(()) }
fn finalize(&self, ctx: &context::Context, st: &State) -> utils::Erm<()> { Ok(()) }
- fn initialize_audio(&self, ctx: &context::Context, st: &State, actx: &audio::Context) ->
- HashMap<String, audio::Audio>
- {
+ fn initialize_audio(
+ &self, ctx: &context::Context, st: &State,
+ actx: &audio::Context
+ ) -> HashMap<String, audio::Audio> {
HashMap::new()
}
fn finish_title(&mut self, st: &mut State) {}
diff --git a/crates/teleia_macros/Cargo.toml b/crates/teleia_macros/Cargo.toml
index b56494e..a3d4fe6 100644
--- a/crates/teleia_macros/Cargo.toml
+++ b/crates/teleia_macros/Cargo.toml
@@ -8,5 +8,7 @@ authors.workspace = true
proc-macro = true
[dependencies]
+env = "*"
walkdir = "*"
-heck = "*" \ No newline at end of file
+heck = "*"
+litrs = "*" \ No newline at end of file
diff --git a/crates/teleia_macros/src/lib.rs b/crates/teleia_macros/src/lib.rs
index d095873..664fc01 100644
--- a/crates/teleia_macros/src/lib.rs
+++ b/crates/teleia_macros/src/lib.rs
@@ -1,11 +1,9 @@
-use proc_macro::TokenStream;
+use proc_macro::{TokenStream};
use std::path::Path;
use std::collections::HashSet;
use walkdir::WalkDir;
use heck::ToUpperCamelCase;
-const BASE: &'static str = "src/assets/";
-
#[derive(Debug, Hash, PartialEq, Eq)]
struct Designator {
parts: Vec<String>,
@@ -26,7 +24,6 @@ impl Designator {
}
}
fn enum_entry(&self, _fnm: &str) -> String {
- let vs: Vec<_> = self.parts.iter().map(|s| s.to_uppercase()).collect();
format!("{}", self.parts.join(" ").to_upper_camel_case())
}
fn load_expr(&self, fnm: &str) -> Option<String> {
@@ -54,9 +51,9 @@ struct Field {
entries: HashSet<Designator>,
}
impl Field {
- fn new(nm: &str) -> Self {
+ fn new(base: &str, nm: &str) -> Self {
let mut entries = HashSet::new();
- let fbase = format!("{}{}", BASE, nm);
+ let fbase = format!("{}{}", base, nm);
for mf in WalkDir::new(&fbase) {
if let Ok(f) = mf {
if f.file_type().is_file() {
@@ -105,12 +102,12 @@ struct AssetData {
fields: Vec<Field>,
}
impl AssetData {
- fn new() -> Self {
+ fn new(base: &str) -> Self {
let mut fields = Vec::new();
- let dirs = std::fs::read_dir(BASE).expect("failed to read assets directory");
+ let dirs = std::fs::read_dir(base).expect(&format!("failed to read assets directory: {}", base));
for dir in dirs {
if let Ok(d) = dir {
- fields.push(Field::new(&d.file_name().into_string().unwrap()));
+ fields.push(Field::new(base, &d.file_name().into_string().unwrap()));
}
}
Self {
@@ -139,8 +136,12 @@ impl AssetData {
}
#[proc_macro]
-pub fn generate_assets(_s: TokenStream) -> TokenStream {
- let assets = AssetData::new();
+pub fn generate_assets(s: TokenStream) -> TokenStream {
+ let token = s.into_iter().next().expect("must pass asset base path as a string literal");
+ let lit = litrs::StringLit::try_from(token).expect("argument was not a string literal");
+ let base = lit.value();
+ let manifest = env::var("CARGO_MANIFEST_DIR").expect("failed to get manifest path");
+ let assets = AssetData::new(&format!("{}/{}", manifest, base));
// println!("{}", assets.generate());
format!("{}", assets.generate()).parse().expect("failed to parse generate_assets result")
}