nesbox_utils/
lib.rs

1pub mod prelude {
2    pub use crate::assets::*;
3    pub use crate::audio::*;
4    pub use crate::codes::*;
5    pub use crate::create_bevy_app;
6    pub use crate::input::*;
7    pub use crate::log;
8    pub use crate::pixels::*;
9    pub use crate::render::*;
10    pub use bevy::core::*;
11    pub use bevy::ecs::system::*;
12    pub use bevy::prelude::*;
13    pub use nesbox_utils_macro::nesbox_bevy;
14    pub use rand::prelude::random;
15    pub use wasm_bindgen;
16    pub use wasm_bindgen::prelude::*;
17}
18
19use assets::AssetsPlugin;
20use audio::AudioPlugin;
21use bevy::{prelude::*, time::TimePlugin};
22use input::{ButtonInput, MouseEvent};
23use pixels::Color;
24use render::RenderPlugin;
25
26pub use bevy;
27pub use wasm_bindgen;
28pub use wasm_bindgen::prelude::*;
29pub mod assets;
30pub mod audio;
31pub mod codes;
32pub mod input;
33pub mod pixels;
34pub mod render;
35
36#[wasm_bindgen]
37extern "C" {
38    #[wasm_bindgen(js_namespace = console, js_name = log)]
39    pub fn _log(s: &str);
40}
41
42#[macro_export]
43macro_rules! log {
44    ($($arg:tt)*) => {{
45        #[cfg(target_arch = "wasm32")]
46        $crate::_log(&format!($($arg)*));
47    }};
48}
49
50pub fn create_bevy_app(width: u32, height: u32, clear_color: Color) -> App {
51    if height > 0xff {
52        panic!("height too much big");
53    }
54    let mut app = App::new();
55
56    #[cfg(debug_assertions)]
57    app.add_plugin(bevy::log::LogPlugin::default());
58
59    app.add_plugin(RenderPlugin {
60        width,
61        height,
62        clear_color,
63    })
64    .add_plugin(AudioPlugin::default())
65    .add_plugin(AssetsPlugin::default())
66    .add_plugin(TaskPoolPlugin::default())
67    .add_plugin(TypeRegistrationPlugin::default())
68    .add_plugin(FrameCountPlugin::default())
69    .add_plugin(TimePlugin::default())
70    .add_plugin(TransformPlugin::default())
71    .add_plugin(HierarchyPlugin::default())
72    .add_event::<MouseEvent>()
73    .init_resource::<ButtonInput>();
74
75    app
76}
77
78#[wasm_bindgen(start)]
79pub fn run() {
80    let mut app = create_bevy_app(1, 1, Color::default());
81    app.update();
82    log!("WASM import bevy deps");
83}