From 431789189a7939b27ed2506115d06f0910555c4e Mon Sep 17 00:00:00 2001 From: tuxmain Date: Sun, 28 Aug 2022 19:33:41 +0200 Subject: [PATCH] fix(wasm): request permission for media autoplay if needed --- Cargo.lock | 405 +------------------------------- Cargo.toml | 6 +- README.md | 6 +- assets/silence.wav | 0 index.html | 4 +- cover.png => res/cover.png | Bin cover.xcf => res/cover.xcf | Bin {assets/sound => res}/notes.flp | Bin src/audio_system.rs | 23 +- src/game.rs | 42 +--- src/levels.rs | 4 +- src/main.rs | 3 +- src/menu.rs | 16 -- 13 files changed, 43 insertions(+), 466 deletions(-) create mode 100644 assets/silence.wav rename cover.png => res/cover.png (100%) rename cover.xcf => res/cover.xcf (100%) rename {assets/sound => res}/notes.flp (100%) diff --git a/Cargo.lock b/Cargo.lock index a0cd1a3..18bf35e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -123,25 +123,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "arboard" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc120354d1b5ec6d7aaf4876b602def75595937b5e15d356eb554ab5177e08bb" -dependencies = [ - "clipboard-win", - "core-graphics 0.22.3", - "image 0.23.14", - "log", - "objc", - "objc-foundation", - "objc_id", - "parking_lot 0.12.1", - "thiserror", - "winapi", - "x11rb", -] - [[package]] name = "arrayvec" version = "0.7.2" @@ -188,12 +169,6 @@ version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" -[[package]] -name = "atomic_refcell" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b5e5f48b927f04e952dedc932f31995a65a0bf65ec971c74436e51bf6e970d" - [[package]] name = "autocfg" version = "1.1.0" @@ -215,30 +190,6 @@ dependencies = [ "bevy_internal", ] -[[package]] -name = "bevy-inspector-egui" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c53ed1cad011e33ea145d2c1f649a966e7457453f3768ddff39bc5064bd525" -dependencies = [ - "bevy", - "bevy-inspector-egui-derive", - "bevy_egui", - "image 0.23.14", - "pretty-type-name", -] - -[[package]] -name = "bevy-inspector-egui-derive" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48ef6260a46924d40781bcb9da157c110d5166bbd573795e4a16f2505913d0d0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "bevy_animation" version = "0.8.1" @@ -416,19 +367,6 @@ dependencies = [ "syn", ] -[[package]] -name = "bevy_egui" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf44ff770566dca66b805a6829df783f64700bd01d35aec1034dff31b531a4" -dependencies = [ - "arboard", - "bevy", - "egui", - "thread_local", - "webbrowser", -] - [[package]] name = "bevy_encase_derive" version = "0.8.1" @@ -710,7 +648,7 @@ dependencies = [ "futures-lite", "hex", "hexasphere", - "image 0.24.3", + "image", "naga", "once_cell", "parking_lot 0.12.1", @@ -1066,17 +1004,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "clipboard-win" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4ab1b92798304eedc095b53942963240037c0516452cb11aeba709d420b2219" -dependencies = [ - "error-code", - "str-buf", - "winapi", -] - [[package]] name = "cocoa" version = "0.24.0" @@ -1422,16 +1349,6 @@ dependencies = [ "syn", ] -[[package]] -name = "deflate" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174" -dependencies = [ - "adler32", - "byteorder", -] - [[package]] name = "deflate" version = "1.0.0" @@ -1453,32 +1370,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" -[[package]] -name = "egui" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb095a8b9feb9b7ff8f00b6776dffcef059538a3f4a91238e03c900e9c9ad9a2" -dependencies = [ - "ahash", - "epaint", - "nohash-hasher", -] - [[package]] name = "either" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" -[[package]] -name = "emath" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c223f58c7e38abe1770f367b969f1b3fbd4704b67666bcb65dbb1adb0980ba72" -dependencies = [ - "bytemuck", -] - [[package]] name = "encase" version = "0.3.0" @@ -1521,21 +1418,6 @@ dependencies = [ "regex", ] -[[package]] -name = "epaint" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c29567088888e8ac3e8f61bbb2ddc820207ebb8d69eefde5bcefa06d65e4e89" -dependencies = [ - "ab_glyph", - "ahash", - "atomic_refcell", - "bytemuck", - "emath", - "nohash-hasher", - "parking_lot 0.12.1", -] - [[package]] name = "erased-serde" version = "0.3.23" @@ -1545,16 +1427,6 @@ dependencies = [ "serde", ] -[[package]] -name = "error-code" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21" -dependencies = [ - "libc", - "str-buf", -] - [[package]] name = "euclid" version = "0.22.7" @@ -1618,16 +1490,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" -[[package]] -name = "form_urlencoded" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" -dependencies = [ - "matches", - "percent-encoding", -] - [[package]] name = "fsevent-sys" version = "4.1.0" @@ -1673,16 +1535,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "gethostname" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "getrandom" version = "0.2.7" @@ -1920,33 +1772,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" -[[package]] -name = "idna" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "image" -version = "0.23.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1" -dependencies = [ - "bytemuck", - "byteorder", - "color_quant", - "num-iter", - "num-rational 0.3.2", - "num-traits", - "png 0.16.8", - "tiff", -] - [[package]] name = "image" version = "0.24.3" @@ -1956,9 +1781,9 @@ dependencies = [ "bytemuck", "byteorder", "color_quant", - "num-rational 0.4.1", + "num-rational", "num-traits", - "png 0.17.5", + "png", "scoped_threadpool", ] @@ -2061,12 +1886,6 @@ dependencies = [ "libc", ] -[[package]] -name = "jpeg-decoder" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2" - [[package]] name = "js-sys" version = "0.3.59" @@ -2164,9 +1983,9 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" dependencies = [ "autocfg", "scopeguard", @@ -2186,19 +2005,14 @@ name = "lux-synthese" version = "0.1.0" dependencies = [ "bevy", - "bevy-inspector-egui", "bevy_common_assets", "bevy_mod_picking", "bevy_rapier2d", - "cpal 0.14.0", - "crossbeam-channel", - "hexodsp", "rand", "rand_distr", "rapier2d", "serde", "serde_json", - "ticktock", ] [[package]] @@ -2228,12 +2042,6 @@ dependencies = [ "regex-automata", ] -[[package]] -name = "matches" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" - [[package]] name = "matrixmultiply" version = "0.3.2" @@ -2278,25 +2086,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "miniz_oxide" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" -dependencies = [ - "adler32", -] - -[[package]] -name = "miniz_oxide" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" -dependencies = [ - "adler", - "autocfg", -] - [[package]] name = "miniz_oxide" version = "0.5.3" @@ -2351,7 +2140,7 @@ dependencies = [ "matrixmultiply", "nalgebra-macros", "num-complex", - "num-rational 0.4.1", + "num-rational", "num-traits", "simba", "typenum", @@ -2459,19 +2248,6 @@ dependencies = [ "jni-sys", ] -[[package]] -name = "nix" -version = "0.22.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf" -dependencies = [ - "bitflags", - "cc", - "cfg-if 1.0.0", - "libc", - "memoffset", -] - [[package]] name = "nix" version = "0.23.1" @@ -2496,12 +2272,6 @@ dependencies = [ "libc", ] -[[package]] -name = "nohash-hasher" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" - [[package]] name = "nom" version = "7.1.1" @@ -2560,28 +2330,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-iter" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - [[package]] name = "num-rational" version = "0.4.1" @@ -2644,17 +2392,6 @@ dependencies = [ "objc_exception", ] -[[package]] -name = "objc-foundation" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" -dependencies = [ - "block", - "objc", - "objc_id", -] - [[package]] name = "objc_exception" version = "0.1.2" @@ -2664,15 +2401,6 @@ dependencies = [ "cc", ] -[[package]] -name = "objc_id" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" -dependencies = [ - "objc", -] - [[package]] name = "oboe" version = "0.4.6" @@ -2841,18 +2569,6 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" -[[package]] -name = "png" -version = "0.16.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" -dependencies = [ - "bitflags", - "crc32fast", - "deflate 0.8.6", - "miniz_oxide 0.3.7", -] - [[package]] name = "png" version = "0.17.5" @@ -2861,8 +2577,8 @@ checksum = "dc38c0ad57efb786dd57b9864e5b18bae478c00c824dc55a38bbc9da95dde3ba" dependencies = [ "bitflags", "crc32fast", - "deflate 1.0.0", - "miniz_oxide 0.5.3", + "deflate", + "miniz_oxide", ] [[package]] @@ -2880,12 +2596,6 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" -[[package]] -name = "pretty-type-name" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8815d101cfb4cb491154896bdab292a395a7ac9ab185a9941a2f5be0135900d" - [[package]] name = "proc-macro-crate" version = "1.2.1" @@ -3249,12 +2959,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef5430c8e36b713e13b48a9f709cc21e046723fe44ce34587b73a830203b533e" -[[package]] -name = "str-buf" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" - [[package]] name = "strsim" version = "0.10.0" @@ -3329,23 +3033,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "ticktock" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d226b8341a5d130e3446024468efab6d150ba656e086b793ac37a3d17669e626" - -[[package]] -name = "tiff" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437" -dependencies = [ - "jpeg-decoder", - "miniz_oxide 0.4.4", - "weezl", -] - [[package]] name = "tinyvec" version = "1.6.0" @@ -3455,27 +3142,12 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" -[[package]] -name = "unicode-bidi" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" - [[package]] name = "unicode-ident" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" -[[package]] -name = "unicode-normalization" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-width" version = "0.1.9" @@ -3488,18 +3160,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" -[[package]] -name = "url" -version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" -dependencies = [ - "form_urlencoded", - "idna", - "matches", - "percent-encoding", -] - [[package]] name = "uuid" version = "1.1.2" @@ -3627,26 +3287,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webbrowser" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc6a3cffdb686fbb24d9fb8f03a213803277ed2300f11026a3afe1f108dc021b" -dependencies = [ - "jni", - "ndk-glue 0.6.2", - "url", - "web-sys", - "widestring", - "winapi", -] - -[[package]] -name = "weezl" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" - [[package]] name = "wgpu" version = "0.13.1" @@ -3657,7 +3297,7 @@ dependencies = [ "log", "naga", "parking_lot 0.12.1", - "raw-window-handle 0.4.3", + "raw-window-handle", "smallvec", "wasm-bindgen", "wasm-bindgen-futures", @@ -3747,12 +3387,6 @@ dependencies = [ "safe_arch", ] -[[package]] -name = "widestring" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17882f045410753661207383517a6f62ec3dbeb6a4ed2acce01f0728238d1983" - [[package]] name = "winapi" version = "0.3.9" @@ -3778,15 +3412,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "winapi-wsapoll" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -3877,18 +3502,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "x11rb" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e99be55648b3ae2a52342f9a870c0e138709a3493261ce9b469afe6e4df6d8a" -dependencies = [ - "gethostname", - "nix 0.22.3", - "winapi", - "winapi-wsapoll", -] - [[package]] name = "xi-unicode" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index d47bc94..75f5fcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,19 +9,19 @@ edition = "2021" bevy = "0.8.1" bevy_common_assets = { version = "0.3.0", features = ["json"] } bevy_rapier2d = "0.16.2" -crossbeam-channel = "0.5.6" +#crossbeam-channel = "0.5.6" rand = "0.8.5" rand_distr = "0.4.3" rapier2d = "0.14.0" serde = { version = "1.0.144", features = ["derive"] } [target."cfg(not(target_arch = \"wasm32\"))".dependencies] -bevy-inspector-egui = "0.12.1" +#bevy-inspector-egui = "0.12.1" bevy_mod_picking = "0.9.0" # cpal = "0.14.0" # hexodsp = { git = "https://github.com/WeirdConstructor/HexoDSP", default-features = false } serde_json = "1.0.85" -ticktock = "0.8.0" +#ticktock = "0.8.0" [target."cfg(target_arch = \"wasm32\")".dependencies] #cpal = { version = "0.14.0", features = ["wasm-bindgen"] } diff --git a/README.md b/README.md index 3aaeb14..327f5f2 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,6 @@ cargo build --release ### WASM -**Audio does not work in WASM!** - ```bash rustup target add wasm32-unknown-unknown cargo install wasm-bindgen-cli @@ -44,10 +42,12 @@ python3 -m http.server ## Audio -This game uses [HexoDSP](https://github.com/WeirdConstructor/HexoDSP) for audio synthesis. +This game used [HexoDSP](https://github.com/WeirdConstructor/HexoDSP) for audio synthesis. The synthetizer matrix can be edited using [HexoSynth](https://github.com/WeirdConstructor/HexoSynth) visual editor. +However we could not get this working in WASM, hence we used simple playback audio instead for the jam. The concept of procedural audio is not abandonned but it will be for another time. + ## Develop Skip to level `N: u32` with the command `bevyjam `. diff --git a/assets/silence.wav b/assets/silence.wav new file mode 100644 index 0000000..e69de29 diff --git a/index.html b/index.html index 159b08a..4b3e242 100644 --- a/index.html +++ b/index.html @@ -57,10 +57,12 @@ a, a:visited { import init from './target/lux-synthese.js' init() + +

Lux synthesĕ

- Note: audio does not work in the WASM build. + If audio does not work, please allow media autoplay in browser, then refresh this page.

Controls

    diff --git a/cover.png b/res/cover.png similarity index 100% rename from cover.png rename to res/cover.png diff --git a/cover.xcf b/res/cover.xcf similarity index 100% rename from cover.xcf rename to res/cover.xcf diff --git a/assets/sound/notes.flp b/res/notes.flp similarity index 100% rename from assets/sound/notes.flp rename to res/notes.flp diff --git a/src/audio_system.rs b/src/audio_system.rs index 9ddd291..5669707 100644 --- a/src/audio_system.rs +++ b/src/audio_system.rs @@ -4,8 +4,7 @@ pub struct AudioSystemPlugin; impl Plugin for AudioSystemPlugin { fn build(&self, app: &mut App) { - app - .init_resource::() + app.init_resource::() .add_startup_system(load_audio); } } @@ -23,27 +22,27 @@ pub fn play_audio( color: Vec4, volume: f32, ) { - for i in 0 .. 3 { + for i in 0..3 { audio.play_with_settings( audio_set[i].clone(), - PlaybackSettings::ONCE.with_volume(color[i] * volume) + PlaybackSettings::ONCE.with_volume(color[i] * volume), ); } } -fn load_audio( - mut audio_assets: ResMut, - asset_server: Res, -) { +fn load_audio(mut audio_assets: ResMut, asset_server: Res) { audio_assets.notes[0] = asset_server.load::("sound/notes/a5.ogg"); audio_assets.notes[1] = asset_server.load::("sound/notes/cs6.ogg"); audio_assets.notes[2] = asset_server.load::("sound/notes/e6.ogg"); - audio_assets.reverb_notes[0] = asset_server.load::("sound/reverb_notes/a5.ogg"); - audio_assets.reverb_notes[1] = asset_server.load::("sound/reverb_notes/cs6.ogg"); - audio_assets.reverb_notes[2] = asset_server.load::("sound/reverb_notes/e6.ogg"); + audio_assets.reverb_notes[0] = + asset_server.load::("sound/reverb_notes/a5.ogg"); + audio_assets.reverb_notes[1] = + asset_server.load::("sound/reverb_notes/cs6.ogg"); + audio_assets.reverb_notes[2] = + asset_server.load::("sound/reverb_notes/e6.ogg"); audio_assets.warp_notes[0] = asset_server.load::("sound/warp_notes/a5.ogg"); audio_assets.warp_notes[1] = asset_server.load::("sound/warp_notes/cs6.ogg"); audio_assets.warp_notes[2] = asset_server.load::("sound/warp_notes/e6.ogg"); -} \ No newline at end of file +} diff --git a/src/game.rs b/src/game.rs index 60c1589..015a268 100644 --- a/src/game.rs +++ b/src/game.rs @@ -2,8 +2,8 @@ #![allow(clippy::too_many_arguments)] pub use crate::filters::*; -use crate::{AppState, audio_system}; use crate::levels; +use crate::{audio_system, AppState}; use bevy::{ ecs::system::EntityCommands, @@ -337,7 +337,7 @@ fn char_char_collision_event_system( c1_player.is_some() || c2_player.is_some(), ); - audio_system::play_audio(&audio_assets.warp_notes, &audio, new_color.into(), 1.0); + audio_system::play_audio(&audio_assets.warp_notes, &audio, new_color, 1.0); } } } @@ -364,7 +364,7 @@ fn char_platform_collision_event_system( } } } - + CollisionEvent::Stopped(e1, e2, flags) => { if *flags == CollisionEventFlags::SENSOR { if let (Ok(mut platform_count), Ok(_)) = @@ -412,25 +412,14 @@ fn collision_event_system( } } } else if *flags == CollisionEventFlags::SENSOR { - if let (Ok((mut c_color, _c_transform, mut c_material, c_player)), Ok(filter)) = ( + if let (Ok((mut c_color, _c_transform, mut c_material, _c_player)), Ok(filter)) = ( character_query.get_mut(*e1), pass_through_filter_query.get(*e2), ) { c_color.0 = filter.apply(c_color.0); *c_material = materials.add(ColorMaterial::from(c_color.0)); - - if c_player.is_some() { - audio - .send(AudioMsg::Color([ - c_color.0.r(), - c_color.0.g(), - c_color.0.b(), - ])) - .ok(); - audio.send(AudioMsg::Switch).ok(); - } } else if let ( - Ok((mut c_color, _c_transform, mut c_material, c_player)), + Ok((mut c_color, _c_transform, mut c_material, _c_player)), Ok(filter), ) = ( character_query.get_mut(*e2), @@ -438,17 +427,6 @@ fn collision_event_system( ) { c_color.0 = filter.apply(c_color.0); *c_material = materials.add(ColorMaterial::from(c_color.0)); - - if c_player.is_some() { - audio - .send(AudioMsg::Color([ - c_color.0.r(), - c_color.0.g(), - c_color.0.b(), - ])) - .ok(); - audio.send(AudioMsg::Switch).ok(); - } } } } @@ -568,8 +546,8 @@ fn camera_system( time: Res