Skip to content

Commit a29bb59

Browse files
committed
deploy: 3e81e14
1 parent 23efe09 commit a29bb59

File tree

71 files changed

+12825
-9401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+12825
-9401
lines changed

Examples/introduction.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ <h1 id="examples"><a class="header" href="#examples">Examples</a></h1>
193193
<i class="fa fa-angle-left"></i>
194194
</a>
195195

196-
<a rel="next prefetch" href="../ScriptingReference/introduction.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
196+
<a rel="next prefetch" href="../Migration/guides.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
197197
<i class="fa fa-angle-right"></i>
198198
</a>
199199

@@ -207,7 +207,7 @@ <h1 id="examples"><a class="header" href="#examples">Examples</a></h1>
207207
<i class="fa fa-angle-left"></i>
208208
</a>
209209

210-
<a rel="next prefetch" href="../ScriptingReference/introduction.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
210+
<a rel="next prefetch" href="../Migration/guides.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
211211
<i class="fa fa-angle-right"></i>
212212
</a>
213213
</nav>

Migration/0.14-to-0.15.html

Lines changed: 373 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<!-- Book generated using mdBook -->
55
<meta charset="UTF-8">
6-
<title>Script ID Mapping - Bevy Scripting</title>
6+
<title>Migration Guides - Bevy Scripting</title>
77

88

99
<!-- Custom HTML head -->
@@ -147,7 +147,7 @@ <h1 class="menu-title">Bevy Scripting</h1>
147147
<a href="https://github.com/makspll/bevy_mod_scripting" title="Git repository" aria-label="Git repository">
148148
<i id="git-repository-button" class="fa fa-github"></i>
149149
</a>
150-
<a href="https://github.com/makspll/bevy_mod_scripting/edit/main/docs/src/Summary/script-id-mapping.md" title="Suggest an edit" aria-label="Suggest an edit" rel="edit">
150+
<a href="https://github.com/makspll/bevy_mod_scripting/edit/main/docs/src/Migration/guides.md" title="Suggest an edit" aria-label="Suggest an edit" rel="edit">
151151
<i id="git-edit-button" class="fa fa-edit"></i>
152152
</a>
153153

@@ -181,22 +181,17 @@ <h1 class="menu-title">Bevy Scripting</h1>
181181

182182
<div id="content" class="content">
183183
<main>
184-
<h1 id="script-id-mapping"><a class="header" href="#script-id-mapping">Script ID mapping</a></h1>
185-
<p>Every script is currently identified by a unique ID.</p>
186-
<p>ID's are derived from the script asset path for scripts loaded via the asset system.</p>
187-
<p>By default this is an identity mapping, but you can override this by modifying the <code>AssetPathToScriptIdMapper</code> inside the <code>ScriptAssetSettings</code> resource before loading the script.</p>
188-
<div class="warning">
189-
Be wary of path separators, by default script ID's are derived from asset paths, which are platform dependent. Make sure to use `std::path::PathBuf` if you are targetting multiple platforms.
190-
</div>
184+
<h1 id="migration-guides"><a class="header" href="#migration-guides">Migration Guides</a></h1>
185+
191186
</main>
192187

193188
<nav class="nav-wrapper" aria-label="Page navigation">
194189
<!-- Mobile navigation buttons -->
195-
<a rel="prev" href="../Summary/sharing-contexts-between-scripts.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
190+
<a rel="prev" href="../Examples/introduction.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
196191
<i class="fa fa-angle-left"></i>
197192
</a>
198193

199-
<a rel="next prefetch" href="../ScriptSystems/introduction.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
194+
<a rel="next prefetch" href="../Migration/0.14-to-0.15.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
200195
<i class="fa fa-angle-right"></i>
201196
</a>
202197

@@ -206,11 +201,11 @@ <h1 id="script-id-mapping"><a class="header" href="#script-id-mapping">Script ID
206201
</div>
207202

208203
<nav class="nav-wide-wrapper" aria-label="Page navigation">
209-
<a rel="prev" href="../Summary/sharing-contexts-between-scripts.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
204+
<a rel="prev" href="../Examples/introduction.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
210205
<i class="fa fa-angle-left"></i>
211206
</a>
212207

213-
<a rel="next prefetch" href="../ScriptSystems/introduction.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
208+
<a rel="next prefetch" href="../Migration/0.14-to-0.15.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
214209
<i class="fa fa-angle-right"></i>
215210
</a>
216211
</nav>

ScriptSystems/introduction.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ <h2 id="callback"><a class="header" href="#callback">Callback</a></h2>
248248

