Skip to content

Commit c1d3053

Browse files
committed
Make initial JSWindow coords relative to parent
1 parent 554f4b1 commit c1d3053

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/JSTools.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

src/Monopoly/Initialization.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Place } from "./Classes";
21
import { element, resizeCanvas, getCookie, backToIndex } from "../JSTools";
32
import { setLanguage } from "../languages/Monopoly";
43
import '../globals';

0 commit comments

Comments
 (0)