Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
77
78
79
80
81
82
const WINDOW_SCALER: f32 = 2.0;
#[cfg(not(target_arch = "wasm32"))]
mod setup {
use crate::system::resource_config::WINDOW_SCALER;
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) {
(1920.0, 1080.0)
}
pub fn virtual_size() -> (f32, f32) {
(1280.0 / WINDOW_SCALER, 720.0 / WINDOW_SCALER)
}
}
#[cfg(target_arch = "wasm32")]
mod setup {
use crate::system::load_config::WINDOW_SCALER;
pub fn get_asset_path_string() -> String {
String::from("assets")
}
pub fn virtual_size() -> (f32, f32) {
(1280.0 / WINDOW_SCALER, 720.0 / WINDOW_SCALER)
}
#[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::*;