Skip to content

Commit

Permalink
Removed blenvy from workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanRJohnston committed Jul 19, 2024
1 parent a2ff00a commit 43745c9
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 45 deletions.
2 changes: 1 addition & 1 deletion simulation/src/plugins/animation_link.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{hash::Hash, ops::Deref};
use std::ops::Deref;

use bevy::{prelude::*, utils::HashMap};

Expand Down
2 changes: 1 addition & 1 deletion simulation/src/plugins/event_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn scene_manager(events: Res<Events>, mut next_state: ResMut<NextState<SceneStat

for event in events.0.iter() {
match event {
Event::GameCreated { game_id } => next_state.set(SceneState::Lobby),
Event::GameCreated { .. } => next_state.set(SceneState::Lobby),
Event::GameStarted => next_state.set(SceneState::Lobby),
Event::RaceStarted => next_state.set(SceneState::Lobby),
Event::RaceFinished(_) => next_state.set(SceneState::Lobby),
Expand Down
49 changes: 48 additions & 1 deletion simulation/src/plugins/planets.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use bevy::prelude::*;

use super::scenes::SceneMetadata;

pub struct PlanetsPlugin;

impl Plugin for PlanetsPlugin {
fn build(&self, app: &mut App) {
app.register_type::<RotateSpeed>()
.register_type::<OrbitPoint>()
.add_systems(Update, rotate)
.add_systems(Update, orbit);
.add_systems(Update, orbit)
.add_systems(Update, add_components_on_scene_load);
}
}

Expand Down Expand Up @@ -39,3 +42,47 @@ pub fn orbit(mut query: Query<(&mut Transform, &OrbitPoint)>, time: Res<Time>) {
}
}

pub fn add_components_on_scene_load(
query: Query<(Entity, &SceneMetadata), Added<SceneMetadata>>,
named_entities: Query<(&Name, &Transform)>,
mut commands: Commands,
) {
for (entity, metadata) in &query {
if let Some(value) = metadata.0.get("RotateSpeed") {
match value {
serde_json::Value::Number(n) if n.is_f64() => {
commands.entity(entity).insert(RotateSpeed {
speed: n.as_f64().unwrap() as f32,
});
}
other => panic!("RotateSpeed must be a f64, got {:?}", other),
}
}

if let (Some(name), Some(speed)) =
(metadata.0.get("OrbitAround"), metadata.0.get("OrbitSpeed"))
{
let name = match name {
serde_json::Value::String(s) => s.clone(),
other => panic!("OrbitAround must be a string, got {:?}", other),
};

let speed = match speed {
serde_json::Value::Number(n) if n.is_f64() => n.as_f64().unwrap() as f32,
other => panic!("OrbitSpeed must be a f64, got {:?}", other),
};

// Linear traversal of all entities, but there aren't that many... for now
let planet = named_entities
.into_iter()
.find(|(planet_name, _)| planet_name.as_str() == name)
.ok_or("failed to find planet to orbit around")
.unwrap();

commands.entity(entity).insert(OrbitPoint {
velocity: speed,
point: planet.1.translation,
});
}
}
}
64 changes: 25 additions & 39 deletions simulation/src/plugins/scenes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use std::error::Error;

use bevy::{
core_pipeline::{bloom::BloomSettings, tonemapping::Tonemapping, Skybox},
gltf::{Gltf, GltfMaterialExtras, GltfMesh, GltfMeshExtras, GltfSceneExtras},
gltf::Gltf,
pbr::{CascadeShadowConfig, CascadeShadowConfigBuilder},
prelude::*,
render::camera::Exposure,
utils::HashMap,
};
use bevy_asset_loader::prelude::*;

use crate::plugins::spectators::{Spectator, SpectatorBundle};

use self::{lobby::LobbyPlugin, pregame::PreGamePlugin, race::RacePlugin};

pub mod lobby;
Expand Down Expand Up @@ -51,38 +47,7 @@ impl Plugin for ScenesPlugin {
)
.add_systems(OnEnter(SceneState::Spawning), scene_setup)
.add_systems(OnEnter(SceneState::Lobby), setup_skybox)
.add_systems(
Update,
|query: Query<(Entity, &Name, &GltfExtras), Added<GltfExtras>>,
mut commands: Commands| {
query.into_iter().for_each(|(entity, name, extras)| {
println!("{}: {}", name, extras.value);

match serde_json::from_str::<serde_json::Map<String, serde_json::Value>>(
&extras.value,
) {
Ok(metadata) => {
commands.entity(entity).insert(SceneMetadata(metadata));
}
Err(e) => {
println!(
"warning failed to deserialise gtlf metadata, {}: {}",
name, extras.value
);
}
}

// if let Some(value) = metadata.get("RaceSpawnPoint") {
// match value {
// serde_json::Value::Number(n) if n.is_u64() => {}
// other => {
// Err(format!("unsupported RaceSpawnPoint value: {other:?}"))?
// }
// }
// }
});
},
);
.add_systems(Update, deserialize_gltf_extras);
}
}

