1use crate::prelude::*;
2use bevy::prelude::*;
3use std::marker::PhantomData;
4
5#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
7pub enum Context {
8 Global,
10 User,
12 #[default]
14 Slot,
15}
16
17#[derive(Event, Debug, Clone)]
20pub struct SaveRequest<T>
21where
22 T: SaveData,
23{
24 pub(crate) sub_directory: Option<String>,
26 pub(crate) file_name: String,
28 pub(crate) save_data: T,
30 pub(crate) context: Context,
32}
33
34impl<T> SaveRequest<T>
35where
36 T: SaveData,
37{
38 pub fn new(file_name: &str, save_data: T) -> Self {
40 Self {
41 save_data,
42 file_name: file_name.to_string(),
43 sub_directory: None,
44 context: Context::Slot,
45 }
46 }
47
48 pub fn with_sub_directory(mut self, sub_directory: &str) -> Self {
50 self.sub_directory = Some(sub_directory.replace(|c: char| !c.is_ascii(), "_"));
51 self
52 }
53
54 pub fn with_context(mut self, context: Context) -> Self {
56 self.context = context;
57 self
58 }
59}
60
61#[derive(Event, Debug, Clone)]
64pub struct LoadRequest<T>
65where
66 T: SaveData,
67{
68 pub(crate) sub_directory: Option<String>,
70 pub(crate) file_name: String,
72 pub(crate) context: Context,
74 marker: PhantomData<T>,
76}
77
78impl<T> LoadRequest<T>
79where
80 T: SaveData,
81{
82 pub fn new(file_name: &str) -> Self {
84 Self {
85 sub_directory: None,
86 context: Context::Slot,
87 file_name: file_name.to_string(),
88 marker: PhantomData,
89 }
90 }
91
92 pub fn with_sub_directory(mut self, sub_directory: &str) -> Self {
94 self.sub_directory = Some(sub_directory.replace(|c: char| !c.is_ascii(), "_"));
95 self
96 }
97
98 pub fn with_context(mut self, context: Context) -> Self {
100 self.context = context;
101 self
102 }
103}
104
105#[derive(Event, Debug, Clone)]
107pub struct LoadComplete<T>
108where
109 T: SaveData,
110{
111 pub outcome: LoadOutcome,
113 pub file_name: String,
115 pub(crate) _marker: PhantomData<T>,
116}
117
118#[derive(Event, Debug, Clone)]
120pub struct SaveComplete<T>
121where
122 T: SaveData,
123{
124 pub outcome: SaveOutcome,
126 pub file_name: String,
128 pub(crate) _marker: PhantomData<T>,
129}