249249
<nav class="nav-wrapper" aria-label="Page navigation">
250250
<!-- Mobile navigation buttons -->
251-
<a rel="prev" href="../Summary/script-id-mapping.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
251+
<a rel="prev" href="../Summary/contexts.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
252252
<i class="fa fa-angle-left"></i>
253253
</a>
254254

@@ -262,7 +262,7 @@ <h2 id="callback"><a class="header" href="#callback">Callback</a></h2>
262262
</div>
263263

264264
<nav class="nav-wide-wrapper" aria-label="Page navigation">
265-
<a rel="prev" href="../Summary/script-id-mapping.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
265+
<a rel="prev" href="../Summary/contexts.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
266266
<i class="fa fa-angle-left"></i>
267267
</a>
268268

ScriptingReference/introduction.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ <h2 id="globals"><a class="header" href="#globals">Globals</a></h2>
196196

197197
<nav class="nav-wrapper" aria-label="Page navigation">
198198
<!-- Mobile navigation buttons -->
199-
<a rel="prev" href="../Examples/introduction.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
199+
<a rel="prev" href="../Migration/0.14-to-0.15.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
200200
<i class="fa fa-angle-left"></i>
201201
</a>
202202

@@ -210,7 +210,7 @@ <h2 id="globals"><a class="header" href="#globals">Globals</a></h2>
210210
</div>
211211

212212
<nav class="nav-wide-wrapper" aria-label="Page navigation">
213-
<a rel="prev" href="../Examples/introduction.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
213+
<a rel="prev" href="../Migration/0.14-to-0.15.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
214214
<i class="fa fa-angle-left"></i>
215215
</a>
216216

Summary/sharing-contexts-between-scripts.html renamed to Summary/contexts.html

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<!-- Book generated using mdBook -->
55
<meta charset="UTF-8">
6-
<title>Shared Contexts - Bevy Scripting</title>
6+
<title>Contexts - Bevy Scripting</title>
77

88

99
<!-- Custom HTML head -->
@@ -147,7 +147,7 @@ <h1 class="menu-title">Bevy Scripting</h1>
147147
<a href="https://github.com/makspll/bevy_mod_scripting" title="Git repository" aria-label="Git repository">
148148
<i id="git-repository-button" class="fa fa-github"></i>
149149
</a>
150-
<a href="https://github.com/makspll/bevy_mod_scripting/edit/main/docs/src/Summary/sharing-contexts-between-scripts.md" title="Suggest an edit" aria-label="Suggest an edit" rel="edit">
150+
<a href="https://github.com/makspll/bevy_mod_scripting/edit/main/docs/src/Summary/contexts.md" title="Suggest an edit" aria-label="Suggest an edit" rel="edit">
151151
<i id="git-edit-button" class="fa fa-edit"></i>
152152
</a>
153153

@@ -181,19 +181,59 @@ <h1 class="menu-title">Bevy Scripting</h1>
181181

