Skip to content

Commit

Permalink
Merge pull request #429 from Annoraaq/feature/#408-improve-error-msg
Browse files Browse the repository at this point in the history
#408 throw error
  • Loading branch information
Annoraaq committed Aug 9, 2023
2 parents 36bc618 + 9bf39ab commit bfd32c7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/GridTilemap/Phaser/PhaserTilemap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,32 @@ describe("PhaserTilemap", () => {
);
}
});

it("should throw error if initialized without tilemapLayer", () => {
const tilemap = createPhaserTilemapStub(
new Map([["layer_name", ["..", ".."]]])
);
const tiledProject = {
propertyTypes: [
{
name: "SomeTiledClass",
type: "class",
members: [
{
name: "testProp",
type: "boolean",
value: true,
},
],
},
],
};
// @ts-ignore
tilemap.layers[0].tilemapLayer = undefined;
expect(() => new PhaserTilemap(tilemap, tiledProject)).toThrow(
new Error(
"Error initializing tilemap. Layer 'layer_name' has no 'tilemapLayer'. This can happen if you call 'createLayer' with the wrong layer ID."
)
);
});
});
10 changes: 9 additions & 1 deletion src/GridTilemap/Phaser/PhaserTilemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ export class PhaserTilemap implements Tilemap {
constructor(
private phaserTilemap: Phaser.Tilemaps.Tilemap,
private tiledProject?: TiledProject
) {}
) {
for (const l of this.phaserTilemap.layers) {
if (l.tilemapLayer == null) {
throw new Error(
`Error initializing tilemap. Layer '${l.name}' has no 'tilemapLayer'. This can happen if you call 'createLayer' with the wrong layer ID.`
);
}
}
}

getTileWidth(): number {
return this.phaserTilemap.tileWidth;
Expand Down

0 comments on commit bfd32c7

Please sign in to comment.