Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Unnecessary Closure & Log Message #64

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ impl AssetLoader for GameMetaLoader {
.insert(font_name.clone(), font_handle);
}

error!("Locale paths: {:?}", locale_paths);

load_context.set_default_asset(
LoadedAsset::new(meta)
.with_dependencies(vec![start_level_path, main_menu_background_path])
Expand Down
45 changes: 20 additions & 25 deletions src/localization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,6 @@ fn load_locales(
mut events: EventReader<AssetEvent<BundleAsset>>,
assets: Res<Assets<BundleAsset>>,
) {
// Helper to rebuild the localization
let mut reload_localization = || {
let mut new_localization = Localization::new();

// Create map containing the bundles and their handles, indexed by their locale
let mut bundles = assets
.iter()
.map(|(handle_id, asset)| (&asset.locales[0], (handle_id, asset)))
.collect::<HashMap<_, _>>();

// Extract sorted list of locales in a fallback chain
let locales = locale.fallback_chain(bundles.keys().cloned());

// Insert bundles into the localization in sorted order
for locale in locales {
if let Some((handle_id, bundle)) = bundles.remove(locale) {
new_localization.insert(&Handle::weak(handle_id), bundle);
}
}

// Update the localization resource
*localization = new_localization;
};

// Whether there was an update that means we need to rebuild the localization
let mut should_rebuild_localization = false;

Expand Down Expand Up @@ -84,6 +60,25 @@ fn load_locales(

// Rebuild localization if anything was updated
if should_rebuild_localization {
reload_localization();
let mut new_localization = Localization::new();

// Create map containing the bundles and their handles, indexed by their locale
let mut bundles = assets
.iter()
.map(|(handle_id, asset)| (&asset.locales[0], (handle_id, asset)))
.collect::<HashMap<_, _>>();

// Extract sorted list of locales in a fallback chain
let locales = locale.fallback_chain(bundles.keys().cloned());

// Insert bundles into the localization in sorted order
for locale in locales {
if let Some((handle_id, bundle)) = bundles.remove(locale) {
new_localization.insert(&Handle::weak(handle_id), bundle);
}
}

// Update the localization resource
*localization = new_localization;
}
}