M crates/unified/assets/config/recipes.rc.toml => crates/unified/assets/config/recipes.rc.toml +2 -2
@@ 1,7 1,7 @@
[recipes]
Frame = [
- { Silicon = 10 }
+ { order = 0, inputs = { Silicon = 10 } }
]
Thruster = [
- { Silicon = 20, Carbon = 20 }
+ { order = 1, inputs = { Silicon = 20, Carbon = 20 } }
]
M crates/unified/src/client/crafting/ui.rs => crates/unified/src/client/crafting/ui.rs +42 -17
@@ 161,23 161,7 @@ fn initial_create_recipe_list(
if let Some(strong_recipes_config) = recipes_config.get(&recipe_collection.handle.clone().unwrap()) {
for recipe_holder in &added_recipes_holders {
let mut recipe_holder = commands.get_entity(recipe_holder).unwrap();
- for (module_name, recipes) in &strong_recipes_config.recipes {
- for recipe in recipes {
- let resource_list = recipe.iter()
- .map(|(resource_name, quantity)| format!("{} {}", quantity, resource_name))
- .collect::<Vec<_>>().join(", ");
- recipe_holder.with_child((
- Node {
- ..Default::default()
- },
- TextFont {
- font_size: 10.0,
- ..Default::default()
- },
- Text::new(format!("{}: {}", module_name, resource_list)),
- ));
- }
- }
+ create_recipe_list(&mut recipe_holder, strong_recipes_config);
recipe_holder
.insert(RecipesHolder)
.remove::<PendingRecipesHolder>();
@@ 187,6 171,9 @@ fn initial_create_recipe_list(
fn update_recipe_list(
mut ev_config: MessageReader<AssetEvent<RecipesConfig>>,
recipe_collection: ResMut<RecipeCollection>,
+ assets: ResMut<Assets<RecipesConfig>>,
+ mut commands: Commands,
+ recipes_holders: Query<Entity, With<RecipesHolder>>,
) {
let Some(handle) = recipe_collection.handle.as_ref() else {
return
@@ 196,10 183,48 @@ fn update_recipe_list(
if let AssetEvent::Modified { id } = ev {
if *id == handle.id() {
debug!("recipe list config modified - reloading lists");
+ let strong_recipes_config = assets.get(*id).unwrap();
+ for recipe_holder in &recipes_holders {
+ let mut recipe_holder = commands.get_entity(recipe_holder).unwrap();
+ recipe_holder.despawn_children();
+ create_recipe_list(&mut recipe_holder, strong_recipes_config);
+ }
}
}
}
}
+fn create_recipe_list(
+ recipe_holder: &mut EntityCommands,
+ strong_recipes_config: &RecipesConfig,
+) {
+ let mut ui_recipes = Vec::new();
+ for (module_name, recipes) in &strong_recipes_config.recipes {
+ for recipe in recipes {
+ let resource_list = recipe.inputs.iter()
+ .map(|(resource_name, quantity)| format!("{} {}", quantity, resource_name))
+ .collect::<Vec<_>>().join(", ");
+ ui_recipes.push((
+ recipe.order,
+ (Node {
+ ..Default::default()
+ },
+ TextFont {
+ font_size: 10.0,
+ ..Default::default()
+ },
+ Text::new(format!("{}: {}", module_name, resource_list)))
+ ));
+ }
+ }
+ // ordering stuff
+ ui_recipes.sort_by(|a, b| a.0.cmp(&b.0));
+ let ui_recipes = ui_recipes.iter().map(|recipe| &recipe.1).collect::<Vec<_>>();
+ recipe_holder.with_children(move |parent| {
+ for recipe in ui_recipes {
+ parent.spawn(recipe.clone());
+ }
+ });
+}
fn drill_button(
mut interaction_query: Query<
M crates/unified/src/config/recipe.rs => crates/unified/src/config/recipe.rs +4 -3
@@ 7,10 7,11 @@ use crate::prelude::*;
#[derive(Deserialize, Asset, TypePath, Component, Serialize, Clone, Debug)]
#[require(Replicated)]
pub struct RecipesConfig {
- pub recipes: HashMap<String, Vec<HashMap<String, u32>>>,
+ pub recipes: HashMap<String, Vec<Recipe>>,
}
-/*#[derive(Deserialize, TypePath, Component, Serialize, Clone, Debug)]
+#[derive(Deserialize, TypePath, Component, Serialize, Clone, Debug)]
pub struct Recipe {
+ pub order: usize,
pub inputs: HashMap<String, u32>,
-}*/
+}