Skip to content

Commit c289bc4

Browse files
committed
improve docs, fix issues
1 parent 941f800 commit c289bc4

File tree

7 files changed

+87
-3
lines changed

7 files changed

+87
-3
lines changed

crates/ladfile_builder/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ use bevy_mod_scripting_core::{
2121
};
2222
use bevy_reflect::{NamedField, TypeInfo, TypeRegistry, Typed, UnnamedField};
2323
use ladfile::*;
24+
use std::{
25+
any::TypeId,
26+
borrow::Cow,
27+
cmp::{max, min},
28+
collections::HashMap,
29+
ffi::OsString,
30+
path::PathBuf,
31+
};
2432

2533
/// We can assume that the types here will be either primitives
2634
/// or reflect types, as the rest will be covered by typed wrappers
@@ -843,6 +851,8 @@ impl<'t> LadFileBuilder<'t> {
843851

844852
#[cfg(test)]
845853
mod test {
854+
use std::collections::HashMap;
855+
846856
use bevy_mod_scripting_core::{
847857
bindings::{
848858
function::{

docs/src/Migration/guides.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

docs/src/Migration/0.14-to-0.15.md renamed to docs/src/ReleaseNotes/0.14-to-0.15.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,34 @@ pub struct ScriptCallbackEvent {
188188
/// Whether the callback should emit a response event
189189
pub trigger_response: bool,
190190
}
191+
```
192+
193+
## Bindings Changes
194+
195+
### ScriptId
196+
`script_id` is replaced with `script_asset` which now has a type of `Handle<ScriptAsset>`. This means that you can no longer use a string to refer to a script, but rather you must use a handle.
197+
198+
Scripts can still access the asset path of the script using:
199+
```lua,ignore
200+
-- prints: "my_script.lua"
201+
print(script_asset:asset_path())
202+
```
203+
204+
### ScriptAttachment
205+
The concept of script attachments has been introduced to describe the idea of a script instance. Previously this was muddied due to the fact script ID's were the primary way to refer to scripts. Now the instance of a script and its mapping to a context is clearer.
206+
207+
This is reflected in a brand new set of bindings:
208+
209+
```lua,ignore
210+
-- will create backing ScriptAttachment instances, that can be used in other bindings.
211+
local entity_script = ScriptAttachment.new_entity_script(entity, script_asset)
212+
local static_script = ScriptAttachment.new_static_script(script_asset)
213+
```
214+
215+
### System Builder
216+
the system builder no longer accepts script id's as parameters. Instead it accepts script attachments
217+
218+
```diff,lua
219+
-system_builder("my_callback", "this_script_id.lua")
220+
+system_builder("my_callback", ScriptAttachment.new_static_script(script_asset))
191221
```

docs/src/ReleaseNotes/0.15.0.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 0.15.0 - Asset Handles and Context Policies
2+
3+
This release focuses on aligning `bevy_mod_scripting` with modern Bevy practices, most notably by switching to `Handle<ScriptAsset>` for script management. This change simplifies the API, removes boilerplate, and makes script handling more idiomatic.
4+
5+
## Summary
6+
7+
### Asset-First Workflow
8+
Scripts are now treated as first-class Bevy assets. The old `ScriptId` (which was a string) has been replaced by `AssetId<ScriptAsset>`, and you'll primarily interact with scripts via `Handle<ScriptAsset>`.
9+
10+
```rust,ignore
11+
// New way
12+
let handle: Handle<ScriptAsset> = asset_server.load("my_script.lua");
13+
commands.spawn(ScriptComponent(vec![handle]));
14+
```
15+
16+
Scripts are now only evaluated when they are attached to a `ScriptComponent` or added to `StaticScripts`, which means you have more control over when and how scripts are executed.
17+
18+
### Flexible Context Policies
19+
You now have much finer control over how script contexts (i.e., the environment a script runs in) are created. The old `enable_context_sharing()` has been replaced with `set_context_policy()` which accepts a `ContextPolicy`:
20+
21+
- `ContextPolicy::shared()`: All scripts run in one global context
22+
- `ContextPolicy::per_script()`: Each script asset gets its own context (the old default.)
23+
- `ContextPolicy::per_entity()`: Each entity with scripts gets its own context.
24+
- `ContextPolicy::per_entity_and_script()`: A unique context for every script on every entity (the new default).
25+
26+
This means that each script is maximally isolated by default, but you can still opt for shared contexts if needed.
27+
28+
29+
### Other Changes
30+
- **`Recipients` Enum:** The `Recipients` enum for events has been redesigned to align with the new context policies, offering `AllScripts` and `AllContexts` variants, and removing some variants which don't fit the new model. If you need the old behaviour, you can simply query the ECS first before sending events.
31+
- **API Cleanup:** Several types and traits were removed or simplified, including `ScriptAssetSettings`, `AssetPathToScriptIdMapper`, and `ScriptMetadataStore`, as they are no longer needed with the new asset-based approach.
32+
33+
## Migration Guide
34+
This release contains significant breaking changes. Please refer to the migration guide for detailed instructions on updating your project.
35+
36+
- [Migration Guide: 0.14 to 0.15](https://makspll.github.io/bevy_mod_scripting/Migration/0.14-to-0.15.html)

docs/src/ReleaseNotes/guides.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Release Notes
2+
3+
This section contains migration guides and release notes relevant to the `bevy_mod_scripting` crate.
4+
5+
This used to live in the repository, so for older release notes or guides, refer to the [GitHub repository](https://github.com/makspll/bevy_mod_scripting/blob/main/release-notes/)

docs/src/SUMMARY.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
- [Contexts](./Summary/contexts.md)
1212
- [Script Systems](./ScriptSystems/introduction.md)
1313
- [Examples](./Examples/introduction.md)
14-
- [Migration Guides](./Migration/guides.md)
15-
- [0.14-to-0.15](./Migration/0.14-to-0.15.md)
14+
15+
# Release Notes
16+
17+
- [Release Notes](./ReleaseNotes/guides.md)
18+
- [0.14-to-0.15](./ReleaseNotes/0.14-to-0.15.md)
19+
- [0.15.0](./ReleaseNotes/0.15.0.md)
1620

1721
# Scripting Reference
1822

0 commit comments

Comments
 (0)