#[cfg(not(target_arch = "wasm32"))] mod setup { pub fn get_asset_path_string() -> String { std::env::current_dir() .unwrap() .join("assets") .to_str() .unwrap() .to_string() } pub fn initial_size() -> (f32, f32) { (16.0 * 32.0, 16.0 * 18.0) } } #[cfg(target_arch = "wasm32")] mod setup { pub fn get_asset_path_string() -> String { String::from("assets") } #[cfg(feature = "no_aspect")] pub fn initial_size() -> (f32, f32) { static default_width: f32 = 16.0 * 32.0; static default_height: f32 = 16.0 * 18.0; web_sys::window() .and_then(|window: web_sys::Window| { let w = window .inner_width() .ok() .and_then(|val| val.as_f64().map(|v| v as f32)) .unwrap_or(default_width); let h = window .inner_height() .ok() .and_then(|val| val.as_f64().map(|v| v as f32)) .unwrap_or(default_height); log::info!("Using w/h without ratio: {}/{}", w, h); Some((w, h)) }) .unwrap_or((default_width, default_height)) } #[cfg(not(feature = "no_aspect"))] pub fn initial_size() -> (f32, f32) { static default_width: f32 = 16.0 * 32.0; static default_height: f32 = 16.0 * 18.0; static ratio: f32 = default_width / default_height; web_sys::window() .and_then(|window: web_sys::Window| { let w = window .inner_width() .ok() .and_then(|val| val.as_f64().map(|v| v as f32)) .unwrap_or(default_width); let h = window .inner_height() .ok() .and_then(|val| val.as_f64().map(|v| v as f32)) .unwrap_or(default_height); log::info!("Using w/h with ratio: {}/{}", w, h / ratio); Some((w, h / ratio)) }) .unwrap_or((default_width, default_height)) } } pub use setup::*;