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

Use the global references to the Roll classes instead of the imported ones #1097

Closed
aaclayton opened this issue May 3, 2021 · 6 comments
Closed
Assignees
Labels

Comments

@aaclayton
Copy link
Contributor

Originally in GitLab by @Moerill

While i do like the new DamageRoll and D20Rollclasses, they make it more difficult to modify rolling behaviour for modules without having to use prototype patching.

What i've been doing previously

I created my own Rollclass Mars5eRolland replaced the global reference to the original Rollclass with my own one and everything worked fine without resulting to prototype patching. While still being a bit hacky (by replacing the global reference to a class), i found this solution to be cleaner and more easily maintainable.

The new issue

The introduction of the DamageRoll and D20Roll classes in theory allow for better moddability and modification of the rolling behaviour. In reality though a module can't intercept the usage of those classes and inject a custom class, since all references i found in the code only reference the imported classes, not the global class references in game.dnd5e.dice. So currently one would have to rely on hacky prototype patching, since this is the only way of modifying the behaviour of these classes.

My proposed solution

Instead of using imported references to the DamageRoll and D20Rollclasses, use the global references in game.dnd5e.dice. These references do already exist, but are currently not used.

This way i (or other modders wanting to modify this) could do smth like this and be done:

Hooks.on('init', () => {
  class Mars5eDamageRoll extends game.dnd5e.dice.DamageRoll {
     // Do whatever customizations i desire
  }
  game.dnd5e.dice.DamageRoll = Mars5eDamageRoll;
});

If this proposal gets accepted i'd of course be willing to put this "Find and Replace" in a quick MR, with any changes proposed in a possible discussion here!

@aaclayton
Copy link
Contributor Author

I think in general the proposal is a good one, but I don't want the process for modules to override the class to be changing what is exposed within game.dnd5e - which should always provide references to the original classes in case they are needed.

Why don't we use a similar approach that is used for other classes of assigning something to the global CONFIG object instead. Perhaps something like CONFIG.Dice.d20Roll = D20Roll and CONFIG.Dice.damageRoll = DamageRoll and then reference the configured implementations there instead?

@aaclayton
Copy link
Contributor Author

Originally in GitLab by @Moerill

This is a good change in the proposal and does make sense!

Should i go and create a MR as soon as i find some time?

@aaclayton
Copy link
Contributor Author

Please feel free!

@aaclayton
Copy link
Contributor Author

Originally in GitLab by @Moerill

Thanks for the quick reactions before ! :)

@aaclayton
Copy link
Contributor Author

mentioned in commit 065e9c9

@aaclayton
Copy link
Contributor Author

mentioned in commit 37b404c

@aaclayton aaclayton self-assigned this Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant