From 8cbf0f286deb1756d5dab5653b5bf5a646717c37 Mon Sep 17 00:00:00 2001 From: Nathan Laing Date: Wed, 14 May 2025 22:06:56 +1200 Subject: [PATCH 1/7] Fix `strictNullChecks` in `TileTextureArray.ts` - `text_sizes` is assigned in constructor so doesn't need null assignment - `tex_buf` is also assigned in constructor - `bind_group` has null check in `getBindGroup()` - added `| null` to `bind_group` to accurately reflect typing --- src/TileTextureArray.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TileTextureArray.ts b/src/TileTextureArray.ts index b490007..943abaa 100644 --- a/src/TileTextureArray.ts +++ b/src/TileTextureArray.ts @@ -16,11 +16,11 @@ export class TileTextureArray count = 0; dirty = false; dirty_gpu = false; - bind_group: BindGroup = null; + bind_group: BindGroup | null = null; bind_group_resources: any = {}; - tex_sizes: Float32Array = null; + tex_sizes: Float32Array; null_color: Float32Array = new Float32Array([0, 0, 0, 0.5]); - tex_buf: Buffer = null; + tex_buf: Buffer; get length() { From 0227758a5cae8f755d4146ddd59311c66be0c66a Mon Sep 17 00:00:00 2001 From: Nathan Laing Date: Wed, 14 May 2025 22:43:52 +1200 Subject: [PATCH 2/7] Fix `strictNullChecks` in `TilemapPipe.ts` Breaking Change: - changed return type of `getShader()` - `indexBuffer` can be made readonly and type kept as it's assigned in constructor - added `| null` to `shader` --- src/TilemapPipe.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TilemapPipe.ts b/src/TilemapPipe.ts index f5c930d..dcae797 100644 --- a/src/TilemapPipe.ts +++ b/src/TilemapPipe.ts @@ -52,10 +52,10 @@ export class TilemapPipe implements RenderPipe, InstructionPipe, InstructionPipe Date: Wed, 14 May 2025 22:47:02 +1200 Subject: [PATCH 3/7] Add check for undefined instructionSet in `TilemapPipe.ts` --- src/TilemapPipe.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TilemapPipe.ts b/src/TilemapPipe.ts index dcae797..f229a76 100644 --- a/src/TilemapPipe.ts +++ b/src/TilemapPipe.ts @@ -142,7 +142,7 @@ export class TilemapPipe implements RenderPipe, InstructionPipe Date: Wed, 14 May 2025 22:48:30 +1200 Subject: [PATCH 4/7] Fix typing of `tilemap` variable --- src/CompositeTilemap.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CompositeTilemap.ts b/src/CompositeTilemap.ts index 5b6ef0a..8302c75 100644 --- a/src/CompositeTilemap.ts +++ b/src/CompositeTilemap.ts @@ -233,7 +233,7 @@ export class CompositeTilemap extends Container } = {} ): this { - let tilemap: Tilemap = null; + let tilemap: Tilemap | null = null; const children = this.children; this.lastModifiedTilemap = null; From e52a68a251500ab661eb085848df20171b9da81f Mon Sep 17 00:00:00 2001 From: Nathan Laing Date: Wed, 14 May 2025 22:51:32 +1200 Subject: [PATCH 5/7] Fix typing of private vb arrays in `Tilemap.ts` - adjusts typing to reflect assigned types --- src/Tilemap.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Tilemap.ts b/src/Tilemap.ts index c8b8568..8756b30 100644 --- a/src/Tilemap.ts +++ b/src/Tilemap.ts @@ -402,9 +402,9 @@ export class Tilemap extends ViewContainer private vbId = 0; vb: TilemapGeometry = null; - private vbBuffer: ArrayBuffer = null; - private vbArray: Float32Array = null; - private vbInts: Uint32Array = null; + private vbBuffer: ArrayBuffer | null = null; + private vbArray: Float32Array | null = null; + private vbInts: Uint32Array | null = null; private destroyVb(): void { @@ -459,8 +459,8 @@ export class Tilemap extends ViewContainer this.vbInts = new Uint32Array(this.vbBuffer); } - const arr = this.vbArray; - const ints = this.vbInts; + const arr = this.vbArray ?? new Float32Array(this.vbBuffer); + const ints = this.vbInts ?? new Uint32Array(this.vbBuffer); let sz = 0; let textureId = 0; From e7f66a660428a94c4b84ecb3b887ecb4209c2937 Mon Sep 17 00:00:00 2001 From: Nathan Laing Date: Wed, 14 May 2025 22:54:40 +1200 Subject: [PATCH 6/7] Fix strictNullCheck typing changes in public api - doesn't change the initial values of any of the variables - adds `| null` where `null` was assigned - adds `null` checks ^ would want opinion in review if position of these checks makes sense --- src/CompositeTilemap.ts | 6 +++--- src/Tilemap.ts | 6 +++--- src/TilemapPipe.ts | 2 +- src/gl_tilemap.ts | 8 +++++--- src/gpu_tilemap.ts | 22 +++++++++++++++++----- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/CompositeTilemap.ts b/src/CompositeTilemap.ts index 8302c75..7158d08 100644 --- a/src/CompositeTilemap.ts +++ b/src/CompositeTilemap.ts @@ -74,10 +74,10 @@ export class CompositeTilemap extends Container * The animation frame vector specifies which animation frame texture to use. If the x/y coordinate is * larger than the `animCountX` or `animCountY` for a specific tile, the modulus is taken. */ - public tileAnim: [number, number] = null; + public tileAnim: [number, number] | null = null; /** The last modified tilemap. */ - protected lastModifiedTilemap: Tilemap = null; + protected lastModifiedTilemap: Tilemap | null = null; private modificationMarker = 0; // private shadowColor = new Float32Array([0.0, 0.0, 0.0, 0.5]); @@ -103,7 +103,7 @@ export class CompositeTilemap extends Container * * @param tileTextures - The list of tile textures that make up the tileset. */ - tileset(tileTextures: Array): this + tileset(tileTextures?: Array): this { if (!tileTextures) { diff --git a/src/Tilemap.ts b/src/Tilemap.ts index 8756b30..227b4cd 100644 --- a/src/Tilemap.ts +++ b/src/Tilemap.ts @@ -94,7 +94,7 @@ export class Tilemap extends ViewContainer * * @see CompositeTilemap.tileAnim */ - public tileAnim: [number, number] = null; + public tileAnim: [number, number] | null = null; /** * This is the last uploaded size of the tilemap geometry. @@ -134,7 +134,7 @@ export class Tilemap extends ViewContainer this._bounds.maxY = bounds.maxY; } - public batched: boolean; + public batched = false; /** * @param tileset - The tileset to use for the tilemap. This can be reset later with {@link Tilemap.setTileset}. The @@ -401,7 +401,7 @@ export class Tilemap extends ViewContainer } private vbId = 0; - vb: TilemapGeometry = null; + vb: TilemapGeometry | null = null; private vbBuffer: ArrayBuffer | null = null; private vbArray: Float32Array | null = null; private vbInts: Uint32Array | null = null; diff --git a/src/TilemapPipe.ts b/src/TilemapPipe.ts index f229a76..e9b3b4b 100644 --- a/src/TilemapPipe.ts +++ b/src/TilemapPipe.ts @@ -130,7 +130,7 @@ export class TilemapPipe implements RenderPipe, InstructionPipe Date: Wed, 14 May 2025 22:55:05 +1200 Subject: [PATCH 7/7] Turn `strictNullChecks` on --- tsconfig.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index afa5e75..3925d90 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,7 @@ { "extends": "@pixi/extension-scripts/tsconfig", "compilerOptions": { - // TODO: Remove this when null checks are strict - "strictNullChecks": false + "strictNullChecks":true }, "include": [ "src/**/*"