use bevy::prelude::*; use crate::{nature, settings, actor, audio, hud}; const MIN_INTERACT_DISTANCE: f32 = 30.0; const ASSET_CONVERSATIONS: &str = "scenes/conversations.scn.ron"; pub struct ActorPlugin; impl Plugin for ActorPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, setup); app.register_type::(); app.register_type::(); app.add_systems(FixedUpdate, update); app.add_systems(Update, ( handle_new_conversations, handle_conversations, handle_input, )); app.add_event::(); } } #[derive(Event)] pub struct StartConversationEvent { pub conv: String } #[derive(Component)] pub struct Actor { pub hp: f32, pub m: f32, // mass pub v: Vec3, // velocity // TODO: rotation } impl Default for Actor { fn default() -> Self { Self { hp: 100.0, m: 100.0, v: Vec3::ZERO, } } } #[derive(Component)] pub struct Player; #[derive(Component)] pub struct PlayerInConversation; #[derive(Component)] pub struct InConversationWithPlayer; #[derive(Component, Reflect, Default)] #[reflect(Component)] pub struct ChatBranch { pub id: String, pub name: String, pub label: String, pub delay: f64, pub sound: String, pub reply: String, pub goto: String, } #[derive(Component, Reflect, Default)] #[reflect(Component)] pub struct ChatChoice { pub id: String, pub label: String, pub choice: String, pub goto: String, } #[derive(Component)] pub struct Chat { pub id: String, pub label: String, pub timer: f64, } #[derive(Component)] pub struct Talker { pub conv: String, } #[derive(Component)] pub struct LifeForm { pub adrenaline: f32, pub adrenaline_baseline: f32, pub adrenaline_jolt: f32, } impl Default for LifeForm { fn default() -> Self { Self { adrenaline: 0.3, adrenaline_baseline: 0.3, adrenaline_jolt: 0.0, }}} #[derive(Component)] pub struct Suit { pub oxygen: f32, pub power: f32, pub oxygen_max: f32, pub power_max: f32, } impl Default for Suit { fn default() -> Self { SUIT_SIMPLE } } const SUIT_SIMPLE: Suit = Suit { power: 1e5, power_max: 1e5, oxygen: nature::OXY_D, oxygen_max: nature::OXY_D, }; pub fn setup( mut commands: Commands, asset_server: Res, ) { commands.spawn(DynamicSceneBundle { scene: asset_server.load(ASSET_CONVERSATIONS), ..default() }); } //#[allow(dead_code)] //pub fn serialize( // world: &mut World, //) { // let mut scene_world = World::new(); // scene_world.spawn(ChatBranch { // id: "hialien".to_string(), // name: "Icarus".to_string(), // label: "INTERACT".to_string(), // delay: 0.0, // reply: "Requesting permission to communicate...".to_string(), // goto: "requested".to_string(), // }); // let type_registry = world.resource::().clone(); // scene_world.insert_resource(type_registry); // let type_registry = world.resource::(); // let scene = DynamicScene::from_world(&scene_world); // let serialized_scene = scene.serialize_ron(type_registry).unwrap(); // info!("{}", serialized_scene); //} pub fn update( time: Res