import type { ShapeOptions , ShapeType } from "./Shapes" ; import { SHAPES } from "./Shapes" ; import type { ShapeObject , ShapeRenderable } from "kittik-shape-basic" ; export class ShapeBuilder < T extends ShapeType , O extends ShapeOptions < T > > implements ShapeObject < T , O > { public type : T ; public options : O ; public constructor ( type ) { this . type = type ; this . options = { } as unknown as O ; } public static start < T extends ShapeType , O extends ShapeOptions < T > > ( type ) { return new this ( type ) ; } public withType ( type ) { this . type = type ; return this ; } public withOptions ( options ) { this . options = { ... this . options , ... options } ; return this ; } public withText ( text ) { this . options . text = text ; return this ; } public withX ( x ) { this . options . x = x ; return this ; } public withY ( y ) { this . options . y = y ; return this ; } public withWidth ( width ) { this . options . width = width ; return this ; } public withHeight ( height ) { this . options . height = height ; return this ; } public withBackground ( background ) { this . options . background = background ; return this ; } public withForeground ( foreground ) { this . options . foreground = foreground ; return this ; } public end ( ) { const ctr = SHAPES . get ( this . type ) ; if ( typeof ctr === "undefined" ) { throw new Error ( `You tried to build a shape with the type "${ this . type }". ` + "But the shape of this type is not implemented or you made a typo." ) ; } return ctr . fromObject < T , O , ShapeRenderable > ( this ) ; } }