@@ -53,7 +53,11 @@ pub fn with_handler_system_state<
53
53
///
54
54
/// This is useful for interacting with scripts, since [`WithWorldGuard`] will ensure scripts cannot gain exclusive access to the world if *any* reads or writes
55
55
/// are claimed on the world. Removing the resource from the world lets you access it in the context of running scripts without blocking exclusive world access.
56
- pub struct ResScope < ' state , T : Resource + Default > ( pub & ' state mut T ) ;
56
+ ///
57
+ /// # Safety
58
+ /// - Because the resource is removed during the `get_param` call, if there is a conflicting resource access, this will be unsafe
59
+ /// - You must ensure you're only using this in combination with system parameters which will not read or write to this resource in `get_param`
60
+ pub ( crate ) struct ResScope < ' state , T : Resource + Default > ( pub & ' state mut T ) ;
57
61
58
62
impl < T : Resource + Default > Deref for ResScope < ' _ , T > {
59
63
type Target = T ;
@@ -108,8 +112,12 @@ unsafe impl<T: Resource + Default> SystemParam for ResScope<'_, T> {
108
112
}
109
113
110
114
/// A version of [`bevy::ecs::event::EventReader`] which behaves just like [`ResScope`].
115
+ ///
116
+ /// # Safety
117
+ /// - unsafe to use this in a way which violates the invariants on [`ResScope`].
111
118
#[ derive( SystemParam ) ]
112
- pub struct EventReaderScope < ' s , T : Event > {
119
+ #[ doc( hidden) ]
120
+ pub ( crate ) struct EventReaderScope < ' s , T : Event > {
113
121
events : ResScope < ' s , Events < T > > ,
114
122
reader : Local < ' s , EventCursor < T > > ,
115
123
}
@@ -125,20 +133,50 @@ impl<T: Event> EventReaderScope<'_, T> {
125
133
#[ derive( SystemParam ) ]
126
134
pub struct HandlerContext < ' s , P : IntoScriptPluginParams > {
127
135
/// Settings for callbacks
128
- pub callback_settings : ResScope < ' s , CallbackSettings < P > > ,
136
+ pub ( crate ) callback_settings : ResScope < ' s , CallbackSettings < P > > ,
129
137
/// Settings for loading contexts
130
- pub context_loading_settings : ResScope < ' s , ContextLoadingSettings < P > > ,
138
+ pub ( crate ) context_loading_settings : ResScope < ' s , ContextLoadingSettings < P > > ,
131
139
/// Scripts
132
- pub scripts : ResScope < ' s , Scripts > ,
140
+ pub ( crate ) scripts : ResScope < ' s , Scripts > ,
133
141
/// The runtime container
134
- pub runtime_container : ResScope < ' s , RuntimeContainer < P > > ,
142
+ pub ( crate ) runtime_container : ResScope < ' s , RuntimeContainer < P > > ,
135
143
/// The script contexts
136
- pub script_contexts : ResScope < ' s , ScriptContexts < P > > ,
144
+ pub ( crate ) script_contexts : ResScope < ' s , ScriptContexts < P > > ,
137
145
/// List of static scripts
138
- pub static_scripts : ResScope < ' s , StaticScripts > ,
146
+ pub ( crate ) static_scripts : ResScope < ' s , StaticScripts > ,
139
147
}
140
148
141
149
impl < P : IntoScriptPluginParams > HandlerContext < ' _ , P > {
150
+ /// Get the callback settings
151
+ pub fn callback_settings ( & mut self ) -> & mut CallbackSettings < P > {
152
+ & mut self . callback_settings
153
+ }
154
+
155
+ /// Get the context loading settings
156
+ pub fn context_loading_settings ( & mut self ) -> & mut ContextLoadingSettings < P > {
157
+ & mut self . context_loading_settings
158
+ }
159
+
160
+ /// Get the scripts
161
+ pub fn scripts ( & mut self ) -> & mut Scripts {
162
+ & mut self . scripts
163
+ }
164
+
165
+ /// Get the runtime container
166
+ pub fn runtime_container ( & mut self ) -> & mut RuntimeContainer < P > {
167
+ & mut self . runtime_container
168
+ }
169
+
170
+ /// Get the script contexts
171
+ pub fn script_contexts ( & mut self ) -> & mut ScriptContexts < P > {
172
+ & mut self . script_contexts
173
+ }
174
+
175
+ /// Get the static scripts
176
+ pub fn static_scripts ( & mut self ) -> & mut StaticScripts {
177
+ & mut self . static_scripts
178
+ }
179
+
142
180
/// checks if the script is loaded such that it can be executed.
143
181
pub fn is_script_fully_loaded ( & self , script_id : ScriptId ) -> bool {
144
182
// check script exists in scripts and contexts
0 commit comments