diff --git a/Cargo.lock b/Cargo.lock index 655ab40..8fcdca2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4870,6 +4870,7 @@ dependencies = [ "iyes_progress", "lazy_static", "rand", + "shared", "statig", "wasm-bindgen", "web-sys", diff --git a/assets/registry.json b/assets/registry.json index e847c2f..0894504 100644 --- a/assets/registry.json +++ b/assets/registry.json @@ -9127,47 +9127,7 @@ "type": "string", "typeInfo": "Enum" }, - "simulation::plugins::spectators::Spectator": { - "additionalProperties": false, - "isComponent": true, - "isResource": false, - "properties": {}, - "required": [], - "short_name": "Spectator", - "title": "simulation::plugins::spectators::Spectator", - "type": "object", - "typeInfo": "Struct" - }, - "smallvec::SmallVec<[bevy_ecs::Entity; 8]>": { - "isComponent": false, - "isResource": false, - "items": { - "type": { - "$ref": "#/$defs/bevy_ecs::Entity" - } - }, - "short_name": "SmallVec<[Entity; 8]>", - "title": "smallvec::SmallVec<[bevy_ecs::Entity; 8]>", - "type": "array", - "typeInfo": "List" - }, - "std::ffi::OsString": { - "isComponent": false, - "isResource": false, - "short_name": "OsString", - "title": "std::ffi::OsString", - "type": "object", - "typeInfo": "Value" - }, - "std::path::PathBuf": { - "isComponent": false, - "isResource": false, - "short_name": "PathBuf", - "title": "std::path::PathBuf", - "type": "object", - "typeInfo": "Value" - }, - "test::OrbitPoint": { + "simulation::plugins::planets::OrbitPoint": { "additionalProperties": false, "isComponent": true, "isResource": false, @@ -9188,22 +9148,41 @@ "point" ], "short_name": "OrbitPoint", - "title": "test::OrbitPoint", + "title": "simulation::plugins::planets::OrbitPoint", + "type": "object", + "typeInfo": "Struct" + }, + "simulation::plugins::planets::RotateSpeed": { + "additionalProperties": false, + "isComponent": true, + "isResource": false, + "properties": { + "speed": { + "type": { + "$ref": "#/$defs/f32" + } + } + }, + "required": [ + "speed" + ], + "short_name": "RotateSpeed", + "title": "simulation::plugins::planets::RotateSpeed", "type": "object", "typeInfo": "Struct" }, - "test::PreGameCamera": { + "simulation::plugins::scenes::pregame::PreGameCamera": { "additionalProperties": false, "isComponent": true, "isResource": false, "properties": {}, "required": [], "short_name": "PreGameCamera", - "title": "test::PreGameCamera", + "title": "simulation::plugins::scenes::pregame::PreGameCamera", "type": "object", "typeInfo": "Struct" }, - "test::PreGameSpawnPoint": { + "simulation::plugins::scenes::pregame::PreGameSpawnPoint": { "additionalProperties": false, "isComponent": true, "isResource": false, @@ -9218,11 +9197,11 @@ "id" ], "short_name": "PreGameSpawnPoint", - "title": "test::PreGameSpawnPoint", + "title": "simulation::plugins::scenes::pregame::PreGameSpawnPoint", "type": "object", "typeInfo": "Struct" }, - "test::RaceSpawnPoint": { + "simulation::plugins::scenes::race::RaceSpawnPoint": { "additionalProperties": false, "isComponent": true, "isResource": false, @@ -9237,39 +9216,60 @@ "id" ], "short_name": "RaceSpawnPoint", - "title": "test::RaceSpawnPoint", + "title": "simulation::plugins::scenes::race::RaceSpawnPoint", "type": "object", "typeInfo": "Struct" }, - "test::RaceStartCamera": { + "simulation::plugins::scenes::race::RaceStartCamera": { "additionalProperties": false, "isComponent": true, "isResource": false, "properties": {}, "required": [], "short_name": "RaceStartCamera", - "title": "test::RaceStartCamera", + "title": "simulation::plugins::scenes::race::RaceStartCamera", "type": "object", "typeInfo": "Struct" }, - "test::RotateSpeed": { + "simulation::plugins::spectators::Spectator": { "additionalProperties": false, "isComponent": true, "isResource": false, - "properties": { - "speed": { - "type": { - "$ref": "#/$defs/f32" - } + "properties": {}, + "required": [], + "short_name": "Spectator", + "title": "simulation::plugins::spectators::Spectator", + "type": "object", + "typeInfo": "Struct" + }, + "smallvec::SmallVec<[bevy_ecs::Entity; 8]>": { + "isComponent": false, + "isResource": false, + "items": { + "type": { + "$ref": "#/$defs/bevy_ecs::Entity" } }, - "required": [ - "speed" - ], - "short_name": "RotateSpeed", - "title": "test::RotateSpeed", + "short_name": "SmallVec<[Entity; 8]>", + "title": "smallvec::SmallVec<[bevy_ecs::Entity; 8]>", + "type": "array", + "typeInfo": "List" + }, + "std::ffi::OsString": { + "isComponent": false, + "isResource": false, + "short_name": "OsString", + "title": "std::ffi::OsString", "type": "object", - "typeInfo": "Struct" + "typeInfo": "Value" + }, + "std::path::PathBuf": { + "isComponent": false, + "isResource": false, + "short_name": "PathBuf", + "title": "std::path::PathBuf", + "type": "object", + "typeInfo": "Value" }, "u128": { "isComponent": false, diff --git a/shared/src/models/monsters.rs b/shared/src/models/monsters.rs index 2af5b76..7d738cd 100644 --- a/shared/src/models/monsters.rs +++ b/shared/src/models/monsters.rs @@ -126,12 +126,9 @@ pub fn race(monsters: &[&Monster; 3], seed: u32) -> Results { #[cfg(test)] mod test { - use std::collections::HashMap; - use super::{race, Monster, MONSTERS}; + use super::{race, MONSTERS}; use quickcheck_macros::quickcheck; - use rand::{thread_rng, RngCore}; - use uuid::Uuid; #[quickcheck] pub fn same_outcome_for_same_seed(seed: u32) -> bool { @@ -140,3 +137,4 @@ mod test { race(monsters, seed) == race(monsters, seed) } } + diff --git a/simulation/Cargo.toml b/simulation/Cargo.toml index 478111c..eb8c6f2 100644 --- a/simulation/Cargo.toml +++ b/simulation/Cargo.toml @@ -3,9 +3,6 @@ name = "simulation" version = "0.1.0" edition = "2021" -[[bin]] -name = "test" -path = "src/bin/test.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -24,6 +21,8 @@ rand = "0.8.5" statig = { version = "0.3.1", features = ["bevy"] } wasm-bindgen = "0.2.91" web-sys = "0.3.68" +shared = { workspace = true } + [features] default = ["bevy/dynamic_linking"] diff --git a/simulation/assets/Scene.glb b/simulation/assets/Scene.glb index 3cec865..e4e64c0 100644 Binary files a/simulation/assets/Scene.glb and b/simulation/assets/Scene.glb differ diff --git a/simulation/assets/library/Pregame_Spawn_Point.glb b/simulation/assets/library/Pregame_Spawn_Point.glb deleted file mode 100644 index d38c62e..0000000 Binary files a/simulation/assets/library/Pregame_Spawn_Point.glb and /dev/null differ diff --git a/simulation/assets/library/Race_Spawn_Point.glb b/simulation/assets/library/Race_Spawn_Point.glb deleted file mode 100644 index e3b7b16..0000000 Binary files a/simulation/assets/library/Race_Spawn_Point.glb and /dev/null differ diff --git a/simulation/assets/library/Spectator.glb b/simulation/assets/library/Spectator.glb index ceb0b8e..35a324f 100644 Binary files a/simulation/assets/library/Spectator.glb and b/simulation/assets/library/Spectator.glb differ diff --git a/simulation/game.blend b/simulation/game.blend index 1824922..a8f8f62 100644 Binary files a/simulation/game.blend and b/simulation/game.blend differ diff --git a/simulation/src/bin/debug.rs b/simulation/src/bin/debug.rs new file mode 100644 index 0000000..c93cf0c --- /dev/null +++ b/simulation/src/bin/debug.rs @@ -0,0 +1,11 @@ +use bevy_inspector_egui::quick::WorldInspectorPlugin; +use bevy_registry_export::*; +use simulation::start; + +fn main() { + start(|app| { + app.add_plugins(ExportRegistryPlugin::default()) + .add_plugins(WorldInspectorPlugin::default()); + }); +} + diff --git a/simulation/src/bin/simulation.rs b/simulation/src/bin/simulation.rs index a4021b5..2d28a40 100644 --- a/simulation/src/bin/simulation.rs +++ b/simulation/src/bin/simulation.rs @@ -1,43 +1,6 @@ -use std::f32::consts::PI; - -use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*}; use simulation::start; fn main() { - start(|app| { - app.add_systems(Startup, setup); - }); + start(|_| {}); } -fn setup( - mut commands: Commands, - mut meshes: ResMut>, - mut materials: ResMut>, -) { - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(5.0, 9.0, 8.0) - .looking_at(Vec3::new(0.0, 0.0, -5.0), Vec3::Y), - ..default() - }); - - commands.spawn(PbrBundle { - mesh: meshes.add(shape::Plane::from_size(10000.0).into()), - material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), - ..default() - }); - - commands.spawn(DirectionalLightBundle { - transform: Transform::from_rotation(Quat::from_euler(EulerRot::ZYX, 0.0, 1.0, -PI / 4.)), - directional_light: DirectionalLight { - shadows_enabled: true, - ..default() - }, - cascade_shadow_config: CascadeShadowConfigBuilder { - first_cascade_far_bound: 20.0, - maximum_distance: 40.0, - ..default() - } - .into(), - ..default() - }); -} diff --git a/simulation/src/bin/test.rs b/simulation/src/bin/test.rs deleted file mode 100644 index 751db9b..0000000 --- a/simulation/src/bin/test.rs +++ /dev/null @@ -1,177 +0,0 @@ -use bevy::{gltf::Gltf, pbr::CascadeShadowConfigBuilder, prelude::*, utils::HashMap}; -use bevy_asset_loader::prelude::*; -use bevy_gltf_blueprints::{BluePrintBundle, BlueprintName, GltfBlueprintsSet}; -use bevy_registry_export::*; -use simulation::{ - plugins::monster::{MonsterBundle, Speed, Stats}, - start, -}; - -#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, States)] -enum SceneState { - #[default] - Loading, - Loaded, -} - -fn main() { - start(|app| { - app.register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .add_plugins(bevy_gltf_blueprints::BlueprintsPlugin { - library_folder: "library".into(), - material_library: false, - legacy_mode: false, - ..Default::default() - }) - .insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.0))) - .add_state::() - .add_loading_state( - LoadingState::new(SceneState::Loading) - .continue_to_state(SceneState::Loaded) - .load_collection::(), - ) - .add_plugins(ExportRegistryPlugin::default()) - .add_systems(OnEnter(SceneState::Loaded), setup) - .add_plugins(bevy_inspector_egui::quick::WorldInspectorPlugin::default()) - .add_systems(Update, rotate) - .add_systems(Update, orbit) - .add_systems(Update, find_spawn.in_set(GltfBlueprintsSet::AfterSpawn)); - }); -} - -#[derive(AssetCollection, Resource)] -struct Scene { - #[asset(path = "Scene.glb")] - world: Handle, - - #[asset(path = "library", collection(typed, mapped))] - models: HashMap>, - // #[asset(path = "materials", collection(typed))] - // materials: Vec>, -} - -#[derive(Debug, Component, Reflect, Default)] -#[reflect(Component)] -pub struct RotateSpeed { - pub speed: f32, -} - -#[derive(Debug, Component, Reflect, Default)] -#[reflect(Component)] -pub struct OrbitPoint { - pub velocity: f32, - pub point: Vec3, -} - -#[derive(Debug, Component, Reflect, Default)] -#[reflect(Component)] -pub struct RaceSpawnPoint { - pub id: u32, -} - -#[derive(Debug, Component, Reflect, Default)] -#[reflect(Component)] -pub struct PreGameSpawnPoint { - pub id: u32, -} - -fn find_spawn( - mut commands: Commands, - query: Query<(&RaceSpawnPoint, &Transform), Added>, -) { - for (spawn_point, transform) in &query { - if spawn_point.id == 0 { - continue; - } - - println!( - "Found race spawn point {:?} at {:?}", - spawn_point, transform - ); - - let mut name = "Monster_Alien"; - - if spawn_point.id == 2 { - name = "Monster_Chicken"; - } - - if spawn_point.id == 3 { - name = "Monster_Mushnub"; - } - - commands.spawn(( - BluePrintBundle { - blueprint: BlueprintName(name.into()), - ..default() - }, - MonsterBundle { - speed: Speed(1.0), - stats: Stats { recovery_time: 2.0 }, - ..default() - }, - *transform, - )); - } -} - -fn setup( - mut commands: Commands, - game_assets: Res, - models: Res>, - mut ambient_light: ResMut, -) { - ambient_light.brightness = 0.075; - - commands.spawn(DirectionalLightBundle { - transform: Transform::from_rotation(Quat::from_euler(EulerRot::XYZ, -0.6, 0.9, 0.0)), - directional_light: DirectionalLight { - illuminance: 75000.0, - shadows_enabled: true, - ..default() - }, - cascade_shadow_config: CascadeShadowConfigBuilder { - maximum_distance: 40.0, - ..default() - } - .into(), - ..default() - }); - - commands.spawn(SceneBundle { - scene: models - .get(game_assets.world.id()) - .expect("main level should have been loaded") - .scenes[0] - .clone(), - ..default() - }); -} - -pub fn rotate(mut query: Query<(&mut Transform, &RotateSpeed)>, time: Res