From 34f85be4ef737a05230fe060e77fdd1abe56280d Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Mon, 11 Nov 2024 17:21:36 +0200 Subject: [PATCH 1/8] fix(maze): tile wall orientation --- Cargo.lock | 445 +++++++++++++++++++------------------------ Cargo.toml | 6 +- src/lib.rs | 2 +- src/maze/grid.rs | 220 --------------------- src/maze/mod.rs | 2 - src/maze/plugin.rs | 4 +- src/maze/prism.rs | 62 +++--- src/maze/resource.rs | 4 +- src/maze/tile.rs | 55 ------ 9 files changed, 236 insertions(+), 564 deletions(-) delete mode 100644 src/maze/grid.rs delete mode 100644 src/maze/tile.rs diff --git a/Cargo.lock b/Cargo.lock index a54fa34..90d8ee5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ab_glyph" @@ -147,7 +147,7 @@ dependencies = [ "ndk-context", "ndk-sys 0.6.0+11769913", "num_enum", - "thiserror", + "thiserror 1.0.63", ] [[package]] @@ -314,9 +314,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bevy" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8ece0d8dde51890fb52dcba5b04fd1c657617a4022908c327b2d6e83d173a32" +checksum = "043c9ad4b6fc4ca52d779873a8ca792a4e37842d07fce95363c9e17e36a1d8a0" dependencies = [ "bevy_dylib", "bevy_internal", @@ -363,14 +363,14 @@ checksum = "89f3be3ba88a25445c0c10684709b1ccd07e37f5f6b5d1b8dcf11d34548f1d61" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] name = "bevy_a11y" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82d84e0ae7155afa21c4926fb8b89ebe0cbd66239ac817fdb834025327c4089b" +checksum = "ae1a976cb539d6a5a3ff579cdb78187a6bcfbffa7e8224ea28f23d8b983d9389" dependencies = [ "accesskit", "bevy_app", @@ -380,9 +380,9 @@ dependencies = [ [[package]] name = "bevy_animation" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abec61c2d9d19329d8d9f0d7f1ce0188f6ed2c6d74d90412b238efc38c7d7794" +checksum = "93aef7d21a0342c24b05059493aa31d58f1798d34a2236569a8789b74df5a475" dependencies = [ "bevy_app", "bevy_asset", @@ -403,16 +403,16 @@ dependencies = [ "petgraph", "ron", "serde", - "thiserror", + "thiserror 1.0.63", "thread_local", "uuid", ] [[package]] name = "bevy_app" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0af99549f5de61cc91c8c23303b13aa07f97b73fbace39695dee0a0a32cec9d4" +checksum = "a5361d0f8a8677a5d0102cfe7321a7ecd2a8b9a4f887ce0dde1059311cf9cd42" dependencies = [ "bevy_derive", "bevy_ecs", @@ -421,16 +421,16 @@ dependencies = [ "bevy_utils", "console_error_panic_hook", "downcast-rs", - "thiserror", + "thiserror 1.0.63", "wasm-bindgen", "web-sys", ] [[package]] name = "bevy_asset" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6533d17f13b44ea4fb5177f83b0900269ed13c0fd45772ccffd19a69980647ec" +checksum = "60ec5ea257e1ebd3d411f669e29acf60beb715bebc7e1f374c17f49cd3aad46c" dependencies = [ "async-broadcast", "async-fs", @@ -452,7 +452,7 @@ dependencies = [ "parking_lot", "ron", "serde", - "thiserror", + "thiserror 1.0.63", "uuid", "wasm-bindgen", "wasm-bindgen-futures", @@ -461,21 +461,21 @@ dependencies = [ [[package]] name = "bevy_asset_macros" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74b0e132a89e254c0f5c8bc8deebb0f2490f5662f4aa2215a6996701446d6a7b" +checksum = "c9eb05ce838d282f09d83380b4d6432aec7519d421dee8c75cc20e6148237e6e" dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] name = "bevy_audio" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3050cb7244560313800b284e4b5eafcf91e833464e44d8407b20ec6c65974fc" +checksum = "8ee31312a0e67f288fe12a1d9aa679dd0ba8a49e1e6fe5fcd2ba1aa1ea34e5ed" dependencies = [ "bevy_app", "bevy_asset", @@ -492,24 +492,24 @@ dependencies = [ [[package]] name = "bevy_color" -version = "0.14.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c031f121b8d72e7637c94ef139097613bd32935784d36728f83e77cfdf26f4" +checksum = "04842e9d38a93f0c75ab46f7f404ea24ef57ad83dbd159e5b4b35318b02257bb" dependencies = [ "bevy_math", "bevy_reflect", "bytemuck", "encase", "serde", - "thiserror", + "thiserror 1.0.63", "wgpu-types", ] [[package]] name = "bevy_core" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccc7118a2865267136afb5e6a2c0aed30994e522f298b2ba0b088878e6ddf59" +checksum = "de706862871a1fe99ea619bff2f99d73e43ad82f19ef866a9e19a14c957c8537" dependencies = [ "bevy_app", "bevy_ecs", @@ -521,9 +521,9 @@ dependencies = [ [[package]] name = "bevy_core_pipeline" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "559ad1dc48c3fa6bbace503df2fe44a7de38c8dfe11bee911ec0ffaf93e3e57d" +checksum = "2f6e1e122ada4cd811442e083fb5ad3e325c59a87271d5ef57193f1c2cad7f8c" dependencies = [ "bevy_app", "bevy_asset", @@ -541,25 +541,25 @@ dependencies = [ "radsort", "serde", "smallvec", - "thiserror", + "thiserror 1.0.63", ] [[package]] name = "bevy_derive" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8675f337f374b2b8ae90539982b947d171f9adb302d00c032b823bd5231f8978" +checksum = "3fbfc33a4c6b80760bb8bf850a2cc65a1e031da62fd3ca8b552189104dc98514" dependencies = [ "bevy_macro_utils", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] name = "bevy_dev_tools" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8cc87d018c71ab225cc3535051af5c0a7ade699b820b043a5484ce4097addf2" +checksum = "0abf99960653c5b0827c562e75fd7a6c74ffa517d2c138519c31375f17f12ce8" dependencies = [ "bevy_app", "bevy_asset", @@ -585,9 +585,9 @@ dependencies = [ [[package]] name = "bevy_diagnostic" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdcc1d7ba5797e4285a7867227134d4cabaaf8cabfb7cdc42eb697d3b3db0460" +checksum = "bebb154e0cc78e3bbfbfdb42fb502b14c1cd47e72f16e6d4228dfe6233ba6cbd" dependencies = [ "bevy_app", "bevy_core", @@ -601,18 +601,18 @@ dependencies = [ [[package]] name = "bevy_dylib" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521e5c295b80798b7a886aab4e54d0a92ea1780aa9586cdb17ded1fe34f36504" +checksum = "0c399292fac67682a72666e78872626f3c1c39b34c430b6f02c81d21da91b500" dependencies = [ "bevy_internal", ] [[package]] name = "bevy_ecs" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a3eed7f144811946ebfa1c740da9e3bcd6dd2dd4da844eda085249d29bc9fef" +checksum = "9ee4222406637f3c8e3991a99788cfcde76097bf997c311f1b6297364057483f" dependencies = [ "arrayvec", "bevy_ecs_macros", @@ -626,19 +626,19 @@ dependencies = [ "nonmax", "petgraph", "serde", - "thiserror", + "thiserror 1.0.63", ] [[package]] name = "bevy_ecs_macros" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d523630f2eb9fde6727e6c5ea48fa708079c5345da21ffeb1a4bd8ca761830da" +checksum = "36b573430b67aff7bde8292257494f39343401379bfbda64035ba4918bba7b20" dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -665,9 +665,9 @@ dependencies = [ [[package]] name = "bevy_encase_derive" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a20ec101b103f430481112591e280a8fc3f2db6741579f885595372073b749b" +checksum = "d06c9693847a2a6ea61d6b86288dd4d8b6a79f05d4bf6e27b96d4f5c8d552fe4" dependencies = [ "bevy_macro_utils", "encase_derive_impl", @@ -675,9 +675,9 @@ dependencies = [ [[package]] name = "bevy_gilrs" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a64d84c2cbc6a027ba2c293752f9508e6777607acb1d98d03c25eb2a80d55372" +checksum = "0422ccb3ce0f79b264100cf064fdc5ef65cef5c7d51bf6378058f9b96fea4183" dependencies = [ "bevy_app", "bevy_ecs", @@ -685,14 +685,14 @@ dependencies = [ "bevy_time", "bevy_utils", "gilrs", - "thiserror", + "thiserror 1.0.63", ] [[package]] name = "bevy_gizmos" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248324352331d719071b0d1545a43e3d63470f4730e75312edee575f210d3a77" +checksum = "dfe32af0666d8d8a7fd6eb6b5e41eceefdc6f2e5441c74b812e8f0902a9d7f52" dependencies = [ "bevy_app", "bevy_asset", @@ -713,21 +713,21 @@ dependencies = [ [[package]] name = "bevy_gizmos_macros" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbe1708bb0e45a1d0fe0f32e998557689231dfe7bdae62083326e8008e97de23" +checksum = "906b052f8cf3f3983f0f6df625fb10cbd9b27d44e362a327dc1ed51300d362bc" dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] name = "bevy_gltf" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb57239cb4209e52354268062cd1973892af3a2077ccbdb4d19259cbbc2d2c2d" +checksum = "d6adbd325b90e3c700d0966b5404e226c7deec1b8bda8f36832788d7b435b9b8" dependencies = [ "base64 0.22.1", "bevy_animation", @@ -751,14 +751,14 @@ dependencies = [ "serde", "serde_json", "smallvec", - "thiserror", + "thiserror 1.0.63", ] [[package]] name = "bevy_hierarchy" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb332d2789442ca1577c765977bafefea1dcd4db29479713ec8c6932dfb82cdb" +checksum = "a88b912b37e1bc4dbb2aa40723199f74c8b06c4fbb6da0bb4585131df28ef66e" dependencies = [ "bevy_app", "bevy_core", @@ -770,9 +770,9 @@ dependencies = [ [[package]] name = "bevy_input" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9ce5f27a8729b473205b01927cd6a5c4898a004cb8fcffa7c896e19ba999d98" +checksum = "8dd3a54e67cc3ba17971de7b1a7e64eda84493c1e7bb6bfa11c6cf8ac124377b" dependencies = [ "bevy_app", "bevy_ecs", @@ -780,14 +780,14 @@ dependencies = [ "bevy_reflect", "bevy_utils", "smol_str", - "thiserror", + "thiserror 1.0.63", ] [[package]] name = "bevy_internal" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2463102e46d7d67440dbfe3bc97d34bf529c93191c4f4bb41395f4982062ff3" +checksum = "45d435cac77c568f3aef65f786a5fee0e53c81950c5258182dd2c1d6cd6c4fec" dependencies = [ "bevy_a11y", "bevy_animation", @@ -827,9 +827,9 @@ dependencies = [ [[package]] name = "bevy_log" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52f2c0c374af59007396793a51f747f6b10d74ca4acfb080ce0ade267118827b" +checksum = "67240c7596c8f0653e50fce35a60196516817449235193246599facba9002e02" dependencies = [ "android_log-sys", "bevy_app", @@ -842,44 +842,44 @@ dependencies = [ [[package]] name = "bevy_macro_utils" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ec4a585ec2a6dedd4f4143c07219d120ae142121929f0d83e68d82a452cdc9b" +checksum = "bfc65e570012e64a21f3546df68591aaede8349e6174fb500071677f54f06630" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", "toml_edit 0.22.20", ] [[package]] name = "bevy_math" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40253578fe83a5ffe5f4fcb4dfa196b7d9c50f36dc8efaa231a53344bf4b3e57" +checksum = "5421792749dda753ab3718e77d27bfce38443daf1850b836b97530b6245a4581" dependencies = [ "bevy_reflect", "glam", "rand", "serde", "smallvec", - "thiserror", + "thiserror 1.0.63", ] [[package]] name = "bevy_mikktspace" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24a1ad15685c6035e01bdc9d5ea082558ef1438e9d40d69fc552857dd7e83e71" +checksum = "66cf695a264b043f2c4edb92dd5c742e6892180d2b30dac870012d153f8557ea" dependencies = [ "glam", ] [[package]] name = "bevy_pbr" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "588998ba295db4a14dec54e571f272490f2885e5aaac59191fb4fa32a25835d0" +checksum = "4dccaa3c945f19834dcf7cd8eb358236dbf0fc4000dacbc7710564e7856714db" dependencies = [ "bevy_app", "bevy_asset", @@ -902,29 +902,17 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "bevy_prototype_lyon" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66a59b46da5bccc6d86c6047cfc81b8e9027f5b98e24b8721e8e1453c1d05371" -dependencies = [ - "bevy", - "lyon_algorithms", - "lyon_tessellation", - "svgtypes", -] - [[package]] name = "bevy_ptr" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ed72afbb6249a6803a3ed7bd2f68ff080d9392f550475e050b34c1e1c1e3e8f" +checksum = "61baa1bdc1f4a7ac2c18217570a7cc04e1cd54d38456e91782f0371c79afe0a8" [[package]] name = "bevy_reflect" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb37e8fc3c61d04da480c95cc8c303aa7781afed6be01dae333b336af493c38e" +checksum = "2508785a4a5809f25a237eec4fee2c91a4dbcf81324b2bbc2d6c52629e603781" dependencies = [ "bevy_ptr", "bevy_reflect_derive", @@ -936,28 +924,28 @@ dependencies = [ "serde", "smallvec", "smol_str", - "thiserror", + "thiserror 1.0.63", "uuid", ] [[package]] name = "bevy_reflect_derive" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc00d5086f5bf534b4c2dbeba549a6b8d3223515f3cb5ba4fdaabe953ec6cea" +checksum = "967d5da1882ec3bb3675353915d3da909cafac033cbf31e58727824a1ad2a288" dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", "uuid", ] [[package]] name = "bevy_render" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f570f36154296ae5377587d5ef19e1feb4c5734923785c571f55a9fff091701" +checksum = "836cf8a513db013cbe7d55a331060088efd407e49fd5b05c8404700cd82e7619" dependencies = [ "async-channel", "bevy_app", @@ -995,7 +983,7 @@ dependencies = [ "send_wrapper", "serde", "smallvec", - "thiserror", + "thiserror 1.0.63", "wasm-bindgen", "web-sys", "wgpu", @@ -1003,21 +991,21 @@ dependencies = [ [[package]] name = "bevy_render_macros" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe2d5008c7b4a8a516ef7b58452b8e40e4c2317068fc7505398bedf34e8d45f7" +checksum = "cbc24e0e95061a38a7744218b9c7e52e4c08b53f1499f33480e2b749f3864432" dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] name = "bevy_scene" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3910087f6fc45e7833fb62e4de282c36a7012ff381c0584eb2cc84dede02e72f" +checksum = "8ec57a72d75273bdbb6154390688fd07ba79ae9f6f99476d1937f799c736c2da" dependencies = [ "bevy_app", "bevy_asset", @@ -1029,15 +1017,15 @@ dependencies = [ "bevy_transform", "bevy_utils", "serde", - "thiserror", + "thiserror 1.0.63", "uuid", ] [[package]] name = "bevy_sprite" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffdfb9a18968c8606286b6be83c9323ff9008b5cc043a23a3ecc95ff72fb20c" +checksum = "e045b4d8cc8e7422a4c29b1eadbe224f5cc42f170b88d43e7535892fcede3840" dependencies = [ "bevy_app", "bevy_asset", @@ -1056,14 +1044,14 @@ dependencies = [ "guillotiere", "radsort", "rectangle-pack", - "thiserror", + "thiserror 1.0.63", ] [[package]] name = "bevy_state" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21066e7bb8014d1b1dd4f611f28c0f4ea9c7738cec2325281e4260a65072d509" +checksum = "25335bfa58cc22371182335c3b133017293bc9b6d3308402fd4d1f978b83f937" dependencies = [ "bevy_app", "bevy_ecs", @@ -1075,21 +1063,21 @@ dependencies = [ [[package]] name = "bevy_state_macros" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a449823c420d1cc1fa6cf3d484570b08358e5eeedc1b86de1efcf9c10399b5" +checksum = "dee600b659c739f1911f997a81611fec0a1832cf731727956e5fa4e7532b4dd5" dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] name = "bevy_tasks" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f5414c3f49c96e02ceccf5fa12fb6cfbf8b271d2a820902d6f622e9c2fa681" +checksum = "77865f310b1fc48fb05b7c4adbe76607ec01d0c14f8ab4caba4d714c86439946" dependencies = [ "async-channel", "async-executor", @@ -1100,9 +1088,9 @@ dependencies = [ [[package]] name = "bevy_text" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3e77dd86def15f5380e6e7c178ec54e5e356b3f464e2ad35794a08d5ecb82e4" +checksum = "b661db828fd423fc41a4ccf43aa4d1b8e50e75057ec40453317d0d761e8ad62d" dependencies = [ "ab_glyph", "bevy_app", @@ -1118,42 +1106,42 @@ dependencies = [ "bevy_window", "glyph_brush_layout", "serde", - "thiserror", + "thiserror 1.0.63", ] [[package]] name = "bevy_time" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3fb18cfac62098e07786e422e84b4f45f469f27ccb5b572b409500bef465f33" +checksum = "f4e4d53ec32a1b16492396951d04de0d2d90e924bf9adcb8d1adacab5ab6c17c" dependencies = [ "bevy_app", "bevy_ecs", "bevy_reflect", "bevy_utils", "crossbeam-channel", - "thiserror", + "thiserror 1.0.63", ] [[package]] name = "bevy_transform" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ff09cea0dd0d4e6a3ed5f7dcbd4fbbcec07e518ceb64a4c8a75dedbe294ab60" +checksum = "d5493dce84427d00a9266e8e4386d738a72ee8640423b62dfcecb6dfccbfe0d2" dependencies = [ "bevy_app", "bevy_ecs", "bevy_hierarchy", "bevy_math", "bevy_reflect", - "thiserror", + "thiserror 1.0.63", ] [[package]] name = "bevy_ui" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50684629a03b7d4891b5953e84dd971c7a8bbd290751bab5ce06e119b692220b" +checksum = "56d2cba6603b39a3765f043212ae530e25550af168a7eec6b23b9b93c19bc5f7" dependencies = [ "bevy_a11y", "bevy_app", @@ -1176,14 +1164,14 @@ dependencies = [ "nonmax", "smallvec", "taffy", - "thiserror", + "thiserror 1.0.63", ] [[package]] name = "bevy_utils" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6efbe5a621b56cc4ffa41074929eca84107e242302496b9bb7550675e6bf2e7" +checksum = "ffb0ec333b5965771153bd746f92ffd8aeeb9d008a8620ffd9ed474859381a5e" dependencies = [ "ahash", "bevy_utils_proc_macros", @@ -1196,20 +1184,20 @@ dependencies = [ [[package]] name = "bevy_utils_proc_macros" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36a1e91b4294cad2d08620ac062509395d4f65247b636946d6497eaeccf4dbfd" +checksum = "38f1ab8f2f6f58439d260081d89a42b02690e5fdd64f814edc9417d33fcf2857" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] name = "bevy_window" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ba11880f05a3b267ecfa4149fe789b0c046c35fd8418dd8899fad3a4359c986" +checksum = "c89e88a20db64ea8204540afb4699295947c454738fd50293f7b32ab8be857a6" dependencies = [ "bevy_a11y", "bevy_app", @@ -1223,9 +1211,9 @@ dependencies = [ [[package]] name = "bevy_winit" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5aeb4b2e3b1ece189fcf37ea2de625ceab93e6ac2a14d4b15b0393351e4c18b" +checksum = "d0bef8ec3e4b45db943ad4d1c0bf59b09e382ce0651a706e2f33a70fa955303c" dependencies = [ "accesskit_winit", "approx", @@ -1266,7 +1254,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -1363,7 +1351,7 @@ checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -1395,7 +1383,7 @@ dependencies = [ "polling", "rustix", "slab", - "thiserror", + "thiserror 1.0.63", ] [[package]] @@ -1804,7 +1792,7 @@ dependencies = [ "const_panic", "encase_derive", "glam", - "thiserror", + "thiserror 1.0.63", ] [[package]] @@ -1824,7 +1812,7 @@ checksum = "fd31dbbd9743684d339f907a87fe212cb7b51d75b9e8e74181fe363199ee9b47" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -1975,12 +1963,6 @@ dependencies = [ "miniz_oxide", ] -[[package]] -name = "float_next_after" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf7cc16383c4b8d58b9905a8509f02926ce3058053c056376248d958c9df1e8" - [[package]] name = "fnv" version = "1.0.7" @@ -2005,7 +1987,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -2184,7 +2166,7 @@ dependencies = [ "inflections", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -2246,7 +2228,7 @@ checksum = "6f56f6318968d03c18e1bcf4857ff88c61157e9da8e47c5f29055d60e1228884" dependencies = [ "log", "presser", - "thiserror", + "thiserror 1.0.63", "winapi", "windows 0.52.0", ] @@ -2308,7 +2290,7 @@ dependencies = [ "com", "libc", "libloading 0.8.5", - "thiserror", + "thiserror 1.0.63", "widestring", "winapi", ] @@ -2335,6 +2317,19 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "hexlab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "538df606c368ad8b02f7ce78c3edf0d8b26e5f984e2bc31f063f0b1e34fb6576" +dependencies = [ + "bevy", + "hexx", + "rand", + "rand_chacha", + "thiserror 2.0.3", +] + [[package]] name = "hexx" version = "0.18.0" @@ -2470,7 +2465,7 @@ dependencies = [ "combine", "jni-sys", "log", - "thiserror", + "thiserror 1.0.63", "walkdir", "windows-sys 0.45.0", ] @@ -2551,15 +2546,6 @@ dependencies = [ "bitflags 1.3.2", ] -[[package]] -name = "kurbo" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd85a5776cd9500c2e2059c8c76c3b01528566b7fcbaf8098b55a33fc298849b" -dependencies = [ - "arrayvec", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -2609,12 +2595,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "libm" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" - [[package]] name = "libredox" version = "0.0.2" @@ -2664,48 +2644,6 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" -[[package]] -name = "lyon_algorithms" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3bca95f9a4955b3e4a821fbbcd5edfbd9be2a9a50bb5758173e5358bfb4c623" -dependencies = [ - "lyon_path", - "num-traits", -] - -[[package]] -name = "lyon_geom" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edecfb8d234a2b0be031ab02ebcdd9f3b9ee418fb35e265f7a540a48d197bff9" -dependencies = [ - "arrayvec", - "euclid", - "num-traits", -] - -[[package]] -name = "lyon_path" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c08a606c7a59638d6c6aa18ac91a06aa9fb5f765a7efb27e6a4da58700740d7" -dependencies = [ - "lyon_geom", - "num-traits", -] - -[[package]] -name = "lyon_tessellation" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579d42360a4b09846eff2feef28f538696c7d6c7439bfa65874ff3cbe0951b2c" -dependencies = [ - "float_next_after", - "lyon_path", - "num-traits", -] - [[package]] name = "mach2" version = "0.4.2" @@ -2735,11 +2673,11 @@ dependencies = [ [[package]] name = "maze-ascension" -version = "0.0.5" +version = "0.1.0" dependencies = [ "bevy", "bevy-inspector-egui", - "bevy_prototype_lyon", + "hexlab", "hexx", "log", "rand", @@ -2822,7 +2760,7 @@ dependencies = [ "rustc-hash", "spirv", "termcolor", - "thiserror", + "thiserror 1.0.63", "unicode-xid", ] @@ -2841,7 +2779,7 @@ dependencies = [ "regex", "regex-syntax 0.8.4", "rustc-hash", - "thiserror", + "thiserror 1.0.63", "tracing", "unicode-ident", ] @@ -2857,7 +2795,7 @@ dependencies = [ "log", "ndk-sys 0.5.0+25.2.9519653", "num_enum", - "thiserror", + "thiserror 1.0.63", ] [[package]] @@ -2872,7 +2810,7 @@ dependencies = [ "ndk-sys 0.6.0+11769913", "num_enum", "raw-window-handle", - "thiserror", + "thiserror 1.0.63", ] [[package]] @@ -2993,7 +2931,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -3003,7 +2941,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", - "libm", ] [[package]] @@ -3024,7 +2961,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -3371,7 +3308,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -3627,7 +3564,7 @@ checksum = "d1fceb9d127d515af1586d8d0cc601e1245bdb0af38e75c865a156290184f5b3" dependencies = [ "cpal", "lewton", - "thiserror", + "thiserror 1.0.63", ] [[package]] @@ -3734,7 +3671,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -3770,12 +3707,6 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" -[[package]] -name = "siphasher" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" - [[package]] name = "slab" version = "0.4.9" @@ -3814,7 +3745,7 @@ dependencies = [ "log", "memmap2", "rustix", - "thiserror", + "thiserror 1.0.63", "wayland-backend", "wayland-client", "wayland-csd-frame", @@ -3861,16 +3792,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20e16a0f46cf5fd675563ef54f26e83e20f2366bcf027bcb3cc3ed2b98aaf2ca" -[[package]] -name = "svgtypes" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71499ff2d42f59d26edb21369a308ede691421f79ebc0f001e2b1fd3a7c9e52" -dependencies = [ - "kurbo", - "siphasher", -] - [[package]] name = "syn" version = "1.0.109" @@ -3884,9 +3805,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.72" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -3935,7 +3856,16 @@ version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.63", +] + +[[package]] +name = "thiserror" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +dependencies = [ + "thiserror-impl 2.0.3", ] [[package]] @@ -3946,7 +3876,18 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", ] [[package]] @@ -4057,7 +3998,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -4247,7 +4188,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -4281,7 +4222,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4492,7 +4433,7 @@ dependencies = [ "raw-window-handle", "rustc-hash", "smallvec", - "thiserror", + "thiserror 1.0.63", "web-sys", "wgpu-hal", "wgpu-types", @@ -4536,7 +4477,7 @@ dependencies = [ "renderdoc-sys", "rustc-hash", "smallvec", - "thiserror", + "thiserror 1.0.63", "wasm-bindgen", "web-sys", "wgpu-types", @@ -4663,7 +4604,7 @@ checksum = "942ac266be9249c84ca862f0a164a39533dc2f6f33dc98ec89c8da99b82ea0bd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -4674,7 +4615,7 @@ checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -4685,7 +4626,7 @@ checksum = "da33557140a288fae4e1d5f8873aaf9eb6613a9cf82c3e070223ff177f598b60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -4696,7 +4637,7 @@ checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] [[package]] @@ -5098,5 +5039,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.87", ] diff --git a/Cargo.toml b/Cargo.toml index 0878cca..e4b23c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "maze-ascension" authors = ["Kristofers Solo "] -version = "0.0.5" +version = "0.1.0" edition = "2021" [dependencies] @@ -18,7 +18,7 @@ tracing = { version = "0.1", features = [ "release_max_level_warn", ] } hexx = { version = "0.18", features = ["bevy_reflect", "grid"] } -bevy_prototype_lyon = "0.12" +hexlab = { version = "0.1", features = ["bevy"] } bevy-inspector-egui = { version = "0.27", optional = true } @@ -31,7 +31,7 @@ dev = [ # Improve compile times for dev builds by linking Bevy as a dynamic library. "bevy/dynamic_linking", "bevy/bevy_dev_tools", - "bevy-inspector-egui", + "dep:bevy-inspector-egui", ] dev_native = [ "dev", diff --git a/src/lib.rs b/src/lib.rs index 39223ea..9c126f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,7 +91,7 @@ fn spawn_camera(mut commands: Commands) { commands.spawn(( Name::new("Camera"), Camera3dBundle { - transform: Transform::from_xyz(0., 300., 300.).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(200., 200., 0.).looking_at(Vec3::ZERO, Vec3::Y), ..default() }, // Render all UI to this camera. diff --git a/src/maze/grid.rs b/src/maze/grid.rs deleted file mode 100644 index babf67b..0000000 --- a/src/maze/grid.rs +++ /dev/null @@ -1,220 +0,0 @@ -use bevy::{ - color::palettes::css::{BLACK, GREEN, RED}, - pbr::wireframe::{WireframeConfig, WireframePlugin}, - prelude::*, - utils::hashbrown::HashMap, -}; -use bevy_prototype_lyon::{ - draw::{Fill, Stroke}, - entity::ShapeBundle, - path::PathBuilder, - plugin::ShapePlugin, -}; -use hexx::{EdgeDirection, Hex}; -use rand::{prelude::SliceRandom, rngs::ThreadRng, thread_rng}; - -use super::{ - resource::{Layout, MazeConfig, HEX_SIZE}, - tile::{Tile, TileBundle, Walls}, -}; - -pub(super) fn plugin(app: &mut App) { - app.add_plugins((ShapePlugin, WireframePlugin)); - app.init_resource::(); - app.init_resource::(); - app.insert_resource(WireframeConfig { - global: false, - ..default() - }); -} - -pub(super) fn _spawn_hex_grid(mut commands: Commands, config: Res) { - let radius = config.radius as i32; - - for q in -radius..=radius { - let r1 = (-radius).max(-q - radius); - let r2 = radius.min(-q + radius); - for r in r1..=r2 { - let tile = Tile::new(q, r); - commands.spawn(( - Name::new(format!("Tile {}", &tile.to_string())), - TileBundle { - hex: tile, - ..default() - }, - )); - } - } -} - -pub(super) fn _generate_maze( - mut commands: Commands, - query: Query<(Entity, &Tile, &Walls)>, - config: Res, -) { - let mut tiles = query - .into_iter() - .map(|(entity, tile, walls)| (tile.hex, (entity, tile.clone(), walls.clone()))) - .collect(); - - let mut rng = thread_rng(); - _recursive_maze(&mut tiles, config.start_pos, &mut rng); - - for (entity, tile, walls) in tiles.values() { - commands - .entity(*entity) - .insert(tile.clone()) - .insert(walls.clone()); - } -} - -fn _recursive_maze( - tiles: &mut HashMap, - current_hex: Hex, - rng: &mut ThreadRng, -) { - { - let (_, tile, _) = tiles.get_mut(¤t_hex).unwrap(); - tile._visit(); - } - - let mut directions = EdgeDirection::ALL_DIRECTIONS; - directions.shuffle(rng); - - for direction in directions.into_iter() { - let neighbor_hex = current_hex + direction; - if let Some((_, neighbor_tile, _)) = tiles.get(&neighbor_hex) { - if !neighbor_tile.visited { - _remove_wall_between(tiles, current_hex, neighbor_hex, direction); - _recursive_maze(tiles, neighbor_hex, rng); - } - } - } -} - -fn _remove_wall_between( - tiles: &mut HashMap, - current_hex: Hex, - neighbor_hex: Hex, - direction: EdgeDirection, -) { - { - let (_, _, walls) = tiles.get_mut(¤t_hex).unwrap(); - walls.0[direction.index() as usize] = false; - } - { - let (_, _, walls) = tiles.get_mut(&neighbor_hex).unwrap(); - walls.0[direction.const_neg().index() as usize] = false; - } -} - -fn _add_hex_tile( - commands: &mut Commands, - position: Vec3, - size: f32, - tile: &Tile, - walls: &Walls, - fill_color: Color, - layout: &Layout, -) { - let hex_points = tile - .hex - .all_vertices() - .into_iter() - .map(|v| { - let mut layout = layout.clone(); - layout.origin = position.xy(); - layout.hex_size = Vec2::splat(size); - layout.hex_to_world_pos(v.origin + v.direction) - }) - .collect::>(); - - let mut path_builder = PathBuilder::new(); - path_builder.move_to(hex_points[0]); - for point in &hex_points[1..] { - path_builder.line_to(*point); - } - path_builder.close(); - let hexagon = path_builder.build(); - - // Create the hexagon fill - commands - .spawn(( - ShapeBundle { - path: hexagon, - spatial: SpatialBundle { - transform: Transform::from_xyz(position.x, position.y, 0.), - ..default() - }, - ..default() - }, - Fill::color(fill_color), - )) - .with_children(|p| { - p.spawn(Text2dBundle { - text: Text { - sections: vec![TextSection { - value: tile.to_string(), - style: TextStyle { - font_size: 16., - color: Color::BLACK, - ..default() - }, - }], - ..default() - }, - transform: Transform::from_xyz(position.x * 2., position.y * 2., 1.), - ..default() - }); - }); - - // Draw walls - for direction in EdgeDirection::iter() { - let idx = direction.index() as usize; - if walls[idx] { - let start = hex_points[idx]; - let end = hex_points[(idx + 1) % 6]; - let mut line_builder = PathBuilder::new(); - line_builder.move_to(start); - line_builder.line_to(end); - let line = line_builder.build(); - - commands.spawn(( - ShapeBundle { - path: line, - spatial: SpatialBundle { - transform: Transform::from_xyz(position.x, position.y, 1.), - ..default() - }, - ..default() - }, - Stroke::new(BLACK, 2.), - )); - } - } -} - -pub(super) fn _render_maze( - mut commands: Commands, - query: Query<(&Tile, &mut Walls)>, - layout: Res, - config: Res, -) { - for (tile, walls) in query.iter() { - let world_pos = layout.hex_to_world_pos(tile.hex).extend(0.); - let fill_color = match tile.hex { - pos if pos == config.start_pos => GREEN.into(), - pos if pos == config.end_pos => RED.into(), - _ => Color::srgb(0.8, 0.8, 0.8), - }; - _add_hex_tile( - &mut commands, - world_pos, - HEX_SIZE, - tile, - walls, - fill_color, - &layout, - ); - } -} diff --git a/src/maze/mod.rs b/src/maze/mod.rs index c3266d1..94f0bdd 100644 --- a/src/maze/mod.rs +++ b/src/maze/mod.rs @@ -1,10 +1,8 @@ use bevy::{ecs::world::Command, prelude::*}; use plugin::MazePlugin; -pub mod grid; pub mod plugin; pub mod prism; pub mod resource; -pub mod tile; pub fn spawn_grid(world: &mut World) { MazePlugin.apply(world); diff --git a/src/maze/plugin.rs b/src/maze/plugin.rs index d59f509..ad31ce9 100644 --- a/src/maze/plugin.rs +++ b/src/maze/plugin.rs @@ -3,7 +3,7 @@ use bevy::{ prelude::*, }; -use super::{grid, prism}; +use super::prism; #[derive(Default)] pub(crate) struct MazePlugin; @@ -11,7 +11,7 @@ pub(crate) struct MazePlugin; impl Plugin for MazePlugin { fn build(&self, app: &mut App) { app.add_plugins(prism::plugin); - app.add_plugins(grid::plugin); + // app.add_plugins(grid::plugin); // app.insert_resource(AmbientLight { // brightness: f32::MAX, // color: Color::WHITE, diff --git a/src/maze/prism.rs b/src/maze/prism.rs index 0310a0a..cc3e7e8 100644 --- a/src/maze/prism.rs +++ b/src/maze/prism.rs @@ -1,13 +1,14 @@ +use super::resource::{Layout, MazeConfig, HEX_SIZE}; use bevy::prelude::*; use core::f32; -use std::f32::consts::{FRAC_PI_2, FRAC_PI_3}; +use hexlab::prelude::*; +use hexx::{HexLayout, HexOrientation}; +use std::f32::consts::{FRAC_PI_2, FRAC_PI_3, FRAC_PI_6}; -use super::{ - resource::{Layout, MazeConfig, HEX_SIZE}, - tile::Tile, -}; - -pub(super) fn plugin(_app: &mut App) {} +pub(super) fn plugin(app: &mut App) { + app.init_resource::(); + app.init_resource::(); +} const WALL_SIZE: f32 = 1.0; pub(super) fn setup( @@ -17,10 +18,14 @@ pub(super) fn setup( config: Res, layout: Res, ) { - let radius = config.radius as i32; + let maze = MazeBuilder::new() + .with_radius(config.radius) + // .with_seed(0) + .with_generator(GeneratorType::RecursiveBacktracking) + .build() + .expect("Something went wrong while creating maze"); let assets = create_base_assets(&mut meshes, &mut materials, &config); - // spawn_single_hex_tile(&mut commands, &assets, &config); commands .spawn(( Name::new("Floor"), @@ -30,44 +35,47 @@ pub(super) fn setup( }, )) .with_children(|parent| { - for q in -radius..=radius { - let r1 = (-radius).max(-q - radius); - let r2 = radius.min(-q + radius); - for r in r1..=r2 { - let tile = Tile::new(q, r); - spawn_single_hex_tile(parent, &tile, &layout, &assets, &config); - } + for tile in maze.values() { + spawn_single_hex_tile(parent, &assets, tile, &layout.0, config.height) } }); } fn spawn_single_hex_tile( parent: &mut ChildBuilder, - tile: &Tile, - layout: &Res, assets: &MazeAssets, - config: &Res, + tile: &HexTile, + layout: &HexLayout, + hex_height: f32, ) { - let pos = tile.to_vec3(layout); + let world_pos = tile.to_vec3(layout); + let rotation = match layout.orientation { + HexOrientation::Pointy => Quat::from_rotation_y(0.0), + HexOrientation::Flat => Quat::from_rotation_y(FRAC_PI_6), // 30 degrees rotation + }; + parent .spawn(( - Name::new(format!("Hex {}", &tile.to_string())), + Name::new(format!("Hex {}", tile.to_string())), PbrBundle { mesh: assets.hex_mesh.clone(), material: assets.hex_material.clone(), - transform: Transform::from_translation(pos), + transform: Transform::from_translation(world_pos).with_rotation(rotation), ..default() }, )) - .with_children(|parent| spawn_walls(parent, assets, config)); + .with_children(|parent| spawn_walls(parent, assets, hex_height / 2., &tile.walls())); } -fn spawn_walls(parent: &mut ChildBuilder, asstets: &MazeAssets, config: &Res) { - let y_offset = config.height / 2.; +fn spawn_walls(parent: &mut ChildBuilder, assets: &MazeAssets, y_offset: f32, walls: &Walls) { let z_rotation = Quat::from_rotation_z(-FRAC_PI_2); for i in 0..6 { - let wall_angle = FRAC_PI_3 * i as f32; + if !walls.contains(i) { + continue; + } + + let wall_angle = -FRAC_PI_3 * i as f32; let x_offset = (HEX_SIZE - WALL_SIZE) * f32::cos(wall_angle); let z_offset = (HEX_SIZE - WALL_SIZE) * f32::sin(wall_angle); @@ -76,7 +84,7 @@ fn spawn_walls(parent: &mut ChildBuilder, asstets: &MazeAssets, config: &Res Self { let mut rng = thread_rng(); - let radius = 11; + let radius = 7; let start_pos = Hex::new( rng.gen_range(-radius..radius), rng.gen_range(-radius..radius), @@ -43,7 +43,7 @@ pub struct Layout(pub HexLayout); impl FromWorld for Layout { fn from_world(_world: &mut World) -> Self { Self(HexLayout { - orientation: HexOrientation::Pointy, + orientation: HexOrientation::Flat, hex_size: Vec2::splat(HEX_SIZE), ..default() }) diff --git a/src/maze/tile.rs b/src/maze/tile.rs deleted file mode 100644 index 7c75af7..0000000 --- a/src/maze/tile.rs +++ /dev/null @@ -1,55 +0,0 @@ -use std::fmt::Display; - -use bevy::prelude::*; -use hexx::{Hex, HexLayout}; - -#[derive(Debug, Reflect, Component, Default, PartialEq, Eq, Hash, Clone)] -#[reflect(Component)] -pub struct Tile { - pub hex: Hex, - pub visited: bool, -} - -#[derive(Debug, Reflect, Component, Deref, DerefMut, Clone)] -#[reflect(Component)] -pub struct Walls(pub [bool; 6]); - -#[derive(Debug, Reflect, Bundle, Default)] -pub struct TileBundle { - pub hex: Tile, - pub walls: Walls, -} - -impl Tile { - pub fn new(q: i32, r: i32) -> Self { - Self { - hex: Hex::new(q, r), - visited: false, - } - } - - pub fn _visit(&mut self) { - self.visited = true; - } - - pub fn to_vec2(&self, layout: &HexLayout) -> Vec2 { - layout.hex_to_world_pos(self.hex) - } - - pub fn to_vec3(&self, layout: &HexLayout) -> Vec3 { - let pos = self.to_vec2(layout); - Vec3::new(pos.x, 0., pos.y) - } -} - -impl Display for Tile { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "({},{})", self.hex.x, self.hex.y) - } -} - -impl Default for Walls { - fn default() -> Self { - Self([true; 6]) - } -} From 0ca94082a9a0879d39ae3eeda323ad724813f752 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sun, 8 Dec 2024 16:26:20 +0200 Subject: [PATCH 2/8] refactor(maze): reorganize maze module code --- Cargo.lock | 3 +- Cargo.toml | 4 +- src/maze/assets.rs | 56 +++++++++ src/maze/components.rs | 9 ++ src/maze/mod.rs | 8 +- src/maze/plugin.rs | 14 +-- src/maze/prism.rs | 154 ------------------------- src/maze/{resource.rs => resources.rs} | 1 + src/maze/systems/mod.rs | 2 + src/maze/systems/setup.rs | 36 ++++++ src/maze/systems/spawn.rs | 74 ++++++++++++ 11 files changed, 192 insertions(+), 169 deletions(-) create mode 100644 src/maze/assets.rs create mode 100644 src/maze/components.rs delete mode 100644 src/maze/prism.rs rename src/maze/{resource.rs => resources.rs} (97%) create mode 100644 src/maze/systems/mod.rs create mode 100644 src/maze/systems/setup.rs create mode 100644 src/maze/systems/spawn.rs diff --git a/Cargo.lock b/Cargo.lock index 90d8ee5..eee077a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2673,10 +2673,11 @@ dependencies = [ [[package]] name = "maze-ascension" -version = "0.1.0" +version = "0.0.6" dependencies = [ "bevy", "bevy-inspector-egui", + "bevy_egui", "hexlab", "hexx", "log", diff --git a/Cargo.toml b/Cargo.toml index e4b23c0..8f92d8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "maze-ascension" authors = ["Kristofers Solo "] -version = "0.1.0" +version = "0.0.6" edition = "2021" [dependencies] @@ -20,6 +20,7 @@ tracing = { version = "0.1", features = [ hexx = { version = "0.18", features = ["bevy_reflect", "grid"] } hexlab = { version = "0.1", features = ["bevy"] } bevy-inspector-egui = { version = "0.27", optional = true } +bevy_egui = { version = "0.30", optional = true } [features] @@ -32,6 +33,7 @@ dev = [ "bevy/dynamic_linking", "bevy/bevy_dev_tools", "dep:bevy-inspector-egui", + "dep:bevy_egui", ] dev_native = [ "dev", diff --git a/src/maze/assets.rs b/src/maze/assets.rs new file mode 100644 index 0000000..539f4a6 --- /dev/null +++ b/src/maze/assets.rs @@ -0,0 +1,56 @@ +use std::f32::consts::FRAC_PI_2; + +use bevy::prelude::*; + +use super::{ + resources::{HEX_SIZE, WALL_SIZE}, + MazeConfig, +}; + +pub(crate) struct MazeAssets { + pub(crate) hex_mesh: Handle, + pub(crate) wall_mesh: Handle, + pub(crate) hex_material: Handle, + pub(crate) wall_material: Handle, +} + +pub(crate) fn create_base_assets( + meshes: &mut ResMut>, + materials: &mut ResMut>, + config: &Res, +) -> MazeAssets { + MazeAssets { + hex_mesh: meshes.add(generate_hex_mesh(HEX_SIZE, config.height)), + wall_mesh: meshes.add(generate_square_mesh(HEX_SIZE)), + hex_material: materials.add(white_material()), + wall_material: materials.add(Color::BLACK), + } +} + +fn generate_hex_mesh(radius: f32, depth: f32) -> Mesh { + let hexagon = RegularPolygon { + sides: 6, + circumcircle: Circle::new(radius), + }; + let prism_shape = Extrusion::new(hexagon, depth); + let rotation = Quat::from_rotation_x(FRAC_PI_2); + + Mesh::from(prism_shape).rotated_by(rotation) +} + +fn generate_square_mesh(depth: f32) -> Mesh { + let square = Rectangle::new(WALL_SIZE, WALL_SIZE); + let rectangular_prism = Extrusion::new(square, depth); + let rotation = Quat::from_rotation_x(FRAC_PI_2); + + Mesh::from(rectangular_prism).rotated_by(rotation) +} + +fn white_material() -> StandardMaterial { + let val = 10.; + StandardMaterial { + base_color: Color::WHITE, + emissive: LinearRgba::new(val, val, val, val), + ..default() + } +} diff --git a/src/maze/components.rs b/src/maze/components.rs new file mode 100644 index 0000000..2cb53b4 --- /dev/null +++ b/src/maze/components.rs @@ -0,0 +1,9 @@ +use bevy::prelude::*; + +#[derive(Debug, Reflect, Component)] +#[reflect(Component)] +pub(crate) struct MazeWall; + +#[derive(Debug, Reflect, Component)] +#[reflect(Component)] +pub(crate) struct MazeTile; diff --git a/src/maze/mod.rs b/src/maze/mod.rs index 94f0bdd..23064f0 100644 --- a/src/maze/mod.rs +++ b/src/maze/mod.rs @@ -1,8 +1,12 @@ use bevy::{ecs::world::Command, prelude::*}; use plugin::MazePlugin; +mod assets; +mod components; pub mod plugin; -pub mod prism; -pub mod resource; +mod resources; +mod systems; + +pub use resources::MazeConfig; pub fn spawn_grid(world: &mut World) { MazePlugin.apply(world); diff --git a/src/maze/plugin.rs b/src/maze/plugin.rs index ad31ce9..b08bb06 100644 --- a/src/maze/plugin.rs +++ b/src/maze/plugin.rs @@ -3,27 +3,19 @@ use bevy::{ prelude::*, }; -use super::prism; +use super::{resources::Layout, systems, MazeConfig}; #[derive(Default)] pub(crate) struct MazePlugin; impl Plugin for MazePlugin { fn build(&self, app: &mut App) { - app.add_plugins(prism::plugin); - // app.add_plugins(grid::plugin); - // app.insert_resource(AmbientLight { - // brightness: f32::MAX, - // color: Color::WHITE, - // }); + app.init_resource::().init_resource::(); } } impl Command for MazePlugin { fn apply(self, world: &mut World) { - // world.run_system_once(spawn_hex_grid); - // world.run_system_once(generate_maze); - // world.run_system_once(render_maze); - world.run_system_once(prism::setup); + world.run_system_once(systems::setup::setup); } } diff --git a/src/maze/prism.rs b/src/maze/prism.rs deleted file mode 100644 index cc3e7e8..0000000 --- a/src/maze/prism.rs +++ /dev/null @@ -1,154 +0,0 @@ -use super::resource::{Layout, MazeConfig, HEX_SIZE}; -use bevy::prelude::*; -use core::f32; -use hexlab::prelude::*; -use hexx::{HexLayout, HexOrientation}; -use std::f32::consts::{FRAC_PI_2, FRAC_PI_3, FRAC_PI_6}; - -pub(super) fn plugin(app: &mut App) { - app.init_resource::(); - app.init_resource::(); -} -const WALL_SIZE: f32 = 1.0; - -pub(super) fn setup( - mut commands: Commands, - mut meshes: ResMut>, - mut materials: ResMut>, - config: Res, - layout: Res, -) { - let maze = MazeBuilder::new() - .with_radius(config.radius) - // .with_seed(0) - .with_generator(GeneratorType::RecursiveBacktracking) - .build() - .expect("Something went wrong while creating maze"); - - let assets = create_base_assets(&mut meshes, &mut materials, &config); - commands - .spawn(( - Name::new("Floor"), - SpatialBundle { - transform: Transform::from_translation(Vec3::ZERO), - ..default() - }, - )) - .with_children(|parent| { - for tile in maze.values() { - spawn_single_hex_tile(parent, &assets, tile, &layout.0, config.height) - } - }); -} - -fn spawn_single_hex_tile( - parent: &mut ChildBuilder, - assets: &MazeAssets, - tile: &HexTile, - layout: &HexLayout, - hex_height: f32, -) { - let world_pos = tile.to_vec3(layout); - let rotation = match layout.orientation { - HexOrientation::Pointy => Quat::from_rotation_y(0.0), - HexOrientation::Flat => Quat::from_rotation_y(FRAC_PI_6), // 30 degrees rotation - }; - - parent - .spawn(( - Name::new(format!("Hex {}", tile.to_string())), - PbrBundle { - mesh: assets.hex_mesh.clone(), - material: assets.hex_material.clone(), - transform: Transform::from_translation(world_pos).with_rotation(rotation), - ..default() - }, - )) - .with_children(|parent| spawn_walls(parent, assets, hex_height / 2., &tile.walls())); -} - -fn spawn_walls(parent: &mut ChildBuilder, assets: &MazeAssets, y_offset: f32, walls: &Walls) { - let z_rotation = Quat::from_rotation_z(-FRAC_PI_2); - - for i in 0..6 { - if !walls.contains(i) { - continue; - } - - let wall_angle = -FRAC_PI_3 * i as f32; - - let x_offset = (HEX_SIZE - WALL_SIZE) * f32::cos(wall_angle); - let z_offset = (HEX_SIZE - WALL_SIZE) * f32::sin(wall_angle); - let pos = Vec3::new(x_offset, y_offset, z_offset); - - let x_rotation = Quat::from_rotation_x(wall_angle + FRAC_PI_2); - let final_rotation = z_rotation * x_rotation; - - spawn_single_wall(parent, assets, final_rotation, pos); - } -} - -fn spawn_single_wall( - parent: &mut ChildBuilder, - asstets: &MazeAssets, - rotation: Quat, - offset: Vec3, -) { - parent.spawn(( - Name::new("Wall"), - PbrBundle { - mesh: asstets.wall_mesh.clone(), - material: asstets.wall_material.clone(), - transform: Transform::from_translation(offset).with_rotation(rotation), - ..default() - }, - )); -} - -fn create_base_assets( - meshes: &mut ResMut>, - materials: &mut ResMut>, - config: &Res, -) -> MazeAssets { - MazeAssets { - hex_mesh: meshes.add(generate_hex_mesh(HEX_SIZE, config.height)), - wall_mesh: meshes.add(generate_square_mesh(HEX_SIZE)), - hex_material: materials.add(white_material()), - wall_material: materials.add(Color::BLACK), - } -} - -fn generate_hex_mesh(radius: f32, depth: f32) -> Mesh { - let hexagon = RegularPolygon { - sides: 6, - circumcircle: Circle::new(radius), - }; - let prism_shape = Extrusion::new(hexagon, depth); - let rotation = Quat::from_rotation_x(FRAC_PI_2); - - Mesh::from(prism_shape).rotated_by(rotation) -} - -fn generate_square_mesh(depth: f32) -> Mesh { - let square = Rectangle::new(WALL_SIZE, WALL_SIZE); - let rectangular_prism = Extrusion::new(square, depth); - let rotation = Quat::from_rotation_x(FRAC_PI_2); - - Mesh::from(rectangular_prism).rotated_by(rotation) -} - -fn white_material() -> StandardMaterial { - let val = 10.; - StandardMaterial { - base_color: Color::WHITE, - emissive: LinearRgba::new(val, val, val, val), - ..default() - } -} - -struct MazeAssets { - hex_mesh: Handle, - wall_mesh: Handle, - hex_material: Handle, - wall_material: Handle, -} diff --git a/src/maze/resource.rs b/src/maze/resources.rs similarity index 97% rename from src/maze/resource.rs rename to src/maze/resources.rs index 0bc2f84..ccc9d6b 100644 --- a/src/maze/resource.rs +++ b/src/maze/resources.rs @@ -3,6 +3,7 @@ use hexx::{Hex, HexLayout, HexOrientation}; use rand::{thread_rng, Rng}; pub(crate) const HEX_SIZE: f32 = 6.; +pub(crate) const WALL_SIZE: f32 = 1.0; #[derive(Debug, Reflect, Resource)] #[reflect(Resource)] diff --git a/src/maze/systems/mod.rs b/src/maze/systems/mod.rs new file mode 100644 index 0000000..c525b54 --- /dev/null +++ b/src/maze/systems/mod.rs @@ -0,0 +1,2 @@ +pub mod setup; +mod spawn; diff --git a/src/maze/systems/setup.rs b/src/maze/systems/setup.rs new file mode 100644 index 0000000..c00ee92 --- /dev/null +++ b/src/maze/systems/setup.rs @@ -0,0 +1,36 @@ +use bevy::prelude::*; +use hexlab::{GeneratorType, MazeBuilder}; + +use crate::maze::{assets::create_base_assets, resources::Layout, MazeConfig}; + +use super::spawn::spawn_single_hex_tile; + +pub(crate) fn setup( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, + config: Res, + layout: Res, +) { + let maze = MazeBuilder::new() + .with_radius(config.radius) + // .with_seed(0) + .with_generator(GeneratorType::RecursiveBacktracking) + .build() + .expect("Something went wrong while creating maze"); + + let assets = create_base_assets(&mut meshes, &mut materials, &config); + commands + .spawn(( + Name::new("Floor"), + SpatialBundle { + transform: Transform::from_translation(Vec3::ZERO), + ..default() + }, + )) + .with_children(|parent| { + for tile in maze.values() { + spawn_single_hex_tile(parent, &assets, tile, &layout.0, config.height) + } + }); +} diff --git a/src/maze/systems/spawn.rs b/src/maze/systems/spawn.rs new file mode 100644 index 0000000..25b13db --- /dev/null +++ b/src/maze/systems/spawn.rs @@ -0,0 +1,74 @@ +use std::f32::consts::{FRAC_PI_2, FRAC_PI_3, FRAC_PI_6}; + +use bevy::prelude::*; +use hexlab::prelude::*; +use hexx::HexOrientation; + +use crate::maze::{ + assets::MazeAssets, + resources::{HEX_SIZE, WALL_SIZE}, +}; + +pub(super) fn spawn_single_hex_tile( + parent: &mut ChildBuilder, + assets: &MazeAssets, + tile: &HexTile, + layout: &HexLayout, + hex_height: f32, +) { + let world_pos = tile.to_vec3(layout); + let rotation = match layout.orientation { + HexOrientation::Pointy => Quat::from_rotation_y(0.0), + HexOrientation::Flat => Quat::from_rotation_y(FRAC_PI_6), // 30 degrees rotation + }; + + parent + .spawn(( + Name::new(format!("Hex {}", tile.to_string())), + PbrBundle { + mesh: assets.hex_mesh.clone(), + material: assets.hex_material.clone(), + transform: Transform::from_translation(world_pos).with_rotation(rotation), + ..default() + }, + )) + .with_children(|parent| spawn_walls(parent, assets, hex_height / 2., &tile.walls())); +} + +fn spawn_walls(parent: &mut ChildBuilder, assets: &MazeAssets, y_offset: f32, walls: &Walls) { + let z_rotation = Quat::from_rotation_z(-FRAC_PI_2); + + for i in 0..6 { + if !walls.contains(i) { + continue; + } + + let wall_angle = -FRAC_PI_3 * i as f32; + + let x_offset = (HEX_SIZE - WALL_SIZE) * f32::cos(wall_angle); + let z_offset = (HEX_SIZE - WALL_SIZE) * f32::sin(wall_angle); + let pos = Vec3::new(x_offset, y_offset, z_offset); + + let x_rotation = Quat::from_rotation_x(wall_angle + FRAC_PI_2); + let final_rotation = z_rotation * x_rotation; + + spawn_single_wall(parent, assets, final_rotation, pos); + } +} + +fn spawn_single_wall( + parent: &mut ChildBuilder, + asstets: &MazeAssets, + rotation: Quat, + offset: Vec3, +) { + parent.spawn(( + Name::new("Wall"), + PbrBundle { + mesh: asstets.wall_mesh.clone(), + material: asstets.wall_material.clone(), + transform: Transform::from_translation(offset).with_rotation(rotation), + ..default() + }, + )); +} From 24b92a24ccf75b7bd5bc541b6b13180344d52a45 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sun, 8 Dec 2024 17:09:21 +0200 Subject: [PATCH 3/8] feat(maze): add maze recreation ability --- src/dev_tools.rs | 55 +++++++++++++++++++++++++++------- src/maze/assets.rs | 2 +- src/maze/components.rs | 6 +++- src/maze/events.rs | 6 ++++ src/maze/mod.rs | 1 + src/maze/plugin.rs | 12 ++++++-- src/maze/systems/mod.rs | 1 + src/maze/systems/recreation.rs | 30 +++++++++++++++++++ src/maze/systems/setup.rs | 17 +++++++++-- src/maze/systems/spawn.rs | 3 ++ 10 files changed, 116 insertions(+), 17 deletions(-) create mode 100644 src/maze/events.rs create mode 100644 src/maze/systems/recreation.rs diff --git a/src/dev_tools.rs b/src/dev_tools.rs index 1b78f7e..14e85db 100644 --- a/src/dev_tools.rs +++ b/src/dev_tools.rs @@ -7,23 +7,29 @@ use bevy::{ }, input::common_conditions::input_just_pressed, prelude::*, + window::PrimaryWindow, }; -use bevy_inspector_egui::quick::WorldInspectorPlugin; +use bevy_inspector_egui::{bevy_egui::EguiContext, DefaultInspectorConfigPlugin}; -use crate::screens::Screen; +use crate::{maze::events::RecreateMazeEvent, screens::Screen}; +use bevy_egui::{ + egui::{self, Button, Color32, ScrollArea}, + EguiPlugin, +}; pub(super) fn plugin(app: &mut App) { // Log `Screen` state transitions. - app.add_systems(Update, log_transitions::); - - // Toggle the debug overlay for UI. - app.add_plugins(DebugUiPlugin); - app.add_plugins(WorldInspectorPlugin::default()); - app.add_systems( - Update, - toggle_debug_ui.run_if(input_just_pressed(TOGGLE_KEY)), - ); + app.add_systems(Update, log_transitions::) + .add_plugins(EguiPlugin) + .add_plugins(DebugUiPlugin) + .add_plugins(DefaultInspectorConfigPlugin) + .add_systems(Update, inspector_ui) + // Toggle the debug overlay for UI. + .add_systems( + Update, + toggle_debug_ui.run_if(input_just_pressed(TOGGLE_KEY)), + ); } const TOGGLE_KEY: KeyCode = KeyCode::Backquote; @@ -31,3 +37,30 @@ const TOGGLE_KEY: KeyCode = KeyCode::Backquote; fn toggle_debug_ui(mut options: ResMut) { options.toggle(); } + +fn inspector_ui(world: &mut World) { + let Ok(egui_context) = world + .query_filtered::<&mut EguiContext, With>() + .get_single(world) + else { + return; + }; + + let mut egui_context = egui_context.clone(); + + egui::Window::new("UI").show(egui_context.get_mut(), |ui| { + ScrollArea::vertical().show(ui, |ui| { + bevy_inspector_egui::bevy_inspector::ui_for_world(world, ui); + }); + + ui.add_space(8.); + + let button = Button::new("Recreate maze").fill(Color32::from_rgb(108, 108, 108)); + + if ui.add(button).clicked() { + if let Some(mut event_writer) = world.get_resource_mut::>() { + event_writer.send(RecreateMazeEvent { floor: 1 }); + } + } + }); +} diff --git a/src/maze/assets.rs b/src/maze/assets.rs index 539f4a6..3ae52fa 100644 --- a/src/maze/assets.rs +++ b/src/maze/assets.rs @@ -17,7 +17,7 @@ pub(crate) struct MazeAssets { pub(crate) fn create_base_assets( meshes: &mut ResMut>, materials: &mut ResMut>, - config: &Res, + config: &MazeConfig, ) -> MazeAssets { MazeAssets { hex_mesh: meshes.add(generate_hex_mesh(HEX_SIZE, config.height)), diff --git a/src/maze/components.rs b/src/maze/components.rs index 2cb53b4..1d9ccd8 100644 --- a/src/maze/components.rs +++ b/src/maze/components.rs @@ -2,8 +2,12 @@ use bevy::prelude::*; #[derive(Debug, Reflect, Component)] #[reflect(Component)] -pub(crate) struct MazeWall; +pub(crate) struct MazeFloor(pub(crate) u8); #[derive(Debug, Reflect, Component)] #[reflect(Component)] pub(crate) struct MazeTile; + +#[derive(Debug, Reflect, Component)] +#[reflect(Component)] +pub(crate) struct MazeWall; diff --git a/src/maze/events.rs b/src/maze/events.rs new file mode 100644 index 0000000..2a10115 --- /dev/null +++ b/src/maze/events.rs @@ -0,0 +1,6 @@ +use bevy::prelude::*; + +#[derive(Debug, Event)] +pub(crate) struct RecreateMazeEvent { + pub(crate) floor: u8, +} diff --git a/src/maze/mod.rs b/src/maze/mod.rs index 23064f0..26aec4f 100644 --- a/src/maze/mod.rs +++ b/src/maze/mod.rs @@ -2,6 +2,7 @@ use bevy::{ecs::world::Command, prelude::*}; use plugin::MazePlugin; mod assets; mod components; +pub mod events; pub mod plugin; mod resources; mod systems; diff --git a/src/maze/plugin.rs b/src/maze/plugin.rs index b08bb06..d4ce8c2 100644 --- a/src/maze/plugin.rs +++ b/src/maze/plugin.rs @@ -3,14 +3,22 @@ use bevy::{ prelude::*, }; -use super::{resources::Layout, systems, MazeConfig}; +use super::{ + events::RecreateMazeEvent, + resources::Layout, + systems::{self, recreation::handle_maze_recreation_event}, + MazeConfig, +}; #[derive(Default)] pub(crate) struct MazePlugin; impl Plugin for MazePlugin { fn build(&self, app: &mut App) { - app.init_resource::().init_resource::(); + app.init_resource::() + .init_resource::() + .add_event::() + .add_systems(Update, handle_maze_recreation_event); } } diff --git a/src/maze/systems/mod.rs b/src/maze/systems/mod.rs index c525b54..6fe5160 100644 --- a/src/maze/systems/mod.rs +++ b/src/maze/systems/mod.rs @@ -1,2 +1,3 @@ +pub mod recreation; pub mod setup; mod spawn; diff --git a/src/maze/systems/recreation.rs b/src/maze/systems/recreation.rs new file mode 100644 index 0000000..cadd2cb --- /dev/null +++ b/src/maze/systems/recreation.rs @@ -0,0 +1,30 @@ +use bevy::prelude::*; + +use crate::maze::{ + components::MazeFloor, events::RecreateMazeEvent, resources::Layout, MazeConfig, +}; + +use super::setup::setup_maze; + +pub(crate) fn handle_maze_recreation_event( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, + config: Res, + layout: Res, + query: Query<(Entity, &MazeFloor)>, + mut event_reader: EventReader, +) { + for event in event_reader.read() { + despawn_floor(&mut commands, &query, event.floor); + setup_maze(&mut commands, &mut meshes, &mut materials, &config, &layout); + } +} + +fn despawn_floor(commands: &mut Commands, query: &Query<(Entity, &MazeFloor)>, floor_num: u8) { + for (entity, maze_floor) in query.iter() { + if maze_floor.0 == floor_num { + commands.entity(entity).despawn_recursive(); + } + } +} diff --git a/src/maze/systems/setup.rs b/src/maze/systems/setup.rs index c00ee92..8e7da5e 100644 --- a/src/maze/systems/setup.rs +++ b/src/maze/systems/setup.rs @@ -1,7 +1,9 @@ use bevy::prelude::*; use hexlab::{GeneratorType, MazeBuilder}; -use crate::maze::{assets::create_base_assets, resources::Layout, MazeConfig}; +use crate::maze::{ + assets::create_base_assets, components::MazeFloor, resources::Layout, MazeConfig, +}; use super::spawn::spawn_single_hex_tile; @@ -11,6 +13,16 @@ pub(crate) fn setup( mut materials: ResMut>, config: Res, layout: Res, +) { + setup_maze(&mut commands, &mut meshes, &mut materials, &config, &layout); +} + +pub(super) fn setup_maze( + commands: &mut Commands, + meshes: &mut ResMut>, + materials: &mut ResMut>, + config: &MazeConfig, + layout: &Layout, ) { let maze = MazeBuilder::new() .with_radius(config.radius) @@ -19,10 +31,11 @@ pub(crate) fn setup( .build() .expect("Something went wrong while creating maze"); - let assets = create_base_assets(&mut meshes, &mut materials, &config); + let assets = create_base_assets(meshes, materials, config); commands .spawn(( Name::new("Floor"), + MazeFloor(1), SpatialBundle { transform: Transform::from_translation(Vec3::ZERO), ..default() diff --git a/src/maze/systems/spawn.rs b/src/maze/systems/spawn.rs index 25b13db..2ec9259 100644 --- a/src/maze/systems/spawn.rs +++ b/src/maze/systems/spawn.rs @@ -6,6 +6,7 @@ use hexx::HexOrientation; use crate::maze::{ assets::MazeAssets, + components::{MazeTile, MazeWall}, resources::{HEX_SIZE, WALL_SIZE}, }; @@ -25,6 +26,7 @@ pub(super) fn spawn_single_hex_tile( parent .spawn(( Name::new(format!("Hex {}", tile.to_string())), + MazeTile, PbrBundle { mesh: assets.hex_mesh.clone(), material: assets.hex_material.clone(), @@ -64,6 +66,7 @@ fn spawn_single_wall( ) { parent.spawn(( Name::new("Wall"), + MazeWall, PbrBundle { mesh: asstets.wall_mesh.clone(), material: asstets.wall_material.clone(), From dca6747f83d6861071f230a4c934234f9f2c29c9 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sun, 8 Dec 2024 17:50:56 +0200 Subject: [PATCH 4/8] feat(maze): use seed --- Cargo.lock | 13 ++++--- Cargo.toml | 1 + src/dev_tools.rs | 74 +++++++++++++++++++++++++++++++---- src/maze/assets.rs | 9 ++--- src/maze/resources.rs | 77 ++++++++++++++++++++++++++----------- src/maze/systems/despawn.rs | 3 ++ src/maze/systems/setup.rs | 4 +- src/maze/systems/spawn.rs | 14 ++++--- 8 files changed, 146 insertions(+), 49 deletions(-) create mode 100644 src/maze/systems/despawn.rs diff --git a/Cargo.lock b/Cargo.lock index eee077a..5b82855 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2327,7 +2327,7 @@ dependencies = [ "hexx", "rand", "rand_chacha", - "thiserror 2.0.3", + "thiserror 2.0.5", ] [[package]] @@ -2682,6 +2682,7 @@ dependencies = [ "hexx", "log", "rand", + "thiserror 2.0.5", "tracing", ] @@ -3862,11 +3863,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.3" +version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +checksum = "643caef17e3128658ff44d85923ef2d28af81bb71e0d67bbfe1d76f19a73e053" dependencies = [ - "thiserror-impl 2.0.3", + "thiserror-impl 2.0.5", ] [[package]] @@ -3882,9 +3883,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.3" +version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +checksum = "995d0bbc9995d1f19d28b7215a9352b0fc3cd3a2d2ec95c2cadc485cdedbcdde" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 8f92d8a..18a1a8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ hexx = { version = "0.18", features = ["bevy_reflect", "grid"] } hexlab = { version = "0.1", features = ["bevy"] } bevy-inspector-egui = { version = "0.27", optional = true } bevy_egui = { version = "0.30", optional = true } +thiserror = "2.0" [features] diff --git a/src/dev_tools.rs b/src/dev_tools.rs index 14e85db..52bea5c 100644 --- a/src/dev_tools.rs +++ b/src/dev_tools.rs @@ -12,9 +12,12 @@ use bevy::{ use bevy_inspector_egui::{bevy_egui::EguiContext, DefaultInspectorConfigPlugin}; -use crate::{maze::events::RecreateMazeEvent, screens::Screen}; +use crate::{ + maze::{events::RecreateMazeEvent, MazeConfig}, + screens::Screen, +}; use bevy_egui::{ - egui::{self, Button, Color32, ScrollArea}, + egui::{self, Button, Color32, DragValue, ScrollArea}, EguiPlugin, }; @@ -52,14 +55,71 @@ fn inspector_ui(world: &mut World) { ScrollArea::vertical().show(ui, |ui| { bevy_inspector_egui::bevy_inspector::ui_for_world(world, ui); }); + }); - ui.add_space(8.); + egui::Window::new("Maze Controls").show(egui_context.get_mut(), |ui| { + if let Some(mut maze_config) = world.get_resource_mut::() { + ui.heading("Maze Configuration"); - let button = Button::new("Recreate maze").fill(Color32::from_rgb(108, 108, 108)); + // radius controls + ui.horizontal(|ui| { + ui.label("Radius:"); + ui.add( + DragValue::new(&mut maze_config.radius) + .speed(1) + .range(1..=100), + ); + }); - if ui.add(button).clicked() { - if let Some(mut event_writer) = world.get_resource_mut::>() { - event_writer.send(RecreateMazeEvent { floor: 1 }); + // height controls + ui.horizontal(|ui| { + ui.label("Height:"); + ui.add( + DragValue::new(&mut maze_config.height) + .speed(0.5) + .range(1.0..=50.), + ); + }); + + // start position + ui.horizontal(|ui| { + ui.label("Start Position:"); + ui.add( + DragValue::new(&mut maze_config.start_pos.x) + .speed(1) + .prefix("x: "), + ); + ui.add( + DragValue::new(&mut maze_config.start_pos.y) + .speed(1) + .prefix("y: "), + ); + }); + + // end position + ui.horizontal(|ui| { + ui.label("End Position:"); + ui.add( + DragValue::new(&mut maze_config.end_pos.x) + .speed(1) + .prefix("x: "), + ); + ui.add( + DragValue::new(&mut maze_config.end_pos.y) + .speed(1) + .prefix("y: "), + ); + }); + + ui.add_space(8.); + + let button = Button::new("Recreate maze").fill(Color32::from_rgb(108, 108, 108)); + if ui.add(button).clicked() { + if let Some(mut event_writer) = + world.get_resource_mut::>() + { + event_writer.send(RecreateMazeEvent { floor: 1 }); + } } } }); diff --git a/src/maze/assets.rs b/src/maze/assets.rs index 3ae52fa..5a2d31d 100644 --- a/src/maze/assets.rs +++ b/src/maze/assets.rs @@ -2,10 +2,7 @@ use std::f32::consts::FRAC_PI_2; use bevy::prelude::*; -use super::{ - resources::{HEX_SIZE, WALL_SIZE}, - MazeConfig, -}; +use super::{resources::WALL_SIZE, MazeConfig}; pub(crate) struct MazeAssets { pub(crate) hex_mesh: Handle, @@ -20,8 +17,8 @@ pub(crate) fn create_base_assets( config: &MazeConfig, ) -> MazeAssets { MazeAssets { - hex_mesh: meshes.add(generate_hex_mesh(HEX_SIZE, config.height)), - wall_mesh: meshes.add(generate_square_mesh(HEX_SIZE)), + hex_mesh: meshes.add(generate_hex_mesh(config.size, config.height)), + wall_mesh: meshes.add(generate_square_mesh(config.size)), hex_material: materials.add(white_material()), wall_material: materials.add(Color::BLACK), } diff --git a/src/maze/resources.rs b/src/maze/resources.rs index ccc9d6b..77bcb0d 100644 --- a/src/maze/resources.rs +++ b/src/maze/resources.rs @@ -1,39 +1,63 @@ +use std::num::TryFromIntError; + use bevy::prelude::*; use hexx::{Hex, HexLayout, HexOrientation}; -use rand::{thread_rng, Rng}; +use rand::{rngs::StdRng, thread_rng, Rng, SeedableRng}; +use thiserror::Error; -pub(crate) const HEX_SIZE: f32 = 6.; pub(crate) const WALL_SIZE: f32 = 1.0; +#[derive(Debug, Error)] +pub enum MazeConfigError { + #[error("Failed to convert radius from u32 to i32: {0}")] + RadiusConverions(#[from] TryFromIntError), +} #[derive(Debug, Reflect, Resource)] #[reflect(Resource)] pub struct MazeConfig { pub radius: u32, pub height: f32, + pub size: f32, pub start_pos: Hex, pub end_pos: Hex, + pub seed: u64, +} + +impl MazeConfig { + fn new( + radius: u32, + height: f32, + size: f32, + seed: Option, + ) -> Result { + let seed = seed.unwrap_or_else(|| thread_rng().gen()); + let mut rng = StdRng::seed_from_u64(seed); + + let start_pos = generate_pos(radius, &mut rng)?; + let end_pos = generate_pos(radius, &mut rng)?; + + debug!("Start pos: ({},{})", start_pos.x, start_pos.y); + debug!("End pos: ({},{})", end_pos.x, end_pos.y); + + Ok(Self { + radius: radius as u32, + height, + size, + start_pos, + end_pos, + seed, + }) + } + + pub fn new_unchecked(radius: u32, height: f32, hex_size: f32, seed: Option) -> Self { + Self::new(radius, height, hex_size, seed) + .expect("Failed to create MazeConfig with supposedly safe values") + } } impl Default for MazeConfig { fn default() -> Self { - let mut rng = thread_rng(); - let radius = 7; - let start_pos = Hex::new( - rng.gen_range(-radius..radius), - rng.gen_range(-radius..radius), - ); - let end_pos = Hex::new( - rng.gen_range(-radius..radius), - rng.gen_range(-radius..radius), - ); - debug!("Start pos: ({},{})", start_pos.x, start_pos.y); - debug!("End pos: ({},{})", end_pos.x, end_pos.y); - Self { - radius: radius as u32, - height: 20., - start_pos, - end_pos, - } + Self::new_unchecked(7, 20., 6., None) } } @@ -42,11 +66,20 @@ impl Default for MazeConfig { pub struct Layout(pub HexLayout); impl FromWorld for Layout { - fn from_world(_world: &mut World) -> Self { + fn from_world(world: &mut World) -> Self { + let config = world.resource::(); Self(HexLayout { orientation: HexOrientation::Flat, - hex_size: Vec2::splat(HEX_SIZE), + hex_size: Vec2::splat(config.size), ..default() }) } } + +fn generate_pos(radius: u32, rng: &mut R) -> Result { + let radius = i32::try_from(radius)?; + Ok(Hex::new( + rng.gen_range(-radius..radius), + rng.gen_range(-radius..radius), + )) +} diff --git a/src/maze/systems/despawn.rs b/src/maze/systems/despawn.rs new file mode 100644 index 0000000..ad25077 --- /dev/null +++ b/src/maze/systems/despawn.rs @@ -0,0 +1,3 @@ +use bevy::prelude::*; + +use crate::maze::components::MazeFloor; diff --git a/src/maze/systems/setup.rs b/src/maze/systems/setup.rs index 8e7da5e..96556ad 100644 --- a/src/maze/systems/setup.rs +++ b/src/maze/systems/setup.rs @@ -26,7 +26,7 @@ pub(super) fn setup_maze( ) { let maze = MazeBuilder::new() .with_radius(config.radius) - // .with_seed(0) + .with_seed(config.seed) .with_generator(GeneratorType::RecursiveBacktracking) .build() .expect("Something went wrong while creating maze"); @@ -43,7 +43,7 @@ pub(super) fn setup_maze( )) .with_children(|parent| { for tile in maze.values() { - spawn_single_hex_tile(parent, &assets, tile, &layout.0, config.height) + spawn_single_hex_tile(parent, &assets, tile, &layout.0, &config) } }); } diff --git a/src/maze/systems/spawn.rs b/src/maze/systems/spawn.rs index 2ec9259..ca6b8d8 100644 --- a/src/maze/systems/spawn.rs +++ b/src/maze/systems/spawn.rs @@ -7,7 +7,8 @@ use hexx::HexOrientation; use crate::maze::{ assets::MazeAssets, components::{MazeTile, MazeWall}, - resources::{HEX_SIZE, WALL_SIZE}, + resources::WALL_SIZE, + MazeConfig, }; pub(super) fn spawn_single_hex_tile( @@ -15,7 +16,7 @@ pub(super) fn spawn_single_hex_tile( assets: &MazeAssets, tile: &HexTile, layout: &HexLayout, - hex_height: f32, + config: &MazeConfig, ) { let world_pos = tile.to_vec3(layout); let rotation = match layout.orientation { @@ -34,11 +35,12 @@ pub(super) fn spawn_single_hex_tile( ..default() }, )) - .with_children(|parent| spawn_walls(parent, assets, hex_height / 2., &tile.walls())); + .with_children(|parent| spawn_walls(parent, assets, config, &tile.walls())); } -fn spawn_walls(parent: &mut ChildBuilder, assets: &MazeAssets, y_offset: f32, walls: &Walls) { +fn spawn_walls(parent: &mut ChildBuilder, assets: &MazeAssets, config: &MazeConfig, walls: &Walls) { let z_rotation = Quat::from_rotation_z(-FRAC_PI_2); + let y_offset = config.height / 2.; for i in 0..6 { if !walls.contains(i) { @@ -47,8 +49,8 @@ fn spawn_walls(parent: &mut ChildBuilder, assets: &MazeAssets, y_offset: f32, wa let wall_angle = -FRAC_PI_3 * i as f32; - let x_offset = (HEX_SIZE - WALL_SIZE) * f32::cos(wall_angle); - let z_offset = (HEX_SIZE - WALL_SIZE) * f32::sin(wall_angle); + let x_offset = (config.size - WALL_SIZE) * f32::cos(wall_angle); + let z_offset = (config.size - WALL_SIZE) * f32::sin(wall_angle); let pos = Vec3::new(x_offset, y_offset, z_offset); let x_rotation = Quat::from_rotation_x(wall_angle + FRAC_PI_2); From 9ecb38b442d72b72c64913817c504b0708f9705e Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sun, 8 Dec 2024 18:02:06 +0200 Subject: [PATCH 5/8] refactor(dev-tools): reorganize dev tools module code --- src/dev_tools.rs | 126 ------------------------------ src/dev_tools/mod.rs | 4 + src/dev_tools/plugin.rs | 36 +++++++++ src/dev_tools/ui/inspector.rs | 20 +++++ src/dev_tools/ui/maze_controls.rs | 117 +++++++++++++++++++++++++++ src/dev_tools/ui/mod.rs | 5 ++ src/lib.rs | 2 +- src/maze/mod.rs | 4 +- src/maze/plugin.rs | 3 +- src/maze/resources.rs | 4 + src/screens/gameplay.rs | 2 +- 11 files changed, 192 insertions(+), 131 deletions(-) delete mode 100644 src/dev_tools.rs create mode 100644 src/dev_tools/mod.rs create mode 100644 src/dev_tools/plugin.rs create mode 100644 src/dev_tools/ui/inspector.rs create mode 100644 src/dev_tools/ui/maze_controls.rs create mode 100644 src/dev_tools/ui/mod.rs diff --git a/src/dev_tools.rs b/src/dev_tools.rs deleted file mode 100644 index 52bea5c..0000000 --- a/src/dev_tools.rs +++ /dev/null @@ -1,126 +0,0 @@ -//! Development tools for the game. This plugin is only enabled in dev builds. - -use bevy::{ - dev_tools::{ - states::log_transitions, - ui_debug_overlay::{DebugUiPlugin, UiDebugOptions}, - }, - input::common_conditions::input_just_pressed, - prelude::*, - window::PrimaryWindow, -}; - -use bevy_inspector_egui::{bevy_egui::EguiContext, DefaultInspectorConfigPlugin}; - -use crate::{ - maze::{events::RecreateMazeEvent, MazeConfig}, - screens::Screen, -}; -use bevy_egui::{ - egui::{self, Button, Color32, DragValue, ScrollArea}, - EguiPlugin, -}; - -pub(super) fn plugin(app: &mut App) { - // Log `Screen` state transitions. - app.add_systems(Update, log_transitions::) - .add_plugins(EguiPlugin) - .add_plugins(DebugUiPlugin) - .add_plugins(DefaultInspectorConfigPlugin) - .add_systems(Update, inspector_ui) - // Toggle the debug overlay for UI. - .add_systems( - Update, - toggle_debug_ui.run_if(input_just_pressed(TOGGLE_KEY)), - ); -} - -const TOGGLE_KEY: KeyCode = KeyCode::Backquote; - -fn toggle_debug_ui(mut options: ResMut) { - options.toggle(); -} - -fn inspector_ui(world: &mut World) { - let Ok(egui_context) = world - .query_filtered::<&mut EguiContext, With>() - .get_single(world) - else { - return; - }; - - let mut egui_context = egui_context.clone(); - - egui::Window::new("UI").show(egui_context.get_mut(), |ui| { - ScrollArea::vertical().show(ui, |ui| { - bevy_inspector_egui::bevy_inspector::ui_for_world(world, ui); - }); - }); - - egui::Window::new("Maze Controls").show(egui_context.get_mut(), |ui| { - if let Some(mut maze_config) = world.get_resource_mut::() { - ui.heading("Maze Configuration"); - - // radius controls - ui.horizontal(|ui| { - ui.label("Radius:"); - ui.add( - DragValue::new(&mut maze_config.radius) - .speed(1) - .range(1..=100), - ); - }); - - // height controls - ui.horizontal(|ui| { - ui.label("Height:"); - ui.add( - DragValue::new(&mut maze_config.height) - .speed(0.5) - .range(1.0..=50.), - ); - }); - - // start position - ui.horizontal(|ui| { - ui.label("Start Position:"); - ui.add( - DragValue::new(&mut maze_config.start_pos.x) - .speed(1) - .prefix("x: "), - ); - ui.add( - DragValue::new(&mut maze_config.start_pos.y) - .speed(1) - .prefix("y: "), - ); - }); - - // end position - ui.horizontal(|ui| { - ui.label("End Position:"); - ui.add( - DragValue::new(&mut maze_config.end_pos.x) - .speed(1) - .prefix("x: "), - ); - ui.add( - DragValue::new(&mut maze_config.end_pos.y) - .speed(1) - .prefix("y: "), - ); - }); - - ui.add_space(8.); - - let button = Button::new("Recreate maze").fill(Color32::from_rgb(108, 108, 108)); - if ui.add(button).clicked() { - if let Some(mut event_writer) = - world.get_resource_mut::>() - { - event_writer.send(RecreateMazeEvent { floor: 1 }); - } - } - } - }); -} diff --git a/src/dev_tools/mod.rs b/src/dev_tools/mod.rs new file mode 100644 index 0000000..ad48bfc --- /dev/null +++ b/src/dev_tools/mod.rs @@ -0,0 +1,4 @@ +mod plugin; +mod ui; + +pub use plugin::DevToolsPlugin; diff --git a/src/dev_tools/plugin.rs b/src/dev_tools/plugin.rs new file mode 100644 index 0000000..660cf20 --- /dev/null +++ b/src/dev_tools/plugin.rs @@ -0,0 +1,36 @@ +use crate::screens::Screen; +use bevy::{ + dev_tools::{ + states::log_transitions, + ui_debug_overlay::{DebugUiPlugin, UiDebugOptions}, + }, + input::common_conditions::input_just_pressed, + prelude::*, +}; +use bevy_egui::EguiPlugin; +use bevy_inspector_egui::DefaultInspectorConfigPlugin; + +use super::ui::{inspector_ui, maze_controls_ui}; + +#[derive(Debug)] +pub struct DevToolsPlugin; + +impl Plugin for DevToolsPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Update, log_transitions::) + .add_plugins(EguiPlugin) + .add_plugins(DebugUiPlugin) + .add_plugins(DefaultInspectorConfigPlugin) + .add_systems(Update, (inspector_ui, maze_controls_ui)) + .add_systems( + Update, + toggle_debug_ui.run_if(input_just_pressed(TOGGLE_KEY)), + ); + } +} + +const TOGGLE_KEY: KeyCode = KeyCode::Backquote; + +fn toggle_debug_ui(mut options: ResMut) { + options.toggle(); +} diff --git a/src/dev_tools/ui/inspector.rs b/src/dev_tools/ui/inspector.rs new file mode 100644 index 0000000..04c8212 --- /dev/null +++ b/src/dev_tools/ui/inspector.rs @@ -0,0 +1,20 @@ +use bevy::{prelude::*, window::PrimaryWindow}; +use bevy_egui::egui::{self, ScrollArea}; +use bevy_inspector_egui::bevy_egui::EguiContext; + +pub(crate) fn inspector_ui(world: &mut World) { + let Ok(egui_context) = world + .query_filtered::<&mut EguiContext, With>() + .get_single(world) + else { + return; + }; + + let mut egui_context = egui_context.clone(); + + egui::Window::new("UI").show(egui_context.get_mut(), |ui| { + ScrollArea::vertical().show(ui, |ui| { + bevy_inspector_egui::bevy_inspector::ui_for_world(world, ui); + }); + }); +} diff --git a/src/dev_tools/ui/maze_controls.rs b/src/dev_tools/ui/maze_controls.rs new file mode 100644 index 0000000..f5b0a0a --- /dev/null +++ b/src/dev_tools/ui/maze_controls.rs @@ -0,0 +1,117 @@ +use std::ops::RangeInclusive; + +use bevy::{prelude::*, window::PrimaryWindow}; +use hexx::Hex; +use rand::{thread_rng, Rng}; + +use crate::maze::{events::RecreateMazeEvent, MazeConfig, MazePluginLoaded}; +use bevy_egui::{ + egui::{self, emath::Numeric, DragValue, TextEdit, Ui}, + EguiContext, +}; + +pub(crate) fn maze_controls_ui(world: &mut World) { + if world.get_resource::().is_none() { + return; + } + + let Ok(egui_context) = world + .query_filtered::<&mut EguiContext, With>() + .get_single(world) + else { + return; + }; + + let mut egui_context = egui_context.clone(); + + egui::Window::new("Maze Controls").show(egui_context.get_mut(), |ui| { + if let Some(mut maze_config) = world.get_resource_mut::() { + let mut changed = false; + ui.heading("Maze Configuration"); + + changed |= add_seed_control(ui, &mut maze_config.seed); + + changed |= add_drag_value_control(ui, "Radius:", &mut maze_config.radius, 1.0, 1..=100); + changed |= + add_drag_value_control(ui, "Height:", &mut maze_config.height, 0.5, 1.0..=50.0); + + changed |= add_position_control(ui, "Start Position:", &mut maze_config.start_pos); + changed |= add_position_control(ui, "End Position:", &mut maze_config.end_pos); + + // Trigger recreation if any value changed + if changed { + if let Some(mut event_writer) = + world.get_resource_mut::>() + { + event_writer.send(RecreateMazeEvent { floor: 1 }); + } + } + } + }); +} + +fn add_drag_value_control( + ui: &mut egui::Ui, + label: &str, + value: &mut T, + speed: f64, + range: RangeInclusive, +) -> bool { + let mut changed = false; + + ui.horizontal(|ui| { + ui.label(label); + let response = ui.add(DragValue::new(value).speed(speed).range(range)); + changed = response.changed(); + }); + changed +} + +fn add_position_control(ui: &mut Ui, label: &str, pos: &mut Hex) -> bool { + let mut changed = false; + + ui.horizontal(|ui| { + ui.label(label); + let response_x = ui.add(DragValue::new(&mut pos.x).speed(1).prefix("x: ")); + let response_y = ui.add(DragValue::new(&mut pos.y).speed(1).prefix("y: ")); + changed = response_x.changed() || response_y.changed(); + }); + changed +} + +fn add_seed_control(ui: &mut Ui, seed: &mut u64) -> bool { + let mut changed = false; + + ui.horizontal(|ui| { + ui.label("Seed:"); + + let mut seed_text = seed.to_string(); + + let response = ui.add( + TextEdit::singleline(&mut seed_text) + .desired_width(150.0) + .hint_text("Enter seed"), + ); + + // Parse text input when changed + if response.changed() { + if let Ok(new_seed) = seed_text.parse::() { + *seed = new_seed; + changed = true; + } + } + + // New random seed button + if ui.button("🎲").clicked() { + *seed = thread_rng().gen(); + changed = true; + } + + // Copy button + if ui.button("đź“‹").clicked() { + ui.output_mut(|o| o.copied_text = seed.to_string()); + } + }); + + changed +} diff --git a/src/dev_tools/ui/mod.rs b/src/dev_tools/ui/mod.rs new file mode 100644 index 0000000..6aca3ec --- /dev/null +++ b/src/dev_tools/ui/mod.rs @@ -0,0 +1,5 @@ +mod inspector; +mod maze_controls; + +pub(crate) use inspector::inspector_ui; +pub(crate) use maze_controls::maze_controls_ui; diff --git a/src/lib.rs b/src/lib.rs index 9c126f5..00564b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,7 +70,7 @@ impl Plugin for AppPlugin { // Enable dev tools for dev builds. #[cfg(feature = "dev")] - app.add_plugins(dev_tools::plugin); + app.add_plugins(dev_tools::DevToolsPlugin); } } diff --git a/src/maze/mod.rs b/src/maze/mod.rs index 26aec4f..56894da 100644 --- a/src/maze/mod.rs +++ b/src/maze/mod.rs @@ -7,8 +7,8 @@ pub mod plugin; mod resources; mod systems; -pub use resources::MazeConfig; +pub use resources::{MazeConfig, MazePluginLoaded}; -pub fn spawn_grid(world: &mut World) { +pub fn spawn_maze(world: &mut World) { MazePlugin.apply(world); } diff --git a/src/maze/plugin.rs b/src/maze/plugin.rs index d4ce8c2..2e24d7f 100644 --- a/src/maze/plugin.rs +++ b/src/maze/plugin.rs @@ -7,7 +7,7 @@ use super::{ events::RecreateMazeEvent, resources::Layout, systems::{self, recreation::handle_maze_recreation_event}, - MazeConfig, + MazeConfig, MazePluginLoaded, }; #[derive(Default)] @@ -24,6 +24,7 @@ impl Plugin for MazePlugin { impl Command for MazePlugin { fn apply(self, world: &mut World) { + world.insert_resource(MazePluginLoaded); world.run_system_once(systems::setup::setup); } } diff --git a/src/maze/resources.rs b/src/maze/resources.rs index 77bcb0d..7e7245a 100644 --- a/src/maze/resources.rs +++ b/src/maze/resources.rs @@ -5,6 +5,10 @@ use hexx::{Hex, HexLayout, HexOrientation}; use rand::{rngs::StdRng, thread_rng, Rng, SeedableRng}; use thiserror::Error; +#[derive(Debug, Default, Reflect, Resource)] +#[reflect(Resource)] +pub struct MazePluginLoaded; + pub(crate) const WALL_SIZE: f32 = 1.0; #[derive(Debug, Error)] pub enum MazeConfigError { diff --git a/src/screens/gameplay.rs b/src/screens/gameplay.rs index f932d17..3e35397 100644 --- a/src/screens/gameplay.rs +++ b/src/screens/gameplay.rs @@ -5,7 +5,7 @@ use bevy::{input::common_conditions::input_just_pressed, prelude::*}; #[cfg(feature = "demo")] use crate::demo::level::spawn_level as spawn_level_command; #[cfg(not(feature = "demo"))] -use crate::maze::spawn_grid as spawn_level_command; +use crate::maze::spawn_maze as spawn_level_command; use crate::{asset_tracking::LoadResource, audio::Music, screens::Screen}; pub(super) fn plugin(app: &mut App) { From 1a0a859feccb37526f07f4de4e5873ce7ab2c089 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sun, 8 Dec 2024 18:49:41 +0200 Subject: [PATCH 6/8] refactor(devt-tools): remove custom inspector --- src/dev_tools/plugin.rs | 8 ++++---- src/dev_tools/ui/inspector.rs | 20 -------------------- src/dev_tools/ui/mod.rs | 2 -- 3 files changed, 4 insertions(+), 26 deletions(-) delete mode 100644 src/dev_tools/ui/inspector.rs diff --git a/src/dev_tools/plugin.rs b/src/dev_tools/plugin.rs index 660cf20..f94886a 100644 --- a/src/dev_tools/plugin.rs +++ b/src/dev_tools/plugin.rs @@ -8,9 +8,9 @@ use bevy::{ prelude::*, }; use bevy_egui::EguiPlugin; -use bevy_inspector_egui::DefaultInspectorConfigPlugin; +use bevy_inspector_egui::quick::WorldInspectorPlugin; -use super::ui::{inspector_ui, maze_controls_ui}; +use super::ui::maze_controls_ui; #[derive(Debug)] pub struct DevToolsPlugin; @@ -19,9 +19,9 @@ impl Plugin for DevToolsPlugin { fn build(&self, app: &mut App) { app.add_systems(Update, log_transitions::) .add_plugins(EguiPlugin) + .add_plugins(WorldInspectorPlugin::new()) .add_plugins(DebugUiPlugin) - .add_plugins(DefaultInspectorConfigPlugin) - .add_systems(Update, (inspector_ui, maze_controls_ui)) + .add_systems(Update, maze_controls_ui) .add_systems( Update, toggle_debug_ui.run_if(input_just_pressed(TOGGLE_KEY)), diff --git a/src/dev_tools/ui/inspector.rs b/src/dev_tools/ui/inspector.rs deleted file mode 100644 index 04c8212..0000000 --- a/src/dev_tools/ui/inspector.rs +++ /dev/null @@ -1,20 +0,0 @@ -use bevy::{prelude::*, window::PrimaryWindow}; -use bevy_egui::egui::{self, ScrollArea}; -use bevy_inspector_egui::bevy_egui::EguiContext; - -pub(crate) fn inspector_ui(world: &mut World) { - let Ok(egui_context) = world - .query_filtered::<&mut EguiContext, With>() - .get_single(world) - else { - return; - }; - - let mut egui_context = egui_context.clone(); - - egui::Window::new("UI").show(egui_context.get_mut(), |ui| { - ScrollArea::vertical().show(ui, |ui| { - bevy_inspector_egui::bevy_inspector::ui_for_world(world, ui); - }); - }); -} diff --git a/src/dev_tools/ui/mod.rs b/src/dev_tools/ui/mod.rs index 6aca3ec..63c404f 100644 --- a/src/dev_tools/ui/mod.rs +++ b/src/dev_tools/ui/mod.rs @@ -1,5 +1,3 @@ -mod inspector; mod maze_controls; -pub(crate) use inspector::inspector_ui; pub(crate) use maze_controls::maze_controls_ui; From 8ef2db1d48928dcbe13eecbdf950d4c92336810e Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sun, 8 Dec 2024 19:30:58 +0200 Subject: [PATCH 7/8] feat(dev-tools): add maze orientation toggle --- src/dev_tools/ui/maze_controls.rs | 28 +++++++++++++++- src/maze/assets.rs | 47 ++++++++++++++++---------- src/maze/plugin.rs | 2 -- src/maze/resources.rs | 55 ++++++++++++++++++------------- src/maze/systems/recreation.rs | 7 ++-- src/maze/systems/setup.rs | 12 +++---- src/maze/systems/spawn.rs | 10 +++--- 7 files changed, 99 insertions(+), 62 deletions(-) diff --git a/src/dev_tools/ui/maze_controls.rs b/src/dev_tools/ui/maze_controls.rs index f5b0a0a..387fbdc 100644 --- a/src/dev_tools/ui/maze_controls.rs +++ b/src/dev_tools/ui/maze_controls.rs @@ -1,7 +1,7 @@ use std::ops::RangeInclusive; use bevy::{prelude::*, window::PrimaryWindow}; -use hexx::Hex; +use hexx::{Hex, HexOrientation}; use rand::{thread_rng, Rng}; use crate::maze::{events::RecreateMazeEvent, MazeConfig, MazePluginLoaded}; @@ -34,12 +34,22 @@ pub(crate) fn maze_controls_ui(world: &mut World) { changed |= add_drag_value_control(ui, "Radius:", &mut maze_config.radius, 1.0, 1..=100); changed |= add_drag_value_control(ui, "Height:", &mut maze_config.height, 0.5, 1.0..=50.0); + changed |= add_drag_value_control( + ui, + "Hex Size:", + &mut maze_config.hex_size, + 1.0, + 1.0..=100.0, + ); + + changed |= add_orientation_control(ui, &mut maze_config.layout.orientation); changed |= add_position_control(ui, "Start Position:", &mut maze_config.start_pos); changed |= add_position_control(ui, "End Position:", &mut maze_config.end_pos); // Trigger recreation if any value changed if changed { + maze_config.update(); if let Some(mut event_writer) = world.get_resource_mut::>() { @@ -115,3 +125,19 @@ fn add_seed_control(ui: &mut Ui, seed: &mut u64) -> bool { changed } + +fn add_orientation_control(ui: &mut Ui, orientation: &mut HexOrientation) -> bool { + let mut changed = false; + + ui.horizontal(|ui| { + ui.label("Orientation:"); + + let response = ui.radio_value(orientation, HexOrientation::Flat, "Flat"); + changed |= response.changed(); + + let response = ui.radio_value(orientation, HexOrientation::Pointy, "Pointy"); + changed |= response.changed(); + }); + + changed +} diff --git a/src/maze/assets.rs b/src/maze/assets.rs index 5a2d31d..3d3dba5 100644 --- a/src/maze/assets.rs +++ b/src/maze/assets.rs @@ -1,8 +1,10 @@ +use super::MazeConfig; +use bevy::prelude::*; use std::f32::consts::FRAC_PI_2; -use bevy::prelude::*; - -use super::{resources::WALL_SIZE, MazeConfig}; +const WALL_OVERLAP_MODIFIER: f32 = 1.25; +const HEX_SIDES: usize = 6; +const WHITE_EMISSION_INTENSITY: f32 = 10.; pub(crate) struct MazeAssets { pub(crate) hex_mesh: Handle, @@ -11,22 +13,27 @@ pub(crate) struct MazeAssets { pub(crate) wall_material: Handle, } -pub(crate) fn create_base_assets( - meshes: &mut ResMut>, - materials: &mut ResMut>, - config: &MazeConfig, -) -> MazeAssets { - MazeAssets { - hex_mesh: meshes.add(generate_hex_mesh(config.size, config.height)), - wall_mesh: meshes.add(generate_square_mesh(config.size)), - hex_material: materials.add(white_material()), - wall_material: materials.add(Color::BLACK), +impl MazeAssets { + pub(crate) fn new( + meshes: &mut ResMut>, + materials: &mut ResMut>, + config: &MazeConfig, + ) -> MazeAssets { + MazeAssets { + hex_mesh: meshes.add(generate_hex_mesh(config.hex_size, config.height)), + wall_mesh: meshes.add(generate_square_mesh( + config.hex_size + config.wall_size() / WALL_OVERLAP_MODIFIER, + config.wall_size(), + )), + hex_material: materials.add(white_material()), + wall_material: materials.add(Color::BLACK), + } } } fn generate_hex_mesh(radius: f32, depth: f32) -> Mesh { let hexagon = RegularPolygon { - sides: 6, + sides: HEX_SIDES, circumcircle: Circle::new(radius), }; let prism_shape = Extrusion::new(hexagon, depth); @@ -35,8 +42,8 @@ fn generate_hex_mesh(radius: f32, depth: f32) -> Mesh { Mesh::from(prism_shape).rotated_by(rotation) } -fn generate_square_mesh(depth: f32) -> Mesh { - let square = Rectangle::new(WALL_SIZE, WALL_SIZE); +fn generate_square_mesh(depth: f32, wall_size: f32) -> Mesh { + let square = Rectangle::new(wall_size, wall_size); let rectangular_prism = Extrusion::new(square, depth); let rotation = Quat::from_rotation_x(FRAC_PI_2); @@ -44,10 +51,14 @@ fn generate_square_mesh(depth: f32) -> Mesh { } fn white_material() -> StandardMaterial { - let val = 10.; StandardMaterial { base_color: Color::WHITE, - emissive: LinearRgba::new(val, val, val, val), + emissive: LinearRgba::new( + WHITE_EMISSION_INTENSITY, + WHITE_EMISSION_INTENSITY, + WHITE_EMISSION_INTENSITY, + WHITE_EMISSION_INTENSITY, + ), ..default() } } diff --git a/src/maze/plugin.rs b/src/maze/plugin.rs index 2e24d7f..cd60cba 100644 --- a/src/maze/plugin.rs +++ b/src/maze/plugin.rs @@ -5,7 +5,6 @@ use bevy::{ use super::{ events::RecreateMazeEvent, - resources::Layout, systems::{self, recreation::handle_maze_recreation_event}, MazeConfig, MazePluginLoaded, }; @@ -16,7 +15,6 @@ pub(crate) struct MazePlugin; impl Plugin for MazePlugin { fn build(&self, app: &mut App) { app.init_resource::() - .init_resource::() .add_event::() .add_systems(Update, handle_maze_recreation_event); } diff --git a/src/maze/resources.rs b/src/maze/resources.rs index 7e7245a..5c4dc60 100644 --- a/src/maze/resources.rs +++ b/src/maze/resources.rs @@ -9,7 +9,6 @@ use thiserror::Error; #[reflect(Resource)] pub struct MazePluginLoaded; -pub(crate) const WALL_SIZE: f32 = 1.0; #[derive(Debug, Error)] pub enum MazeConfigError { #[error("Failed to convert radius from u32 to i32: {0}")] @@ -21,17 +20,19 @@ pub enum MazeConfigError { pub struct MazeConfig { pub radius: u32, pub height: f32, - pub size: f32, + pub hex_size: f32, pub start_pos: Hex, pub end_pos: Hex, pub seed: u64, + pub layout: HexLayout, } impl MazeConfig { fn new( radius: u32, height: f32, - size: f32, + hex_size: f32, + orientation: HexOrientation, seed: Option, ) -> Result { let seed = seed.unwrap_or_else(|| thread_rng().gen()); @@ -43,40 +44,50 @@ impl MazeConfig { debug!("Start pos: ({},{})", start_pos.x, start_pos.y); debug!("End pos: ({},{})", end_pos.x, end_pos.y); + let layout = HexLayout { + orientation, + hex_size: Vec2::splat(hex_size), + ..default() + }; + Ok(Self { radius: radius as u32, height, - size, + hex_size, start_pos, end_pos, seed, + layout, }) } - pub fn new_unchecked(radius: u32, height: f32, hex_size: f32, seed: Option) -> Self { - Self::new(radius, height, hex_size, seed) + pub fn new_unchecked( + radius: u32, + height: f32, + hex_size: f32, + orientation: HexOrientation, + seed: Option, + ) -> Self { + Self::new(radius, height, hex_size, orientation, seed) .expect("Failed to create MazeConfig with supposedly safe values") } + + pub fn wall_size(&self) -> f32 { + self.hex_size / 6. + } + + pub fn wall_offset(&self) -> f32 { + self.hex_size - self.wall_size() + } + + pub fn update(&mut self) { + self.layout.hex_size = Vec2::splat(self.hex_size); + } } impl Default for MazeConfig { fn default() -> Self { - Self::new_unchecked(7, 20., 6., None) - } -} - -#[derive(Debug, Reflect, Resource, Deref, DerefMut, Clone)] -#[reflect(Resource)] -pub struct Layout(pub HexLayout); - -impl FromWorld for Layout { - fn from_world(world: &mut World) -> Self { - let config = world.resource::(); - Self(HexLayout { - orientation: HexOrientation::Flat, - hex_size: Vec2::splat(config.size), - ..default() - }) + Self::new_unchecked(7, 20., 6., HexOrientation::Flat, None) } } diff --git a/src/maze/systems/recreation.rs b/src/maze/systems/recreation.rs index cadd2cb..b3a6472 100644 --- a/src/maze/systems/recreation.rs +++ b/src/maze/systems/recreation.rs @@ -1,8 +1,6 @@ use bevy::prelude::*; -use crate::maze::{ - components::MazeFloor, events::RecreateMazeEvent, resources::Layout, MazeConfig, -}; +use crate::maze::{components::MazeFloor, events::RecreateMazeEvent, MazeConfig}; use super::setup::setup_maze; @@ -11,13 +9,12 @@ pub(crate) fn handle_maze_recreation_event( mut meshes: ResMut>, mut materials: ResMut>, config: Res, - layout: Res, query: Query<(Entity, &MazeFloor)>, mut event_reader: EventReader, ) { for event in event_reader.read() { despawn_floor(&mut commands, &query, event.floor); - setup_maze(&mut commands, &mut meshes, &mut materials, &config, &layout); + setup_maze(&mut commands, &mut meshes, &mut materials, &config); } } diff --git a/src/maze/systems/setup.rs b/src/maze/systems/setup.rs index 96556ad..58cae06 100644 --- a/src/maze/systems/setup.rs +++ b/src/maze/systems/setup.rs @@ -1,9 +1,7 @@ use bevy::prelude::*; use hexlab::{GeneratorType, MazeBuilder}; -use crate::maze::{ - assets::create_base_assets, components::MazeFloor, resources::Layout, MazeConfig, -}; +use crate::maze::{assets::MazeAssets, components::MazeFloor, MazeConfig}; use super::spawn::spawn_single_hex_tile; @@ -12,9 +10,8 @@ pub(crate) fn setup( mut meshes: ResMut>, mut materials: ResMut>, config: Res, - layout: Res, ) { - setup_maze(&mut commands, &mut meshes, &mut materials, &config, &layout); + setup_maze(&mut commands, &mut meshes, &mut materials, &config); } pub(super) fn setup_maze( @@ -22,7 +19,6 @@ pub(super) fn setup_maze( meshes: &mut ResMut>, materials: &mut ResMut>, config: &MazeConfig, - layout: &Layout, ) { let maze = MazeBuilder::new() .with_radius(config.radius) @@ -31,7 +27,7 @@ pub(super) fn setup_maze( .build() .expect("Something went wrong while creating maze"); - let assets = create_base_assets(meshes, materials, config); + let assets = MazeAssets::new(meshes, materials, config); commands .spawn(( Name::new("Floor"), @@ -43,7 +39,7 @@ pub(super) fn setup_maze( )) .with_children(|parent| { for tile in maze.values() { - spawn_single_hex_tile(parent, &assets, tile, &layout.0, &config) + spawn_single_hex_tile(parent, &assets, tile, &config) } }); } diff --git a/src/maze/systems/spawn.rs b/src/maze/systems/spawn.rs index ca6b8d8..838ae3d 100644 --- a/src/maze/systems/spawn.rs +++ b/src/maze/systems/spawn.rs @@ -7,7 +7,6 @@ use hexx::HexOrientation; use crate::maze::{ assets::MazeAssets, components::{MazeTile, MazeWall}, - resources::WALL_SIZE, MazeConfig, }; @@ -15,11 +14,10 @@ pub(super) fn spawn_single_hex_tile( parent: &mut ChildBuilder, assets: &MazeAssets, tile: &HexTile, - layout: &HexLayout, config: &MazeConfig, ) { - let world_pos = tile.to_vec3(layout); - let rotation = match layout.orientation { + let world_pos = tile.to_vec3(&config.layout); + let rotation = match config.layout.orientation { HexOrientation::Pointy => Quat::from_rotation_y(0.0), HexOrientation::Flat => Quat::from_rotation_y(FRAC_PI_6), // 30 degrees rotation }; @@ -49,8 +47,8 @@ fn spawn_walls(parent: &mut ChildBuilder, assets: &MazeAssets, config: &MazeConf let wall_angle = -FRAC_PI_3 * i as f32; - let x_offset = (config.size - WALL_SIZE) * f32::cos(wall_angle); - let z_offset = (config.size - WALL_SIZE) * f32::sin(wall_angle); + let x_offset = config.wall_offset() * f32::cos(wall_angle); + let z_offset = config.wall_offset() * f32::sin(wall_angle); let pos = Vec3::new(x_offset, y_offset, z_offset); let x_rotation = Quat::from_rotation_x(wall_angle + FRAC_PI_2); From dfb653898f4d8e4644cc2b8c008f4f4bd233ce17 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sun, 8 Dec 2024 19:37:07 +0200 Subject: [PATCH 8/8] chore: remove demo project --- Cargo.toml | 1 - QUICKSTART.md | 131 ---------------------------- src/demo/animation.rs | 177 -------------------------------------- src/demo/level.rs | 20 ----- src/demo/mod.rs | 20 ----- src/demo/movement.rs | 84 ------------------ src/demo/player.rs | 153 -------------------------------- src/lib.rs | 6 -- src/maze/resources.rs | 2 +- src/maze/systems/setup.rs | 2 +- src/maze/systems/spawn.rs | 4 +- src/screens/gameplay.rs | 3 - 12 files changed, 4 insertions(+), 599 deletions(-) delete mode 100644 QUICKSTART.md delete mode 100644 src/demo/animation.rs delete mode 100644 src/demo/level.rs delete mode 100644 src/demo/mod.rs delete mode 100644 src/demo/movement.rs delete mode 100644 src/demo/player.rs diff --git a/Cargo.toml b/Cargo.toml index 18a1a8b..f9ab26f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,6 @@ dev_native = [ # Enable embedded asset hot reloading for native dev builds. "bevy/embedded_watcher", ] -demo = [] # Idiomatic Bevy code often triggers these lints, and the CI workflow treats them as errors. diff --git a/QUICKSTART.md b/QUICKSTART.md deleted file mode 100644 index 5a656d9..0000000 --- a/QUICKSTART.md +++ /dev/null @@ -1,131 +0,0 @@ -_Brought to you by the Bevy Jam working group._ - -# Bevy Quickstart - -This template is a great way to get started on a new [Bevy](https://bevyengine.org/) game—especially for a game jam! -Start with a [basic project structure](#write-your-game) and [CI / CD](#release-your-game) that can deploy to [itch.io](https://itch.io). -You can [try this template in your web browser!](https://the-bevy-flock.itch.io/bevy-quickstart) - -[@ChristopherBiscardi](https://github.com/ChristopherBiscardi) made a video on how to use this template from start to finish: - -[A video tutorial for bevy_quickstart](https://www.youtube.com/watch?v=ESBRyXClaYc) - -## Prerequisites - -We assume that you know how to use Bevy already and have seen the [official Quick Start Guide](https://bevyengine.org/learn/quick-start/introduction/). - -If you're new to Bevy, the patterns used in this template may look a bit weird at first glance. -See our [Design Document](./docs/design.md) for more information on how we structured the code and why. - -## Create a new game - -Install [`cargo-generate`](https://github.com/cargo-generate/cargo-generate) and run the following command: - -```sh -cargo generate TheBevyFlock/bevy_quickstart --branch cargo-generate -``` - -Then navigate to the newly generated directory and run the following commands: - -```sh -git branch --move main -cargo update -git commit -am 'Initial commit' -``` - -Then [create a GitHub repository](https://github.com/new) and push your local repository to it. - -
- This template can also be set up manually. - -Navigate to the top of [this GitHub repository](https://github.com/TheBevyFlock/bevy_quickstart/) and select `Use this template > Create a new repository`: - -![UI demonstration](./docs/img/readme-manual-setup.png) - -Clone your new Github repository to a local repository and push a commit with the following changes: - -- Delete `LICENSE`, `README`, and `docs/` files. -- Search for and replace instances of `bevy_quickstart` with the name of your project. -- Adjust the `env` variables in [`.github/workflows/release.yaml`](./.github/workflows/release.yaml). - -
- -## Write your game - -The best way to get started is to play around with what you find in [`src/demo/`](./src/demo). - -This template comes with a basic project structure that you may find useful: - -| Path | Description | -| -------------------------------------------------- | ------------------------------------------------------------------ | -| [`src/lib.rs`](./src/lib.rs) | App setup | -| [`src/asset_tracking.rs`](./src/asset_tracking.rs) | A high-level way to load collections of asset handles as resources | -| [`src/audio/`](./src/audio) | Marker components for sound effects and music | -| [`src/demo/`](./src/demo) | Example game mechanics & content (replace with your own code) | -| [`src/dev_tools.rs`](./src/dev_tools.rs) | Dev tools for dev builds (press \` aka backtick to toggle) | -| [`src/screens/`](./src/screens) | Splash screen, title screen, gameplay screen, etc. | -| [`src/theme/`](./src/theme) | Reusable UI widgets & theming | - -Feel free to move things around however you want, though. - -> [!Tip] -> Be sure to check out the [3rd-party tools](./docs/tooling.md) we recommend! - -## Run your game - -Running your game locally is very simple: - -- Use `cargo run` to run a native dev build. -- Use [`trunk serve`](https://trunkrs.dev/) to run a web dev build. - -If you're using [VS Code](https://code.visualstudio.com/), this template comes with a [`.vscode/tasks.json`](./.vscode/tasks.json) file. - -
- Run release builds - -- Use `cargo run --profile release-native --no-default-features` to run a native release build. -- Use `trunk serve --release --no-default-features` to run a web release build. - -
- -
- Linux dependencies - -If you are using Linux, make sure you take a look at Bevy's [Linux dependencies](https://github.com/bevyengine/bevy/blob/main/docs/linux_dependencies.md). -Note that this template enables Wayland support, which requires additional dependencies as detailed in the link above. -Wayland is activated by using the `bevy/wayland` feature in the [`Cargo.toml`](./Cargo.toml). - -
- -
- (Optional) Improve your compile times - -[`.cargo/config_fast_builds.toml`](./.cargo/config_fast_builds.toml) contains documentation on how to set up your environment to improve compile times. -After you've fiddled with it, rename it to `.cargo/config.toml` to enable it. - -
- -## Release your game - -This template uses [GitHub workflows](https://docs.github.com/en/actions/using-workflows) to run tests and build releases. -See [Workflows](./docs/workflows.md) for more information. - -## Known Issues - -There are some known issues in Bevy that require some arcane workarounds. -To keep this template simple, we have opted not to include those workarounds. -You can read about them in the [Known Issues](./docs/known-issues.md) document. - -## License - -The source code in this repository is licensed under any of the following at your option: - -- [CC0-1.0 License](./LICENSE-CC0-1.0.txt) -- [MIT License](./LICENSE-MIT.txt) -- [Apache License, Version 2.0](./LICENSE-Apache-2.0.txt) - -The CC0 license explicitly does not waive patent rights, but we confirm that we hold no patent rights to anything presented in this repository. - -## Credits - -The [assets](./assets) in this repository are all 3rd-party. See the [credits screen](./src/screens/credits.rs) for more information. diff --git a/src/demo/animation.rs b/src/demo/animation.rs deleted file mode 100644 index fcdb7bb..0000000 --- a/src/demo/animation.rs +++ /dev/null @@ -1,177 +0,0 @@ -//! Player sprite animation. -//! This is based on multiple examples and may be very different for your game. -//! - [Sprite flipping](https://github.com/bevyengine/bevy/blob/latest/examples/2d/sprite_flipping.rs) -//! - [Sprite animation](https://github.com/bevyengine/bevy/blob/latest/examples/2d/sprite_animation.rs) -//! - [Timers](https://github.com/bevyengine/bevy/blob/latest/examples/time/timers.rs) - -use bevy::prelude::*; -use rand::prelude::*; -use std::time::Duration; - -use crate::{ - audio::SoundEffect, - demo::{movement::MovementController, player::PlayerAssets}, - AppSet, -}; - -pub(super) fn plugin(app: &mut App) { - // Animate and play sound effects based on controls. - app.register_type::(); - app.add_systems( - Update, - ( - update_animation_timer.in_set(AppSet::TickTimers), - ( - update_animation_movement, - update_animation_atlas, - trigger_step_sound_effect, - ) - .chain() - .run_if(resource_exists::) - .in_set(AppSet::Update), - ), - ); -} - -/// Update the sprite direction and animation state (idling/walking). -fn update_animation_movement( - mut player_query: Query<(&MovementController, &mut Sprite, &mut PlayerAnimation)>, -) { - for (controller, mut sprite, mut animation) in &mut player_query { - let dx = controller.intent.x; - if dx != 0.0 { - sprite.flip_x = dx < 0.0; - } - - let animation_state = if controller.intent == Vec2::ZERO { - PlayerAnimationState::Idling - } else { - PlayerAnimationState::Walking - }; - animation.update_state(animation_state); - } -} - -/// Update the animation timer. -fn update_animation_timer(time: Res