Skip to content

Commit a8be2cc

Browse files
committed
fixes #148, pass args for wasm usage
1 parent c634779 commit a8be2cc

File tree

16 files changed

+210
-72
lines changed

16 files changed

+210
-72
lines changed

Cargo.lock

Lines changed: 90 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/notation_kb/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ resources = ["assets"]
1212
default = [
1313
"notation_bevy/midi",
1414
]
15+
1516
native = [
1617
"notation_bevy/native",
17-
]
18-
dev = [
19-
"notation_bevy/dev",
20-
"native",
18+
"notation_bevy/dsl",
2119
]
2220

2321
[dependencies]
2422
notation_bevy = { path = "../../crates/notation_bevy" }
2523
notation_viewer = { path = "../notation_viewer" }
24+
clap = { version = "3.0.12", features = [ "derive" ] }

apps/notation_viewer/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ native = [
1717
"notation_bevy/native",
1818
"notation_bevy/dsl",
1919
]
20-
dev = [
21-
"notation_bevy/dev",
22-
"native",
23-
]
2420

2521
[dependencies]
26-
notation_bevy = { path = "../../crates/notation_bevy" }
22+
notation_bevy = { path = "../../crates/notation_bevy" }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cargo run --features native -- --lang zh-CN

apps/notation_viewer/src/main.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
use notation_bevy::bevy::prelude::bevy_main;
1+
use notation_bevy::{bevy::prelude::bevy_main, prelude::NotationArgs};
22
use notation_viewer::assets::NotationViewerAssets;
33

44
#[bevy_main]
55
fn main() {
6-
#[cfg(target_arch = "wasm32")]
7-
let tabs = vec![notation_bevy::prelude::NotationApp::get_tab_from_url()
8-
.unwrap_or("tabs/scarborough_fair.ron".to_owned())];
9-
10-
#[cfg(not(target_arch = "wasm32"))]
11-
let tabs = vec![
12-
"tabs/test.ron".to_owned(),
13-
"tabs/scarborough_fair.ron".to_owned(),
14-
];
15-
notation_viewer::viewer::NotationViewer::run::<NotationViewerAssets>(tabs);
6+
let args = NotationArgs::parse_args();
7+
notation_viewer::viewer::NotationViewer::run::<NotationViewerAssets>(args);
168
}

apps/notation_viewer/src/viewer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use notation_bevy::bevy_egui::EguiContext;
55
use notation_bevy::prelude::*;
66
use notation_bevy::settings::layout_settings::LayoutMode;
77

8-
use crate::assets::NotationViewerAssets;
98
use crate::help_panel::HelpPanel;
109

1110
pub struct NotationViewer();
@@ -24,8 +23,8 @@ impl NotationViewer {
2423
.with_system(HelpPanel::handle_link_evts)
2524
);
2625
}
27-
pub fn run<A: ExtraAssets>(tabs: Vec<String>) {
28-
notation_bevy::prelude::NotationApp::run_with_extra::<A, _>(tabs, Self::extra);
26+
pub fn run<A: ExtraAssets>(args: NotationArgs) {
27+
notation_bevy::prelude::NotationApp::run_with_extra::<A, _>(args, Self::extra);
2928
}
3029
}
3130

crates/notation_bevy/Cargo.toml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@ default = [
1919
"bevy/png",
2020
]
2121

22-
dev = [
23-
#"bevy/dynamic",
24-
"notation_bevy_utils/dev",
25-
]
26-
2722
native = [
28-
# "bevy/bevy_wgpu",
23+
"clap",
2924
]
3025

