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

BasicCrafting and Genome at GenomeAuthoritySystem #119

Closed
DarkWeird opened this issue Aug 13, 2021 · 1 comment · Fixed by #120
Closed

BasicCrafting and Genome at GenomeAuthoritySystem #119

DarkWeird opened this issue Aug 13, 2021 · 1 comment · Fixed by #120

Comments

@DarkWeird
Copy link
Contributor

Genome and BasicCrafting modules is optional dependencies for SimpleFarming.
Both modules using at GenomeAuthoritySystem,
then GenomeAuthoritySystem loads(works) when both modules is active.

Suggestions:

  1. extract BasicCrafting usage from GenomeAuthoritySystem, if BasicCrafting and Genome can be using separately there.
  2. or enrich class with java docs, which explain that this system using both modules together only.
@skaldarnar
Copy link
Contributor

The only event handler integrating with Basic Crafting is onRecipeCraftedEvent, which only works if Genome is also active.

@ReceiveEvent
public void onRecipeCraftedEvent(OnRecipeCrafted event, EntityRef entity) {
EntityRef ingredients[] = event.getIngredients();
if (ingredients.length != 2) {
return;
}
if (!(ingredients[0].hasComponent(GenomeComponent.class) || ingredients[1].hasComponent(GenomeComponent.class))) {
return;
}
SimpleGenomeManager genomeManager = new SimpleGenomeManager();
boolean result = genomeManager.applyBreeding(ingredients[0], ingredients[1], entity);
if (entity.hasComponent(GenomeComponent.class)) {
GenomeMap genomeMap =
genomeRegistry.getGenomeDefinition(entity.getComponent(GenomeComponent.class).genomeId).getGenomeMap();
float fillingModifier = genomeMap.getProperty("filling", entity.getComponent(GenomeComponent.class).genes,
Float.class);
float newFilling = entity.send(new ModifyFilling(fillingModifier)).filling.getValue();
entity.send(new ModifyTint(newFilling));
}
}

We can split this system into two:

  • GenomeExtensionAuthoritySystem (works if at least Genome is loaded)
  • GenomeCraftingExtensionAuthoritySystem (works if both Genome and Basic Crafting are loaded)

I haven't looked at the details to figure out whether the genome-only features only make sense if crafting is also enabled, though.

skaldarnar added a commit that referenced this issue Aug 13, 2021
The integration with Genome and BasicCrafting is optional for SimpleFarming.

As a component system can only be loaded properly if all it's dependencies are also active, this means that the combined `GenomeAuthoritySystem` is only loaded if **both** Genome and BasicCrafting are active.

By splitting the authority system into `GenomeExtensionAuthoritySystem` and `GenomeCraftingExtensionAuthoritySystem` each extension system can run with the minimal set of required modules.

- `GenomeExtensionAuthoritySystem` (works if at least Genome is loaded)
- `GenomeCraftingExtensionAuthoritySystem` (works if both Genome and Basic Crafting are loaded)

Fixes #119
skaldarnar added a commit that referenced this issue Aug 16, 2021
* feat: split GenomeAuthoritySystem based on modules
* feat: add 'requiresOptional' annotation metadata to genome extension systems

The integration with Genome and BasicCrafting is optional for SimpleFarming.

As a component system can only be loaded properly if all it's dependencies are also active, this means that the combined `GenomeAuthoritySystem` is only loaded if **both** Genome and BasicCrafting are active.

By splitting the authority system into `GenomeExtensionAuthoritySystem` and `GenomeCraftingExtensionAuthoritySystem` each extension system can run with the minimal set of required modules.

- `GenomeExtensionAuthoritySystem` (works if at least Genome is loaded)
- `GenomeCraftingExtensionAuthoritySystem` (works if both Genome and Basic Crafting are loaded)

Fixes #119

Co-authored-by: vedant-shroff <[email protected]>
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

Successfully merging a pull request may close this issue.

2 participants