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"] }