182182
<div id="content" class="content">
183183
<main>
184-
<h1 id="shared-contexts"><a class="header" href="#shared-contexts">Shared Contexts</a></h1>
185-
<p>By default BMS will create an individual script context, or sandbox, for each script that is run. This means that each script will have its own set of global variables and functions that are isolated from other scripts. However, sometimes this might not be desirable, if you aren't worried about scripts interfering with each other, or if you want to easilly share data between scripts. In these cases, you can use shared contexts.</p>
186-
<h2 id="enabling-shared-contexts"><a class="header" href="#enabling-shared-contexts">Enabling Shared Contexts</a></h2>
187-
<p>You can enable shared contexts by configuring the relevant scripting plugin like so:</p>
188-
<pre><code class="language-rust ignore">let mut plugin = LuaScriptingPlugin::default().enable_context_sharing();
189-
190-
app.add_plugins(plugin);</code></pre>
184+
<h1 id="contexts"><a class="header" href="#contexts">Contexts</a></h1>
185+
<p>Each script runs in a context. By default BMS will create an individual context, or sandbox, for each script-entity pair that is run. This means that each script-entity pair will have its own set of global variables and functions that are isolated from other scripts. However, sometimes this might not be desirable. If you are not worried about scripts interfering with each other, or if you want to easily share data between scripts, you can consider using a different context policy.</p>
186+
<h2 id="context-policies"><a class="header" href="#context-policies">Context Policies</a></h2>
187+
<h3 id="shared-context"><a class="header" href="#shared-context">Shared Context</a></h3>
188+
<p>A shared context means that all scripts run in the same context; there is in fact only one context to run in. If the scripts interact heavily with each other, this may be what you want.</p>
189+
<p>To enable a shared context, set the corresponding context policy on the scripting plugin:</p>
190+
<pre><code class="language-rust ignore">app.add_plugins(LuaScriptingPlugin::default().set_context_policy(
191+
ContextPolicy::shared(),
192+
));```
193+
194+
## Per Script Context
195+
A per script context provides each script with their own context. However, scripts may be attached to multiple entities, in which case a single script context is shared by multiple entities.
196+
197+
To enable per script contexts, insert the `ContextPolicy::per_script()` resource.
198+
```rust,ignore
199+
app.add_plugins(LuaScriptingPlugin::default().set_context_policy(
200+
ContextPolicy::per_script(),
201+
));```
202+
203+
## Per Entity Context
204+
A per entity context provides each entity with their own context. The scripts attached to an entity via `ScriptComponent` all run in the same context.
205+
206+
To enable per entity contexts, insert the `ContextPolicy::per_entity()` resource.
207+
```rust,ignore
208+
app.add_plugins(LuaScriptingPlugin::default().set_context_policy(
209+
ContextPolicy::per_entity(),
210+
));```
211+
212+
## Per Entity and Script Context
213+
A per entity-and-script context provides each entity-script pair with their own context. This is a maximally isolated way to run scripts.
214+
215+
To enable per entity-and-script contexts, insert the `ContextPolicy::per_entity_and_script()` resource.
216+
```rust,ignore
217+
app.add_plugins(LuaScriptingPlugin::default().set_context_policy(
218+
ContextPolicy::per_entity_and_script(),
219+
));</code></pre>
220+
<h2 id="custom-policies"><a class="header" href="#custom-policies">Custom Policies</a></h2>
221+
<p>Here is another way to write the <code>per_script()</code> policy.</p>
222+
<pre><code class="language-rust ignore">let policy_a = ContextPolicy::per_script();
223+
let policy_b = ContextPolicy { priorities: vec![ContextRule::Script, ContextRule::Shared] };
224+
assert_eq!(policy_a, policy_b);</code></pre>
225+
<p>Reminding ourselves how <code>ContextKey</code> is defined,</p>
226+
<pre><code class="language-rust ignore">pub struct ContextKey {
227+
pub entity: Option&lt;Entity&gt;,
228+
pub script: Option&lt;Handle&lt;ScriptAsset&gt;&gt;,
229+
}</code></pre>
230+
<p>we read <code>policy_b</code> like this: if <code>ContextKey</code> has a script, return a <code>ContextKey</code> with only a script. Failing that <code>ContextRule::Shared</code> always returns an empty <code>ContextKey</code>.</p>
231+
<p>One may also provide an entirely custom rule by implementing the <code>ContextKeySelector</code> trait.</p>
191232
<h2 id="context-loading-settings"><a class="header" href="#context-loading-settings">Context Loading Settings</a></h2>
192233
<p>All context loading settings are stored in a separate resource per scripting plugin namely: <code>ContextLoadingSettings&lt;Plugin&gt;</code>.</p>
193234
<p>The settings are as follows:</p>
194235
<ul>
195236
<li><code>loader</code> - the load and unload strategy for contexts. Each scripting plugin will have a load and unload function which is hooked up through here</li>
196-
<li><code>assigner</code> - the strategy for assigning/unassigning contexts to scripts. This is used to determine how to assign a context to a script when it is run, and what to do with the context when the script is finished.</li>
197237
<li><code>context_initializers</code> - stores all context initializers for the plugin</li>
198238
<li><code>context_pre_handling_initializers</code> - stores all context pre-handling initializers for the plugin</li>
199239
</ul>
@@ -207,7 +247,7 @@ <h2 id="context-loading-settings"><a class="header" href="#context-loading-setti
207247
<i class="fa fa-angle-left"></i>
208248
</a>
209249

210-
<a rel="next prefetch" href="../Summary/script-id-mapping.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
250+
<a rel="next prefetch" href="../ScriptSystems/introduction.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
211251
<i class="fa fa-angle-right"></i>
212252
</a>
213253

@@ -221,7 +261,7 @@ <h2 id="context-loading-settings"><a class="header" href="#context-loading-setti
221261
<i class="fa fa-angle-left"></i>
222262
</a>
223263

224-
<a rel="next prefetch" href="../Summary/script-id-mapping.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
264+
<a rel="next prefetch" href="../ScriptSystems/introduction.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
225265
<i class="fa fa-angle-right"></i>
226266
</a>
227267
</nav>

0 commit comments

Comments
 (0)