3126
midi = [
@@ -67,13 +62,15 @@ rfd = "0.6.3"
6762
lazy_static = "1.4.0"
6863
unic-langid = { version = "0.9", features = [ "macros" ] }
6964

65+
clap = { version = "3.0.12", features = [ "derive" ], optional = true }
66+
7067
[target.'cfg(target_arch = "wasm32")'.dependencies]
7168
wasm-bindgen = "0.2.78"
7269
console_error_panic_hook = "0.1"
7370
gloo-events = "0.1.1"
7471
futures = "0.3"
7572
web-sys = { version = "0.3.55", features = [
76-
"Element", "Document", "Window", "Location", "console", "TouchEvent",
73+
"Element", "Document", "Window", "Location", "Url", "UrlSearchParams", "console", "TouchEvent",
7774
#https://rustwasm.github.io/docs/wasm-bindgen/examples/web-audio.html
7875
"AudioContext", "AudioDestinationNode", "AudioNode", "AudioParam", "GainNode", "OscillatorNode", "OscillatorType",
7976
]}

crates/notation_bevy/src/egui/egui_fonts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::RwLock;
33
use bevy::prelude::*;
44
use bevy_egui::{egui::{FontDefinitions, FontData, FontFamily, TextStyle}, EguiContext};
55

6-
use crate::{notation::assets::{ExtraAssets, NotationAssets}, settings::notation_settings::NotationSettings};
6+
use crate::prelude::{ExtraAssets, NotationSettings};
77

88
lazy_static! {
99
static ref EGUI_FONT: RwLock<EguiFont> = RwLock::new(EguiFont::default());

crates/notation_bevy/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,11 @@ pub mod prelude {
141141
#[doc(hidden)]
142142
pub use crate::notation::app::{NotationApp, NotationPlugins};
143143
#[doc(hidden)]
144+
pub use crate::notation::args::{NotationArgs};
145+
#[doc(hidden)]
144146
pub use crate::notation::events::*;
145147
#[doc(hidden)]
146-
pub use crate::notation::state::{NotationState, TabPathes};
148+
pub use crate::notation::state::{NotationState};
147149
#[doc(hidden)]
148150
pub use crate::notation::assets::{NotationAssets, NotationAssetsStates, ExtraAssets, NoExtraAssets};
149151
#[doc(hidden)]

crates/notation_bevy/src/notation/app.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ use notation_midi::prelude::{
1414
MidiPlugin,
1515
};
1616

17-
use super::state::{NotationState, TabPathes};
18-
1917
pub struct NotationPlugins;
2018
impl PluginGroup for NotationPlugins {
2119
fn build(&mut self, group: &mut PluginGroupBuilder) {
@@ -47,8 +45,9 @@ pub struct NotationApp;
4745
impl NotationApp {
4846
pub const TITLE: &'static str = "Fun Notation";
4947

50-
pub fn new_app<A: ExtraAssets>(title: &str) -> App {
48+
pub fn new_app<A: ExtraAssets>(args: NotationArgs, title: &str) -> App {
5149
let mut app = App::new();
50+
app.insert_resource(args);
5251
AssetLoader::new(NotationAssetsStates::Loading)
5352
.continue_to_state(NotationAssetsStates::Loaded)
5453
.with_collection::<NotationAssets>()
@@ -89,24 +88,13 @@ impl NotationApp {
8988
app
9089
}
9190

92-
#[cfg(target_arch = "wasm32")]
93-
pub fn get_tab_from_url() -> Result<String, String> {
94-
web_sys::window()
95-
.ok_or("No_Window".to_owned())
96-
.and_then(|x| x.document().ok_or("No_Document".to_owned()))
97-
.and_then(|x| x.location().ok_or("No_Location".to_owned()))
98-
.and_then(|x| x.search().map_err(|e| format!("No_Search:{:?}", e)))
99-
.map(|x| x.trim_start_matches('?').to_owned())
100-
}
101-
102-
pub fn run_with_extra<A, F>(tab_pathes: Vec<String>, extra: F)
91+
pub fn run_with_extra<A, F>(args: NotationArgs, extra: F)
10392
where
10493
A: ExtraAssets,
10594
F: Fn(&mut App),
10695
{
107-
let mut app = NotationApp::new_app::<A>(Self::TITLE);
96+
let mut app = NotationApp::new_app::<A>(args, Self::TITLE);
10897

109-
app.insert_resource(TabPathes(tab_pathes));
11098
app.init_resource::<NotationState>();
11199

112100
app.add_startup_system(Self::setup_camera);
@@ -135,8 +123,8 @@ impl NotationApp {
135123
extra(&mut app);
136124
app.run();
137125
}
138-
pub fn run<A: ExtraAssets>(tab_pathes: Vec<String>) {
139-
Self::run_with_extra::<A, _>(tab_pathes, |_app|{})
126+
pub fn run<A: ExtraAssets>(args: NotationArgs) {
127+
Self::run_with_extra::<A, _>(args, |_app|{})
140128
}
141129
}
142130

0 commit comments

Comments
 (0)