grid shenanigans

This commit is contained in:
koneko 2024-09-17 00:54:20 +02:00
parent 2d8616b107
commit 53f8d61de0
2 changed files with 38 additions and 2 deletions

30
src/classes/Grid.ts Normal file
View File

@ -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();
}
}

View File

@ -11,7 +11,13 @@
"allowImportingTsExtensions": true, "allowImportingTsExtensions": true,
"isolatedModules": true, "isolatedModules": true,
"moduleDetection": "force", "moduleDetection": "force",
"noEmit": true "noEmit": true,
"noImplicitAny": false,
"esModuleInterop": true,
"strict": false,
"allowJs": true,
"checkJs": false
}, },
"include": ["src"] "include": ["src/**/*"],
"exclude": ["node_modules", "build"]
} }