grid shenanigans
This commit is contained in:
parent
2d8616b107
commit
53f8d61de0
30
src/classes/Grid.ts
Normal file
30
src/classes/Grid.ts
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -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"]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user