Expand Down Expand Up @@ -147,12 +112,12 @@ fn setup_skybox(
commands.entity(id).insert((
Skybox {
image: game_assets.skybox.clone(),
brightness: 1000.0,
brightness: 2000.0,
},
EnvironmentMapLight {
diffuse_map: game_assets.envmap_diffuse.clone(),
specular_map: game_assets.envmap_specular.clone(),
intensity: 1000.0,
intensity: 1500.0,
},
bloom,
Tonemapping::AcesFitted,
Expand Down Expand Up @@ -187,3 +152,24 @@ fn setup_skybox(
}
}
}

fn deserialize_gltf_extras(
query: Query<(Entity, &Name, &GltfExtras), Added<GltfExtras>>,
mut commands: Commands,
) {
query.into_iter().for_each(|(entity, name, extras)| {
println!("{}: {}", name, extras.value);

match serde_json::from_str::<serde_json::Map<String, serde_json::Value>>(&extras.value) {
Ok(metadata) => {
commands.entity(entity).insert(SceneMetadata(metadata));
}
Err(_) => {
println!(
"warning failed to deserialise gtlf metadata, {}: {}",
name, extras.value
);
}
}
});
}
26 changes: 25 additions & 1 deletion simulation/src/plugins/scenes/pregame.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use bevy::prelude::*;

use super::SceneMetadata;

pub struct PreGamePlugin;

impl Plugin for PreGamePlugin {
fn build(&self, app: &mut App) {
app.register_type::<PreGameSpawnPoint>()
.register_type::<PreGameCamera>();
.register_type::<PreGameCamera>()
.add_systems(Update, spawn_pregame_spawn_point_on_scene_load);
}
}

Expand All @@ -19,3 +22,24 @@ pub struct PreGameSpawnPoint {
#[reflect(Component)]
pub struct PreGameCamera;

pub fn spawn_pregame_spawn_point_on_scene_load(
query: Query<(Entity, &SceneMetadata), Added<SceneMetadata>>,
mut commands: Commands,
) {
for (entity, metadata) in &query {
if let Some(value) = metadata.0.get("PreGameSpawnPoint") {
match value {
serde_json::Value::Number(n) if n.is_u64() => {
commands.entity(entity).insert(PreGameSpawnPoint {
id: n.as_u64().unwrap() as u32,
});
}
other => panic!("PreGameSpawnPoint must be a number, got {:?}", other),
}
}

if metadata.0.get("PreGameCamera").is_some() {
commands.entity(entity).insert(PreGameCamera);
}
}
}
26 changes: 25 additions & 1 deletion simulation/src/plugins/scenes/race.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use bevy::prelude::*;

use super::SceneMetadata;

pub struct RacePlugin;

impl Plugin for RacePlugin {
fn build(&self, app: &mut App) {
app.register_type::<RaceSpawnPoint>()
.register_type::<RaceStartCamera>();
.register_type::<RaceStartCamera>()
.add_systems(Update, spawn_race_spawn_point_on_scene_load);
}
}

Expand All @@ -19,3 +22,24 @@ pub struct RaceSpawnPoint {
#[reflect(Component)]
pub struct RaceStartCamera;

pub fn spawn_race_spawn_point_on_scene_load(
query: Query<(Entity, &SceneMetadata), Added<SceneMetadata>>,
mut commands: Commands,
) {
for (entity, metadata) in &query {
if let Some(value) = metadata.0.get("RaceSpawnPoint") {
match value {
serde_json::Value::Number(n) if n.is_u64() => {
commands.entity(entity).insert(RaceSpawnPoint {
id: n.as_u64().unwrap() as u32,
});
}
other => panic!("RaceSpawnPoint must be a number, got {:?}", other),
}
}

if metadata.0.get("RaceStartCamera").is_some() {
commands.entity(entity).insert(RaceStartCamera);
}
}
}
4 changes: 3 additions & 1 deletion simulation/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use crate::plugins::{
event_stream::EventStreamPlugin,
monster::MonsterPlugin,
planets::PlanetsPlugin,
scenes::{SceneState, ScenesPlugin},
scenes::{
SceneState, ScenesPlugin,
},
skinned_mesh::SkinnedMeshPlugin,
spectators::SpectatorPlugin,
};
Expand Down

0 comments on commit 43745c9

Please sign in to comment.