1pub mod oudiasecond;
2pub mod qetrc;
3pub mod write;
4
5use bevy::prelude::*;
6
7pub struct RwDataPlugin;
8
9impl Plugin for RwDataPlugin {
10 fn build(&self, app: &mut App) {
11 app.add_message::<ModifyData>().add_systems(
12 FixedUpdate,
13 (clear_resources, qetrc::load_qetrc, oudiasecond::load_oud2)
14 .chain()
15 .run_if(on_message::<ModifyData>),
16 );
17 }
18}
19
20#[derive(Message)]
21pub enum ModifyData {
22 ClearAllData,
23 LoadQETRC(String),
24 LoadOuDiaSecond(String),
25}
26
27fn clear_resources(
28 mut commands: Commands,
29 mut reader: MessageReader<ModifyData>,
30 vehicles: Query<Entity, With<crate::vehicles::Vehicle>>,
31 intervals: Query<Entity, With<crate::intervals::Interval>>,
32 stations: Query<Entity, With<crate::intervals::Station>>,
33) {
34 let mut delete = false;
35 for modification in reader.read() {
36 if let ModifyData::ClearAllData = modification {
37 delete = true;
38 }
39 }
40 if !delete {
41 return;
42 }
43 for vehicle in vehicles.iter() {
44 commands.entity(vehicle).despawn_children().despawn();
45 }
46 for interval in intervals.iter() {
47 commands.entity(interval).despawn_children().despawn();
48 }
49 for station in stations.iter() {
50 commands.entity(station).despawn_children().despawn();
51 }
52 info!("Cleared all data from the application.");
53}
54
55fn load_online_data() {
56 todo!("Finish this fucking mess")
57}