Newer
Older
#[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) {
(1280.0, 720.0)
}
}
#[cfg(target_arch = "wasm32")]
mod setup {
pub fn get_asset_path_string() -> String {
String::from("assets")
}
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#[cfg(feature = "no_aspect")]
pub fn initial_size() -> (f32, f32) {
static default_width: f32 = 1280.0;
static default_height: f32 = 720.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);
Some((w, h))
})
.unwrap_or((default_width, default_height))
}
#[cfg(not(feature = "no_aspect"))]
pub fn initial_size() -> (f32, f32) {
static default_width: f32 = 1280.0;
static default_height: f32 = 720.0;
static ratio: f32 = 1280.0 / 720.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);
Some((w, h / ratio))
})
.unwrap_or((default_width, default_height))
}
}
pub use setup::*;