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

Mark Dice as Custom or Standard #630

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/D.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { isCustomSides } from '~guards'
import { DicePoolType } from '~types'

type Type<T> = T extends string[] ? DicePoolType.custom : DicePoolType.standard
type Faces<T> = T extends string[] ? T : number[]
type Result<T> = T extends number[] ? number : string
type Result<F> = F extends number[] ? number : string

class D<Sides extends string[] | number> {
sides: number
faces: Faces<Sides>
type: Type<Sides>

constructor(sides: Sides) {
if (isCustomSides(sides)) {
this.sides = sides.length
this.type = DicePoolType.custom as Type<Sides>
this.faces = sides as Faces<Sides>
return
}
this.sides = sides
this.type = DicePoolType.standard as Type<Sides>
this.faces = Array.from(
{ length: Number(sides) },
(_, index) => index + 1
Expand Down
Loading