Skip to content

Commit a1151ac

Browse files
authored
Merge branch 'main' into feat/static-scripts
2 parents e453ca3 + b322ba4 commit a1151ac

File tree

16 files changed

+229
-16
lines changed

16 files changed

+229
-16
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Missing Documentation Reminder
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
types:
7+
- edited
8+
- closed
9+
10+
jobs:
11+
find-missing-documentation:
12+
permissions:
13+
contents: read
14+
pull-requests: read
15+
issues: write
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Find closed PRs with 'needs documentation' label
21+
uses: actions/github-script@v6
22+
id: find-prs
23+
with:
24+
script: |
25+
26+
const query = `repo:makspll/bevy_mod_scripting is:pr is:merged is:closed label:"needs documentation"`;
27+
const encodedQuery = encodeURIComponent(query);
28+
29+
console.log(encodedQuery);
30+
31+
const { data: { items: pullRequests } } = await github.rest.search.issuesAndPullRequests({
32+
q: query,
33+
per_page: 100
34+
});
35+
36+
console.log(pullRequests)
37+
38+
const prsNeedingDocs = pullRequests.map(pr => `- [ ] ${pr.html_url} by @${pr.user.login}`).join("\n");
39+
if (!prsNeedingDocs) {
40+
return "- [x] All PRs with 'needs documentation' label have been updated in the book.";
41+
} else {
42+
return prsNeedingDocs;
43+
}
44+
result-encoding: string
45+
46+
- name: Update Issue Body
47+
uses: julien-deramond/update-issue-body@v1
48+
with:
49+
issue-number: 255
50+
body: |
51+
This is an automatically generated issue.
52+
53+
The following PRs have been closed but still need updates in the book:
54+
${{ steps.find-prs.outputs.result }}
55+
56+
If you are an author of one of these PRs, please consider updating the boook in `/docs` with appropriate documentation.
57+
Thank you!
58+
edit-mode: replace

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## [0.9.2](https://github.com/makspll/bevy_mod_scripting/compare/v0.9.1...v0.9.2) - 2025-02-08
4+
5+
### Added
6+
7+
- make `extractors` module non-public (#251)
8+
9+
### Fixed
10+
11+
- add missing extensions in the asset loader (#254)
12+
313
## [0.9.1](https://github.com/makspll/bevy_mod_scripting/compare/v0.9.0...v0.9.1) - 2025-02-01
414

515
### Fixed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_mod_scripting"
3-
version = "0.9.1"
3+
version = "0.9.2"
44
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
@@ -53,15 +53,15 @@ rhai = ["bevy_mod_scripting_rhai"]
5353
[dependencies]
5454
bevy = { workspace = true }
5555
bevy_mod_scripting_core = { workspace = true }
56-
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.9.1", optional = true }
57-
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.9.1", optional = true }
56+
bevy_mod_scripting_lua = { path = "crates/languages/bevy_mod_scripting_lua", version = "0.9.2", optional = true }
57+
bevy_mod_scripting_rhai = { path = "crates/languages/bevy_mod_scripting_rhai", version = "0.9.2", optional = true }
5858
# bevy_mod_scripting_rune = { path = "crates/languages/bevy_mod_scripting_rune", version = "0.9.0-alpha.2", optional = true }
5959
bevy_mod_scripting_functions = { workspace = true }
6060
[workspace.dependencies]
6161
profiling = { version = "1.0" }
6262
bevy = { version = "0.15.1", default-features = false }
63-
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.9.1" }
64-
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.9.1", default-features = false }
63+
bevy_mod_scripting_core = { path = "crates/bevy_mod_scripting_core", version = "0.9.2" }
64+
bevy_mod_scripting_functions = { path = "crates/bevy_mod_scripting_functions", version = "0.9.2", default-features = false }
6565

6666
# test utilities
6767
script_integration_test_harness = { path = "crates/script_integration_test_harness" }

crates/bevy_mod_scripting_core/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.9.2](https://github.com/makspll/bevy_mod_scripting/compare/bevy_mod_scripting_core-v0.9.1...bevy_mod_scripting_core-v0.9.2) - 2025-02-08
11+
12+
### Added
13+
14+
- make `extractors` module non-public (#251)
15+
16+
### Fixed
17+
18+
- add missing extensions in the asset loader (#254)
19+
1020
## [0.9.0-alpha.9](https://github.com/makspll/bevy_mod_scripting/compare/bevy_mod_scripting_core-v0.9.0-alpha.8...bevy_mod_scripting_core-v0.9.0-alpha.9) - 2025-01-28
1121

1222
### Fixed

crates/bevy_mod_scripting_core/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_mod_scripting_core"
3-
version = "0.9.1"
3+
version = "0.9.2"
44
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
@@ -43,6 +43,7 @@ derivative = "2.2"
4343
profiling = { workspace = true }
4444
[dev-dependencies]
4545
test_utils = { workspace = true }
46+
tokio = { version = "1", features = ["rt", "macros"] }
4647

4748
[lints]
4849
workspace = true

crates/bevy_mod_scripting_core/src/asset.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ pub struct ScriptAssetSettings {
112112
pub script_id_mapper: AssetPathToScriptIdMapper,
113113
/// Strategies for mapping asset paths to languages
114114
pub script_language_mappers: Vec<AssetPathToLanguageMapper>,
115+
116+
/// The currently supported asset extensions
117+
/// Should be updated by each scripting plugin to include the extensions it supports.
118+
///
119+
/// Will be used to populate the script asset loader with the supported extensions
120+
pub supported_extensions: &'static [&'static str],
115121
}
116122

117123
impl ScriptAssetSettings {
@@ -136,6 +142,7 @@ impl Default for ScriptAssetSettings {
136142
map: (|path: &AssetPath| path.path().to_string_lossy().into_owned().into()),
137143
},
138144
script_language_mappers: vec![],
145+
supported_extensions: &[],
139146
}
140147
}
141148
}
@@ -374,6 +381,7 @@ mod tests {
374381

375382
fn make_test_settings() -> ScriptAssetSettings {
376383
ScriptAssetSettings {
384+
supported_extensions: &[],
377385
script_id_mapper: AssetPathToScriptIdMapper {
378386
map: |path| path.path().to_string_lossy().into_owned().into(),
379387
},

crates/bevy_mod_scripting_core/src/event.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ pub enum Recipients {
122122
Script(ScriptId),
123123
/// The event is to be handled by all the scripts on the specified entity
124124
Entity(Entity),
125+
/// The event is to be handled by all the scripts of one language
126+
Language(crate::asset::Language),
125127
}
126128

127129
/// A callback event meant to trigger a callback in a subset/set of scripts in the world with the given arguments

crates/bevy_mod_scripting_core/src/handler.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ pub(crate) fn event_handler_internal<L: IntoCallbackLabel, P: IntoScriptPluginPa
138138
crate::event::Recipients::Entity(target_entity) if target_entity != entity => {
139139
continue
140140
}
141+
crate::event::Recipients::Language(target_language)
142+
if *target_language != P::LANGUAGE =>
143+
{
144+
continue
145+
}
141146
_ => (),
142147
}
143148
let script = match res_ctxt.scripts.scripts.get(script_id) {

crates/bevy_mod_scripting_core/src/lib.rs

Lines changed: 104 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ use handler::{CallbackSettings, HandlerFn};
2424
use runtime::{initialize_runtime, Runtime, RuntimeContainer, RuntimeInitializer, RuntimeSettings};
2525
use script::{ScriptId, Scripts, StaticScripts};
2626

27+
mod extractors;
28+
2729
pub mod asset;
2830
pub mod bindings;
2931
pub mod commands;
3032
pub mod context;
3133
pub mod docgen;
3234
pub mod error;
3335
pub mod event;
34-
pub mod extractors;
3536
pub mod handler;
3637
pub mod reflection_extensions;
3738
pub mod runtime;
@@ -56,6 +57,10 @@ pub enum ScriptingSystemSet {
5657

5758
/// Types which act like scripting plugins, by selecting a context and runtime
5859
/// Each individual combination of context and runtime has specific infrastructure built for it and does not interact with other scripting plugins
60+
///
61+
/// When implementing a new scripting plugin, also ensure the following implementations exist:
62+
/// - [`Plugin`] for the plugin, both [`Plugin::build`] and [`Plugin::finish`] methods need to be dispatched to the underlying [`ScriptingPlugin`] struct
63+
/// - [`AsMut<ScriptingPlugin<Self>`] for the plugin struct
5964
pub trait IntoScriptPluginParams: 'static {
6065
/// The language of the scripts
6166
const LANGUAGE: Language;
@@ -86,6 +91,9 @@ pub struct ScriptingPlugin<P: IntoScriptPluginParams> {
8691
pub context_initializers: Vec<ContextInitializer<P>>,
8792
/// initializers for the contexts run every time before handling events
8893
pub context_pre_handling_initializers: Vec<ContextPreHandlingInitializer<P>>,
94+
95+
/// Supported extensions to be added to the asset settings without the dot
96+
pub supported_extensions: &'static [&'static str],
8997
}
9098

9199
impl<P: IntoScriptPluginParams> Plugin for ScriptingPlugin<P> {
@@ -110,6 +118,8 @@ impl<P: IntoScriptPluginParams> Plugin for ScriptingPlugin<P> {
110118
// add extension for the language to the asset loader
111119
once_per_app_init(app);
112120

121+
app.add_supported_script_extensions(self.supported_extensions);
122+
113123
app.world_mut()
114124
.resource_mut::<ScriptAssetSettings>()
115125
.as_mut()
@@ -118,6 +128,10 @@ impl<P: IntoScriptPluginParams> Plugin for ScriptingPlugin<P> {
118128

119129
register_types(app);
120130
}
131+
132+
fn finish(&self, app: &mut App) {
133+
once_per_app_finalize(app);
134+
}
121135
}
122136

123137
impl<P: IntoScriptPluginParams> ScriptingPlugin<P> {
@@ -200,6 +214,33 @@ impl<P: IntoScriptPluginParams + AsMut<ScriptingPlugin<P>>> ConfigureScriptPlugi
200214
}
201215
}
202216

217+
fn once_per_app_finalize(app: &mut App) {
218+
#[derive(Resource)]
219+
struct BMSFinalized;
220+
221+
if app.world().contains_resource::<BMSFinalized>() {
222+
return;
223+
}
224+
app.insert_resource(BMSFinalized);
225+
226+
// read extensions from asset settings
227+
let asset_settings_extensions = app
228+
.world_mut()
229+
.get_resource_or_init::<ScriptAssetSettings>()
230+
.supported_extensions;
231+
232+
// convert extensions to static array
233+
bevy::log::info!(
234+
"Initializing BMS with Supported extensions: {:?}",
235+
asset_settings_extensions
236+
);
237+
238+
app.register_asset_loader(ScriptAssetLoader {
239+
extensions: asset_settings_extensions,
240+
preprocessor: None,
241+
});
242+
}
243+
203244
// One of registration of things that need to be done only once per app
204245
fn once_per_app_init(app: &mut App) {
205246
#[derive(Resource)]
@@ -208,7 +249,6 @@ fn once_per_app_init(app: &mut App) {
208249
if app.world().contains_resource::<BMSInitialized>() {
209250
return;
210251
}
211-
212252
app.insert_resource(BMSInitialized);
213253

214254
app.add_event::<ScriptErrorEvent>()
@@ -217,11 +257,7 @@ fn once_per_app_init(app: &mut App) {
217257
.init_resource::<Scripts>()
218258
.init_resource::<StaticScripts>()
219259
.init_asset::<ScriptAsset>()
220-
.init_resource::<AppScriptFunctionRegistry>()
221-
.register_asset_loader(ScriptAssetLoader {
222-
extensions: &[],
223-
preprocessor: None,
224-
});
260+
.init_resource::<AppScriptFunctionRegistry>();
225261

226262
app.add_systems(
227263
PostUpdate,
@@ -279,6 +315,7 @@ impl AddRuntimeInitializer for App {
279315
}
280316
}
281317

318+
282319
/// Trait for adding static scripts to an app
283320
pub trait ManageStaticScripts {
284321
/// Registers a script id as a static script.
@@ -303,3 +340,63 @@ impl ManageStaticScripts for App {
303340
self
304341
}
305342
}
343+
344+
/// Trait for adding a supported extension to the script asset settings.
345+
///
346+
/// This is only valid in the plugin building phase, as the asset loader will be created in the `finalize` phase.
347+
/// Any changes to the asset settings after that will not be reflected in the asset loader.
348+
pub trait ConfigureScriptAssetSettings {
349+
/// Adds a supported extension to the asset settings
350+
fn add_supported_script_extensions(&mut self, extensions: &[&'static str]) -> &mut Self;
351+
}
352+
353+
impl ConfigureScriptAssetSettings for App {
354+
fn add_supported_script_extensions(&mut self, extensions: &[&'static str]) -> &mut Self {
355+
let mut asset_settings = self
356+
.world_mut()
357+
.get_resource_or_init::<ScriptAssetSettings>();
358+
359+
let mut new_arr = Vec::from(asset_settings.supported_extensions);
360+
361+
new_arr.extend(extensions);
362+
363+
let new_arr_static = Vec::leak(new_arr);
364+
365+
asset_settings.supported_extensions = new_arr_static;
366+
367+
self
368+
}
369+
}
370+
371+
#[cfg(test)]
372+
mod test {
373+
use super::*;
374+
375+
#[tokio::test]
376+
async fn test_asset_extensions_correctly_accumulate() {
377+
let mut app = App::new();
378+
app.init_resource::<ScriptAssetSettings>();
379+
app.add_plugins(AssetPlugin::default());
380+
381+
app.world_mut()
382+
.resource_mut::<ScriptAssetSettings>()
383+
.supported_extensions = &["lua", "rhai"];
384+
385+
once_per_app_finalize(&mut app);
386+
387+
let asset_loader = app
388+
.world()
389+
.get_resource::<AssetServer>()
390+
.expect("Asset loader not found");
391+
392+
asset_loader
393+
.get_asset_loader_with_extension("lua")
394+
.await
395+
.expect("Lua loader not found");
396+
397+
asset_loader
398+
.get_asset_loader_with_extension("rhai")
399+
.await
400+
.expect("Rhai loader not found");
401+
}
402+
}

crates/bevy_mod_scripting_functions/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bevy_mod_scripting_functions"
3-
version = "0.9.1"
3+
version = "0.9.2"
44
edition = "2021"
55
authors = ["Maksymilian Mozolewski <makspl17@gmail.com>"]
66
license = "MIT OR Apache-2.0"

0 commit comments

Comments
 (0)