Samasaur1 / DiceKit

A Swift module for simulating dice both real and unreal
https://samasaur1.github.io/DiceKit/
Academic Free License v3.0
4 stars 4 forks source link

Allow the use of all Rollables in Dice #85

Open Samasaur1 opened 4 years ago

Samasaur1 commented 4 years ago

Is your feature request related to a problem? Please describe.

It doesn't make a lot of sense that WeightedDie cannot be used in Dice, and in a larger sense why any Rollable can't be. Rollable requires implementations of what I'm pretty sure are all the rolling/probabilities methods that Die has that Dice uses. It requires looking into, and refactoring some parts of Dice, but it seems like an overdue feature.

Describe the solution you'd like:

Users should be able to use and Rollable type in Dice. This includes the initializers (probably excluding the dice notation String-based initializer), operators, and pretty much everywhere else.

Describe alternatives you've considered:

Maybe Dice should only allow WeightedDie/Rollable types that I define, but that seems overly restrictive. That's what having a protocol is for.

Samasaur1 commented 2 years ago

Especially considering that we convert the dice dictionary to an array before performing calculations anyway:

https://github.com/Samasaur1/DiceKit/blob/5e29f5959818b3322f1905ad7b86c1d887d6b21b/Sources/DiceKit/Dice.swift#L385-L392

and when rolling we need to "expand" the dictionary anyway:

https://github.com/Samasaur1/DiceKit/blob/5e29f5959818b3322f1905ad7b86c1d887d6b21b/Sources/DiceKit/Dice.swift#L313-L322

I see no reason why we shouldn't convert the dice dictionary to (presumably) an any Rollable array