MrGVSV / bevy_proto

Create config files for entities in Bevy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enquiry on simpler custom_loader

hafiidz opened this issue · comments

Is there a way we could do a simple edit of the ron files on the fly without resorting to a full custom loader, especially since this is only planned for some portion of the ron files (i.e. have many different ron file types)?

More detailed use case, wanted to use on_fight vectors from Enemyset to replace children list in EnemyRoot before prototype.load, i.e. the on_flight, might be changed programmatically (on_fight1, on_fight2), or might be a vector of vectors such as in on_fight_alternative

// EnemyRoot.prototype.ron
(
  name: "EnemyRoot",
  schematics: {
    "deck_proto::game::enemy::EnemyRoot": (),
  },
  children: ["EnemySprite", "EnemySprite2"]
)

// EnemysetRoot.prototype.ron
(
  name: "EnemysetRoot",
  schematics: {
    "deck_proto::game::enemy::enemyset::EnemysetRoot": (),
    "deck_proto::app::schematic::Enemyset": (
      // UNIQUE list of enemy that is available in the game
      // TODO, use this list as card list to be loaded during GameState::Init 
      on_fight1: ["EnemySprite", "EnemySprite", "EnemySprite2"],
      on_fight2:  ["EnemySprite2", "EnemySprite", "EnemySprite2"],
      on_fight_alternative:  [["EnemySprite2", "EnemySprite"], ["EnemySprite2"]],

    ),
  }
)

If there is no other choices but to use custom loader, how can I specify custom loader only for a certain portion of the ron file ya? The example .add_plugins(ProtoPlugin::new_with_loader(MyLoader)) will apply custom loader to all files, right? Or it will add this custom loader on top of existing loader?

Alternatively, I might just perform a simple read-write operation via std::fs on the actual ron file on the disk prior to load, hopefully this is not too time consuming ...

To add notes here, I have done some edit to the ECS directly after loading their schematics/ron file already, but as the game grow, I am thinking if I can make the edit before loading, it would save me a lot of codes and potential bug if I can perform the children and other stats/parameters edits just before load.

Just to clarify, are you trying to add/remove new fields programmatically on prototype load? Or are you trying to modify these three sets of fields (on_fight1, on_fight2, and on_fight_alternative) programmatically?

Unless I'm misunderstanding, I don't think Rust allows the first one. Even with custom deserialization logic, you can't add or remove fields on a struct.

For the second option, I don't know if there's a good way of achieving this currently besides using a custom Loader::on_load_prototype implementation. I'm about to start working on parameterized prototypes, which would allow you to load prototypes with pretty much whatever game state/data you want. But I don't have an ETA on when that will land yet.

Just to clarify, are you trying to add/remove new fields programmatically on prototype load? Or are you trying to modify these three sets of fields (on_fight1, on_fight2, and on_fight_alternative) programmatically?

I'm trying to modify the children fields with the value from either on_flight1 or on_flight_alternative.

Noted, in that case I'll work on direct file modification for now, manage to get it working with reasonable speed.

Thank you very much as always, appreciate the insights.