Skip to content

Commit

Permalink
Fix compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim committed Jun 11, 2024
1 parent 1e19607 commit 0d89619
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 127 deletions.
14 changes: 7 additions & 7 deletions crates/bevy_plugin/src/commands/command_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ mod tests {
methods.add_command("test", |_: In<()>| panic!("It works!"));
let method = methods.get_mut("test").unwrap();
let mut app = App::new();
method.call(vec![], &mut app.world);
method.call(vec![], app.world_mut());
}

#[test]
Expand All @@ -189,7 +189,7 @@ mod tests {
methods.add_command("test", |In(a): In<f32>| assert_eq!(1.0, a));
let method = methods.get_mut("test").unwrap();
let mut app = App::new();
method.call(to_method_params([1.0]), &mut app.world);
method.call(to_method_params([1.0]), app.world_mut());
}

#[test]
Expand All @@ -209,10 +209,10 @@ mod tests {
let mut app = App::new();
{
let method1 = methods.get_mut("test1").unwrap();
method1.call(vec![], &mut app.world);
method1.call(vec![], app.world_mut());
}
let method2 = methods.get_mut("test2").unwrap();
method2.call(to_method_params([1.0]), &mut app.world);
method2.call(to_method_params([1.0]), app.world_mut());
}

#[test]
Expand All @@ -228,8 +228,8 @@ mod tests {
let method = methods.get_mut("test").unwrap();

let mut app = App::new();
method.call(to_method_params([1.0]), &mut app.world);
let data = app.world.resource::<Data>();
method.call(to_method_params([1.0]), app.world_mut());
let data = app.world().resource::<Data>();
assert_eq!(data.0, 1.0);
}

Expand All @@ -247,7 +247,7 @@ mod tests {
let method = methods.get_mut("test").unwrap();

let mut app = App::new();
let task = method.call(vec![], &mut app.world);
let task = method.call(vec![], app.world_mut());
assert!(!task.is_finished());
sleep(Duration::from_millis(600));
assert!(task.is_finished());
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_plugin/src/commands/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn execute_commands(world: &mut World, mut reader: Local<ManualEventReader<Execu
}

fn clone_events(
world: &mut World,
world: &World,
reader: &mut ManualEventReader<ExecuteCommandEvent>,
) -> Vec<ExecuteCommandEvent> {
let events = world.resource::<Events<ExecuteCommandEvent>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ impl AssetProvider for FileExtensionAssetProvider {
};

self.loading_handles.retain(|_path, handle| {
asset_server.get_load_state(handle.id()) != Some(LoadState::Failed)
!matches!(
asset_server.get_load_state(handle.id()),
Some(LoadState::Failed(..))
)
});
let newly_loaded: HashMap<_, _> = self
.loading_handles
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_plugin/src/localization/line_id_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn handle_yarn_file_events(
continue;
}
let asset_path = asset_server
.get_path(handle.clone())
.get_path(handle.id())
.with_context(|| format!("Failed to overwrite Yarn file \"{}\" with new IDs because it was not found on disk",
yarn_file.file_name()))?;
let path = asset_root.0.join(asset_path.path());
Expand Down
24 changes: 11 additions & 13 deletions crates/bevy_plugin/src/localization/strings_file/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::prelude::*;
use anyhow::{anyhow, bail};
use bevy::asset::{io::Reader, AssetLoader, AsyncReadExt, BoxedFuture, LoadContext};
use bevy::asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext};
use bevy::prelude::*;
use bevy::reflect::TypePath;
use bevy::utils::HashMap;
Expand All @@ -23,20 +23,18 @@ impl AssetLoader for StringsFileAssetLoader {
type Asset = StringsFile;
type Settings = ();
type Error = anyhow::Error;
fn load<'a>(
async fn load<'a>(
&'a self,
reader: &'a mut Reader,
reader: &'a mut Reader<'_>,
_settings: &'a (),
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let mut csv_reader = csv::Reader::from_reader(bytes.as_slice());
let records: csv::Result<Vec<_>> = csv_reader.deserialize().collect();
let strings_file = StringsFile::new_with_single_language(records?)?;
Ok(strings_file)
})
_load_context: &'a mut LoadContext<'_>,
) -> Result<Self::Asset, Self::Error> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let mut csv_reader = csv::Reader::from_reader(bytes.as_slice());
let records: csv::Result<Vec<_>> = csv_reader.deserialize().collect();
let strings_file = StringsFile::new_with_single_language(records?)?;
Ok(strings_file)
}

