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

Any Way to support nested define GameAssets structure? #246

Open
kyrosle opened this issue Nov 30, 2024 · 3 comments
Open

Any Way to support nested define GameAssets structure? #246

kyrosle opened this issue Nov 30, 2024 · 3 comments

Comments

@kyrosle
Copy link

kyrosle commented Nov 30, 2024

now i put all assets hanndlers in a struct GameAssets, can i split to the corresponding module's assets mod?

@NiklasEi
Copy link
Owner

Could you give an example of what you want your asset collection to look like?

@kyrosle
Copy link
Author

kyrosle commented Nov 30, 2024

In my earliest game development, I only considered one type of player assets. However, after wanting to add more player assets into my game, if I continue adding other player assets into the same GameAssets structure, it will make the fields grow more and more, as shown in this code:

#[derive(AssetCollection, Resource)]
pub struct GameAssets {
  // -- PLAYER ---
  #[asset(texture_atlas(
    tile_size_x = 80,
    tile_size_y = 80,
    columns = 23,
    rows = 5
  ))]
  pub player_layout: Handle<TextureAtlasLayout>,
  #[asset(path = "player/player.png")]
  pub player_sprite: Handle<Image>,
  #[asset(
    paths(
      "player/player.trickfilm#idle",
      "player/player.trickfilm#moving",
      "player/player.trickfilm#dashing",
      "player/player.trickfilm#hooking",
      "player/player.trickfilm#sliding",
    ),
    collection(typed)
  )]
  pub player_animations: Vec<Handle<AnimationClip2D>>,

  #[asset(texture_atlas(
    tile_size_x = 192,
    tile_size_y = 192,
    columns = 10,
    rows = 23,
  ))]
  pub player02_layout: Handle<TextureAtlasLayout>,
  #[asset(path = "player/player02.png")]
  pub player02_sprite: Handle<Image>,
  #[asset(
    paths(
      "player/player02.trickfilm#heal",
      "player/player02.trickfilm#defence",
      "player/player02.trickfilm#flames",
      "player/player02.trickfilm#buff",
    ),
    collection(typed)
  )]
  pub player02_animations: Vec<Handle<AnimationClip2D>>,

Can I put some related resource content into a structure, and then use fields to store it in GameStore(using like assets.player_module.player_sprite), while also being able to use macros?

@NiklasEi
Copy link
Owner

There is no support for nested asset collections at the moment. In this case, I would prefer to split your collection by "domain". Why not create an AssetCollection PlayerAssets? You can load any number of asset collections in a loading state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants