Skip to content

Commit 0f29b53

Browse files
committed
refactor: extract bevy_mod_scripting_bindings and bevy_mod_scripting_display crates, decouple concerns
1 parent 7383c9f commit 0f29b53

File tree

145 files changed

+10457
-8957
lines changed

Some content is hidden

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

145 files changed

+10457
-8957
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
applyTo: docs/, **/*.md
3+
---
4+
5+
# Documentation Instructions
6+
7+
The `/docs` folder contain documentation for the project as well as release notes.
8+
9+
Newer release notes should be added to `/docs/src/ReleaseNotes/`.
10+
11+
When making changes to the documentation, please ensure that you follow these guidelines:
12+
- Use clear and concise language, focusing on EXAMPLES and practical usage.
13+
- Use these naming conventions:
14+
- Use lowercase letters and hyphens for file names (e.g., `my-documentation-file.md`).
15+
- for migration guides use the format `0.0.1-to-0.0.2.md`.
16+
- for release notes use the format `0.0.1.md`.
17+
18+
19+
# Release Notes Instructions
20+
21+
Release notes should highlight the major highlights of each release, while leaving the breaking changes for migration guides.
22+
23+
When creating release notes, please follow these guidelines:
24+
- Include links to relevant issues or pull requests when applicable.
25+
- YOU MUST use the following heading structure:
26+
- `# Version - Short Description`
27+
- `## Summary`
28+
- `### <Theme>` for each major theme or change
29+
- `### Other Changes` (if applicable) for smaller changes worth mentioning
30+
- `## Migration Guide` (if applicable) providing a link to the detailed migration guide.
31+
32+
33+
# Migration Guide Instructions
34+
35+
When creating migration guides, please follow these guidelines:
36+
- Provide step-by-step instructions for updating projects to the new version.
37+
- Each breaking change should come under a heading related to the change i.e. `### ScriptAsset removed`
38+
- Include code snippets to illustrate changes.
39+
- Use diff format when talking about concrete changes to specific structures or traits.
40+
- Include links to relevant issues or pull requests when applicable.
41+
- Generally each pull request has a migration guide section, which must be taken into account and expanded on when writing relevant migration guides.
42+
43+
44+
# Examples
45+
46+
## Release Notes Example
47+
48+
```markdown
49+
# 0.15.0 - Asset Handles and Context Policies
50+
51+
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.
52+
53+
## Summary
54+
55+
### Asset-First Workflow
56+
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>`.
57+
58+
```rust,ignore
59+
// New way
60+
let handle: Handle<ScriptAsset> = asset_server.load("my_script.lua");
61+
commands.spawn(ScriptComponent(vec![handle]));
62+
```
63+
64+
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.
65+
66+
### Other Changes
67+
- **`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.
68+
- **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.
69+
70+
## Migration Guide
71+
This release contains significant breaking changes. Please refer to the migration guide for detailed instructions on updating your project.
72+
73+
- [Migration Guide: 0.14 to 0.15](https://makspll.github.io/bevy_mod_scripting/Migration/0.14-to-0.15.html)
74+
75+
```
76+
77+
## Migration Guide Example
78+
79+
```markdown
80+
# Migration Guide: <from> to <to>
81+
82+
## Changes to pre handling callbacks
83+
84+
This change affects the parameters for the `context_pre_handling_initializers`
85+
```diff
86+
- context_pre_handling_initializers: vec![|script_id, entity, context| {
87+
+ context_pre_handling_initializers: vec![|context_key, context| {
88+
```
89+
and `context_initializers`:
90+
```diff
91+
- context_initializers: vec![|script_id, context| {
92+
+ context_initializers: vec![|context_key, context| {
93+
```
94+
95+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
applyTo: **
3+
---
4+
5+
# Repository Instructions
6+
7+
## High-Level Structure
8+
9+
### Core Components
10+
- **bevy_mod_scripting** - Main workspace crate that re-exports key functionality.
11+
- **bevy_mod_scripting_core** - Core framework with language-agnostic scripting functionality
12+
- **bevy_mod_scripting_asset** - Handles script assets, loading, and language detection
13+
- **bevy_mod_scripting_derive** - Procedural macros for generating bindings
14+
- **bevy_mod_scripting_functions** - Core Bevy function bindings, and plugin managing various binding crates via features.
15+
16+
### Language Implementations
17+
- **bevy_mod_scripting_lua** - Lua language implementation
18+
- **bevy_mod_scripting_rhai** - Rhai language implementation
19+
20+
### Binding Crates
21+
- Multiple **bevy_*_bms_bindings** crates (e.g., transform, asset, pbr, etc.) that provide specific Bevy module bindings
22+
- These are automatically generated via the `/codegen` tools, per bevy release
23+
24+
### Development Tools
25+
- **xtask** - Custom task runner for development workflows
26+
- **codegen** - Code generation tools for generating bindings from Bevy's API
27+
- **docs** - Documentation built with mdbook
28+
- **docs/src/ReleaseNotes** - Release notes and migration guides
29+
30+
## Key Features
31+
32+
1. **Script Management** - Loading, hot reloading, and lifecycle management via Bevy's asset system
33+
2. **Flexible Bindings** - Attach bindings to any Reflect-implementing types
34+
3. **Dynamic Systems** - Create ECS systems from scripts that run in parallel
35+
4. **Component Creation** - Register and use components from scripts
36+
5. **Multiple Language Support** - Currently supports Lua and Rhai
37+
38+
39+
## Xtask Commands
40+
- `cargo xtask check` - Builds the project and runs clippy

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ bevy_mod_scripting_rhai = { workspace = true, optional = true }
9999
bevy_mod_scripting_functions = { workspace = true }
100100
bevy_mod_scripting_derive = { workspace = true }
101101
bevy_mod_scripting_asset = { workspace = true }
102+
bevy_mod_scripting_bindings = { workspace = true }
103+
bevy_mod_scripting_display = { workspace = true }
102104

103105
[workspace.dependencies]
104106
# local crates
@@ -112,7 +114,8 @@ ladfile_builder = { path = "crates/ladfile_builder", version = "0.5.1" }
112114
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.15.1", default-features = false }
113115
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.15.1", default-features = false }
114116
bevy_mod_scripting_asset = { path = "crates/bevy_mod_scripting_asset", version = "0.15.1", default-features = false }
115-
117+
bevy_mod_scripting_bindings = { path = "crates/bevy_mod_scripting_bindings", version = "0.15.1", default-features = false }
118+
bevy_mod_scripting_display = { path = "crates/bevy_mod_scripting_display", version = "0.15.1", default-features = false }
116119
# bevy
117120

118121
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.15.1" }
@@ -190,7 +193,7 @@ itertools = { version = "0.14", default-features = false }
190193
fixedbitset = { version = "0.5", default-features = false }
191194
variadics_please = { version = "1.1.0", default-features = false }
192195
anyhow = { version = "1.0", default-features = false }
193-
196+
indent_write = { version = "2", default-features = false, features = ["std"] }
194197

195198
# development and testing
196199

@@ -245,6 +248,8 @@ members = [
245248
"crates/bevy_system_reflection",
246249
"crates/bindings/*",
247250
"crates/bevy_mod_scripting_asset",
251+
"crates/bevy_mod_scripting_bindings",
252+
"crates/bevy_mod_scripting_display",
248253
]
249254
resolver = "2"
250255
exclude = ["codegen", "crates/macro_tests", "xtask"]

assets/tests/add_system/added_systems_run_in_parallel.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ digraph {
2626
node_1 [label="bevy_asset::assets::Assets<bevy_asset::assets::LoadedUntypedAsset>::asset_events"];
2727
node_2 [label="bevy_asset::assets::Assets<()>::asset_events"];
2828
node_3 [label="bevy_asset::assets::Assets<bevy_mod_scripting_asset::script_asset::ScriptAsset>::asset_events"];
29-
node_4 [label="bevy_mod_scripting_core::bindings::allocator::garbage_collector"];
29+
node_4 [label="bevy_mod_scripting_bindings::allocator::garbage_collector"];
3030
node_5 [label="script_integration_test_harness::dummy_before_post_update_system"];
3131
node_6 [label="script_integration_test_harness::dummy_post_update_system"];
3232
node_7 [label="on_test_post_update"];

assets/tests/add_system/added_systems_run_in_parallel.rhai

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ digraph {
2525
node_1 [label="bevy_asset::assets::Assets<bevy_asset::assets::LoadedUntypedAsset>::asset_events"];
2626
node_2 [label="bevy_asset::assets::Assets<()>::asset_events"];
2727
node_3 [label="bevy_asset::assets::Assets<bevy_mod_scripting_asset::script_asset::ScriptAsset>::asset_events"];
28-
node_4 [label="bevy_mod_scripting_core::bindings::allocator::garbage_collector"];
28+
node_4 [label="bevy_mod_scripting_bindings::allocator::garbage_collector"];
2929
node_5 [label="script_integration_test_harness::dummy_before_post_update_system"];
3030
node_6 [label="script_integration_test_harness::dummy_post_update_system"];
3131
node_7 [label="on_test_post_update"];
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
local type = world._get_mock_resource_type()
32

4-
assert_throws(function ()
3+
assert_throws(function()
54
world.remove_resource(type)
6-
end, "Missing type data ReflectResource for type: Unregistered.TypeId.*")
5+
end, "Missing type data ReflectResource for type: Unregistered Type.*")

assets/tests/remove_resource/no_resource_data_errors.rhai

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ let type = world._get_mock_resource_type.call();
33

44
assert_throws(||{
55
world.remove_resource.call(type)
6-
}, "Missing type data ReflectResource for type: Unregistered.TypeId.*");
6+
}, "Missing type data ReflectResource for type: Unregistered Type.*");

codegen/Cargo.bootstrap.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version = "0.1.0"
55
edition = "2024"
66

77
[dependencies]
8-
bevy_mod_scripting_core = { path = "{{BMS_CORE_PATH}}" }
8+
bevy_mod_scripting_bindings = { path = "{{BMS_BINDINGS_PATH}}" }
99
bevy_reflect = { version = "0.16.0", features = [
1010
"smol_str",
1111
"glam",

codegen/src/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ pub struct Args {
6060
#[arg(global = true, long)]
6161
pub template_args: Option<String>,
6262

63-
/// The path to the bevy_mod_scripting_core crate, used to bootstrap necessary traits
63+
/// The path to the bevy_mod_scripting_bindings crate, used to bootstrap necessary traits
6464
#[arg(global = true, long, default_value = ".")]
65-
pub bms_core_path: Utf8PathBuf,
65+
pub bms_bindings_path: Utf8PathBuf,
6666

6767
/// Crates to exclude from code generation
6868
#[arg(

codegen/src/bin/main.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use log::{debug, error, info};
1616
use strum::VariantNames;
1717
use tera::Context;
1818

19-
const BOOTSTRAP_DEPS: [&str; 2] = ["bevy_reflect", "bevy_mod_scripting_core"];
19+
const BOOTSTRAP_DEPS: [&str; 2] = ["bevy_reflect", "bevy_mod_scripting_bindings"];
2020

2121
fn main() {
2222
// parse this here to early exit on wrong args
@@ -176,7 +176,7 @@ fn main() {
176176

177177
debug!("Bootstrap directory: {}", &temp_dir.as_path().display());
178178

179-
write_bootstrap_files(args.bms_core_path, temp_dir.as_path());
179+
write_bootstrap_files(args.bms_bindings_path, temp_dir.as_path());
180180

181181
let bootstrap_rlibs = build_bootstrap(temp_dir.as_path(), &plugin_target_dir.join("bootstrap"));
182182

@@ -200,7 +200,7 @@ fn main() {
200200
)
201201
};
202202
} else {
203-
panic!("Could not find 'libmlua' artifact among bootstrap crate artifacts, stopping.");
203+
panic!("Could not find all bootstrap rlibs, found: {bootstrap_rlibs:?}");
204204
}
205205

206206
debug!("Running bevy_api_gen main cargo command");
@@ -355,15 +355,16 @@ fn find_bootstrap_dir() -> PathBuf {
355355
}
356356

357357
/// Generate bootstrapping crate files
358-
fn write_bootstrap_files(bms_core_path: Utf8PathBuf, path: &Path) {
359-
const BMS_CORE_PATH_PLACEHOLDER: &str = "{{BMS_CORE_PATH}}";
358+
fn write_bootstrap_files(bms_bindings_path: Utf8PathBuf, path: &Path) {
359+
const BMS_BINDINGS_PATH_PLACEHOLDER: &str = "{{BMS_BINDINGS_PATH}}";
360360

361361
// write manifest file 'Cargo.toml'
362362
let mut manifest_content =
363363
String::from_utf8(include_bytes!("../../Cargo.bootstrap.toml").to_vec())
364364
.expect("Could not read manifest template as utf8");
365365

366-
manifest_content = manifest_content.replace(BMS_CORE_PATH_PLACEHOLDER, bms_core_path.as_str());
366+
manifest_content =
367+
manifest_content.replace(BMS_BINDINGS_PATH_PLACEHOLDER, bms_bindings_path.as_str());
367368

368369
let manifest_path = path.join("Cargo.toml");
369370

0 commit comments

Comments
 (0)