fn extensions(&self) -> &[&str] {
Expand Down
7 changes: 5 additions & 2 deletions crates/bevy_plugin/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Plugin for YarnSpinnerPlugin {
If you really want to load no Yarn files right now and do that later, use `YarnSpinnerPlugin::deferred()` instead.\
If you wanted to load from the default directory instead, use `YarnSpinnerPlugin::default()`.");
app.add_plugins(Self::deferred())
.world
.world_mut()
.send_event(self.project.clone());
}
}
Expand Down Expand Up @@ -236,7 +236,10 @@ impl YarnApp for App {
}

fn register_watching_for_changes(&mut self) -> &mut Self {
let asset_server = self.world.get_resource::<AssetServer>().expect(ASSET_ERROR);
let asset_server = self
.world()
.get_resource::<AssetServer>()
.expect(ASSET_ERROR);

let watching_for_changes = asset_server.watching_for_changes();
self.insert_resource(WatchingForChanges(watching_for_changes))
Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_plugin/tests/test_asset_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn does_not_load_asset_without_localizations() -> Result<()> {
.add_asset_provider(AudioAssetProvider::new())
.build();
dialogue_runner.start_node("Start");
app.world.spawn(dialogue_runner);
app.world_mut().spawn(dialogue_runner);

app.load_project();
let start = Instant::now();
Expand Down Expand Up @@ -61,7 +61,7 @@ fn does_not_load_invalid_asset_id() -> Result<()> {
dialogue_runner
.set_asset_language("en-US")
.start_node("Start");
app.world.spawn(dialogue_runner);
app.world_mut().spawn(dialogue_runner);

app.load_lines();

Expand Down Expand Up @@ -89,13 +89,13 @@ fn loads_asset_from_base_language_localization() -> Result<()> {
.add_asset_provider(AudioAssetProvider::new())
.build();
dialogue_runner.start_node("Start");
app.world.spawn(dialogue_runner);
app.world_mut().spawn(dialogue_runner);
app.load_lines();

let assets = app.dialogue_runner().get_assets_for_id("line:9");
assert_eq!(1, assets.len());
let asset: Handle<AudioSource> = assets.get_handle().unwrap();
let asset_server = app.world.resource::<AssetServer>();
let asset_server = app.world().resource::<AssetServer>();
let path = asset_server.get_path(asset).unwrap();

// Note that this does not contain backslashes on Windows
Expand Down Expand Up @@ -125,13 +125,13 @@ fn loads_asset_from_translated_localization() -> Result<()> {
dialogue_runner
.set_asset_language("de-CH")
.start_node("Start");
app.world.spawn(dialogue_runner);
app.world_mut().spawn(dialogue_runner);
app.load_lines();

let assets = app.dialogue_runner().get_assets_for_id("line:10");
assert_eq!(1, assets.len());
let asset: Handle<AudioSource> = assets.get_handle().unwrap();
let asset_server = app.world.resource::<AssetServer>();
let asset_server = app.world().resource::<AssetServer>();
let path = asset_server.get_path(asset).unwrap();

// Note that this does not contains backslashes on Windows
Expand Down Expand Up @@ -161,7 +161,7 @@ fn panics_on_invalid_language() {
dialogue_runner
.set_asset_language("fr-FR")
.start_node("Start");
app.world.spawn(dialogue_runner);
app.world_mut().spawn(dialogue_runner);
app.load_lines();
}

Expand All @@ -187,7 +187,7 @@ fn does_not_load_asset_with_invalid_type() -> Result<()> {
dialogue_runner
.set_asset_language("en-US")
.start_node("Start");
app.world.spawn(dialogue_runner);
app.world_mut().spawn(dialogue_runner);

app.load_lines();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ fn setup_dialogue_runner_with_localizations(app: &mut App) -> Mut<DialogueRunner
dialogue_runner_builder.add_asset_provider(AudioAssetProvider::new());
}
let dialogue_runner = dialogue_runner_builder.build();
app.world.spawn(dialogue_runner);
app.world
app.world_mut().spawn(dialogue_runner);
app.world_mut()
.query::<&mut DialogueRunner>()
.single_mut(&mut app.world)
.single_mut(app.world_mut())
}

fn english_lines() -> Vec<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn executes_commands_and_fns() -> Result<()> {
]);

app.continue_dialogue_and_update();
let resource = app.world.resource::<Data>().0.as_str();
let resource = app.world().resource::<Data>().0.as_str();
assert_eq!("foo", resource);
assert_events!(asserter, app contains [
PresentLineEvent (n = 0),
Expand Down
22 changes: 15 additions & 7 deletions crates/bevy_plugin/tests/test_strings_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn loads_yarn_assets() {
let yarn_files: Vec<_> = app.load_project().yarn_files().cloned().collect();
assert_eq!(1, yarn_files.len());

let yarn_file_assets = app.world.get_resource::<Assets<YarnFile>>().unwrap();
let yarn_file_assets = app.world().get_resource::<Assets<YarnFile>>().unwrap();
let yarn_file = yarn_file_assets.get(&yarn_files[0]).unwrap();

let expected_source = include_str!("../assets/lines.yarn");
Expand Down Expand Up @@ -65,7 +65,7 @@ fn generates_line_ids() -> anyhow::Result<()> {

let yarn_file = app.load_project().yarn_files().next().unwrap().clone();

let yarn_file_assets = app.world.get_resource::<Assets<YarnFile>>().unwrap();
let yarn_file_assets = app.world().get_resource::<Assets<YarnFile>>().unwrap();
let yarn_file_in_app = yarn_file_assets.get(&yarn_file).unwrap();
let yarn_file_on_disk = fs::read_to_string(&yarn_path)?;

Expand Down Expand Up @@ -169,10 +169,15 @@ fn appends_to_pre_existing_strings_file() -> anyhow::Result<()> {

app.load_project();
let handle = app
.world
.world()
.resource::<AssetServer>()
.load_untyped("dialogue/de-CH.strings.csv");
while app.world.resource::<AssetServer>().get_load_state(&handle) != Some(LoadState::Loaded) {
while app
.world()
.resource::<AssetServer>()
.get_load_state(&handle)
!= Some(LoadState::Loaded)
{
app.update();
}

Expand Down Expand Up @@ -224,10 +229,13 @@ fn replaces_entries_in_strings_file() -> anyhow::Result<()> {

let strings_file_path = dir.path().join("dialogue/de-CH.strings.csv");
{
let project = app.world.resource::<YarnProject>();
let project = app.world().resource::<YarnProject>();
let handle = project.yarn_files().next().unwrap().clone();

let mut yarn_file_assets = app.world.get_resource_mut::<Assets<YarnFile>>().unwrap();
let mut yarn_file_assets = app
.world_mut()
.get_resource_mut::<Assets<YarnFile>>()
.unwrap();
let yarn_file = yarn_file_assets.get_mut(&handle).unwrap();

let strings_file_source =
Expand All @@ -243,7 +251,7 @@ fn replaces_entries_in_strings_file() -> anyhow::Result<()> {
}

while !app
.world
.world()
.resource::<Events<AssetEvent<YarnFile>>>()
.is_empty()
{
Expand Down
18 changes: 9 additions & 9 deletions crates/bevy_plugin/tests/utils/assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ impl EventAsserter {

pub fn clear_events(&mut self, app: &mut App) {
self.present_line_reader
.clear(app.world.resource::<Events<PresentLineEvent>>());
.clear(app.world().resource::<Events<PresentLineEvent>>());
self.present_options_reader
.clear(app.world.resource::<Events<PresentOptionsEvent>>());
.clear(app.world().resource::<Events<PresentOptionsEvent>>());
self.dialogue_start_reader
.clear(app.world.resource::<Events<DialogueStartEvent>>());
.clear(app.world().resource::<Events<DialogueStartEvent>>());
self.dialogue_complete_reader
.clear(app.world.resource::<Events<DialogueCompleteEvent>>());
.clear(app.world().resource::<Events<DialogueCompleteEvent>>());
self.node_start_reader
.clear(app.world.resource::<Events<NodeStartEvent>>());
.clear(app.world().resource::<Events<NodeStartEvent>>());
self.node_complete_reader
.clear(app.world.resource::<Events<NodeCompleteEvent>>());
.clear(app.world().resource::<Events<NodeCompleteEvent>>());
self.line_hints_reader
.clear(app.world.resource::<Events<LineHintsEvent>>());
.clear(app.world().resource::<Events<LineHintsEvent>>());
self.execute_command_reader
.clear(app.world.resource::<Events<ExecuteCommandEvent>>());
.clear(app.world().resource::<Events<ExecuteCommandEvent>>());
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ macro_rules! assert_events {
assert_events!($asserter, $app contains $event (n = 1) $(with $pred)?);
};
($asserter:ident, $app:ident contains $event:ident (n = $num:expr) $(with $pred:expr)?) => {
let events = $app.world.resource::<bevy::prelude::Events<$event>>();
let events = $app.world().resource::<bevy::prelude::Events<$event>>();
let reader = $crate::get_reader!($asserter, $event);
let events: Vec<&$event> = reader.read(&events).collect();
assert_eq!($num, events.len(), "Expected {} events of type {}, but found {}: {events:#?}", stringify!($num), stringify!($event), events.len());
Expand Down
Loading

0 comments on commit 0d89619

Please sign in to comment.