@@ -556,12 +556,10 @@ class JSWindow extends Rectangle { /*collapseit*/
556556 showing : boolean ;
557557 hiding : boolean ;
558558 container : { [ key : string ] : any } ;
559- parent ? : JSWindow | GameState ;
559+ # parent: JSWindow | GameState | undefined ;
560560 constructor ( width : number , height : number ) {
561561 const canvas = ( window as any ) . globals . canvas ;
562- // By default the JSWindow is centered in the canvas. If a parent is
563- // supplied we'll initialize relative to the parent's coordinates.
564- super ( canvas . width / 2 - width / 2 , - height , width , height ) ;
562+ super ( canvas . width / 2 - width / 2 , - height , width , height ) ;
565563 this . color = "#1062e8" ;
566564 this . outlinePosition = "inner" ;
567565 this . maxYMoveSpeed = 40 ;
@@ -578,6 +576,19 @@ class JSWindow extends Rectangle { /*collapseit*/
578576 }
579577 } ) ;
580578 this . parent = undefined ;
579+ Object . defineProperty ( this , 'parent' , {
580+ enumerable : true ,
581+ configurable : true ,
582+ get : ( ) => this . #parent,
583+ set : ( value : JSWindow | GameState | undefined ) => {
584+ this . #parent = value ;
585+ if ( value instanceof JSWindow || value instanceof GameState ) {
586+ const canvas = ( window as any ) . globals . canvas ;
587+ this . x = - value . x + canvas . width / 2 - this . width / 2 ;
588+ this . y = - value . y - this . height ;
589+ }
590+ } ,
591+ } ) ;
581592 }
582593 draw ( ) { /*collapseit*/
583594 const ctx = ( window as any ) . globals . canvas . getContext ( '2d' ) as CanvasRenderingContext2D ;
0 commit comments