From 53f8d61de06894458e8fe4a351ba0d6e03c0a64a Mon Sep 17 00:00:00 2001 From: koneko <67551503+koneko@users.noreply.github.com> Date: Tue, 17 Sep 2024 00:54:20 +0200 Subject: [PATCH] grid shenanigans --- src/classes/Grid.ts | 30 ++++++++++++++++++++++++++++++ tsconfig.json | 10 ++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/classes/Grid.ts diff --git a/src/classes/Grid.ts b/src/classes/Grid.ts new file mode 100644 index 0000000..15c3101 --- /dev/null +++ b/src/classes/Grid.ts @@ -0,0 +1,30 @@ +import * as PIXI from "pixi.js"; + +export class Grid { + public rows: number; + public columns: number; + public gridObject: PIXI.Container; + constructor(x, y, width, height, rows, columns) { + this.rows = rows; + this.columns = columns; + this.gridObject = new PIXI.Container({ + width: width, + height: height, + x: x, + y: y, + }); + } + + getPixelScalingFactor() { + const pixelScaleX = this.gridObject.width / this.columns; + const pixelScaleY = this.gridObject.height / this.rows; + return pixelScaleX < pixelScaleY ? pixelScaleX : pixelScaleY; + } + + gridUnitsToPixels(amount: number): number { + return amount * this.getPixelScalingFactor(); + } + pixelsToGridUnits(pixels: number): number { + return pixels / this.getPixelScalingFactor(); + } +} diff --git a/tsconfig.json b/tsconfig.json index f11a60b..5837dc5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,13 @@ "allowImportingTsExtensions": true, "isolatedModules": true, "moduleDetection": "force", - "noEmit": true + "noEmit": true, + "noImplicitAny": false, + "esModuleInterop": true, + "strict": false, + "allowJs": true, + "checkJs": false }, - "include": ["src"] + "include": ["src/**/*"], + "exclude": ["node_modules", "build"] }