Skip to content

Commit

Permalink
fix: [#453] Add defense to object layer paths (#454)
Browse files Browse the repository at this point in the history
Closes #453
  • Loading branch information
eonarheim authored Aug 10, 2023
1 parent bd019c6 commit 39f8ffa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/tiled-map-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class TiledMap {
}

public getObjects(): TiledObjectGroup[] {
return this.objectGroups.filter(l => !l.getProperty('excalibur-exclude')?.value);
return this.objectGroups.filter(l => !l.getProperty('excalibur-exclude')?.value) ?? [];
}

public getObjectLayerByName(name: string): TiledObjectGroup {
Expand Down Expand Up @@ -122,13 +122,16 @@ export class TiledMap {
let objectlayers = Array.isArray(rawMap.objectgroup) ? rawMap.objectgroup : [rawMap.objectgroup];
for (let objectlayer of objectlayers) {
objectlayer.type = objectlayer.type ?? 'objectgroup';
objectlayer.objects = Array.isArray(objectlayer.object) ? objectlayer.object : [objectlayer.object];
objectlayer.objects.forEach((o: any) => o.properties = o.properties?.property ?? []);
objectlayer.objects.forEach((o: any) => _convertToArray(o, 'properties'));
objectlayer.properties = objectlayer.properties?.property ?? [];

_convertToArray(objectlayer, 'properties');
delete objectlayer.object;
if (objectlayer.object) {
objectlayer.objects = Array.isArray(objectlayer.object) ? objectlayer.object : [objectlayer.object];
objectlayer.objects.forEach((o: any) => o.properties = o.properties?.property ?? []);
objectlayer.objects.forEach((o: any) => _convertToArray(o, 'properties'));
delete objectlayer.object;
} else {
continue;
}

for (let object of objectlayer.objects) {
if (object.text) {
Expand Down
4 changes: 2 additions & 2 deletions src/tiled-map-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class TiledMapResource implements Loadable<TiledMap> {

private _addTiledText(scene: Scene) {
const excaliburObjectLayers = this.data?.getObjects();
if (excaliburObjectLayers.length > 0) {
if (excaliburObjectLayers && excaliburObjectLayers.length > 0) {
for (const objectLayer of excaliburObjectLayers) {
const textObjects = objectLayer.getText();
for (const text of textObjects) {
Expand Down Expand Up @@ -245,7 +245,7 @@ export class TiledMapResource implements Loadable<TiledMap> {

private _addTiledInsertedTiles(scene: Scene) {
const excaliburObjectLayers = this.data?.getObjects();
if (excaliburObjectLayers.length > 0) {
if (excaliburObjectLayers && excaliburObjectLayers.length > 0) {
for (const objectLayer of excaliburObjectLayers) {
const inserted = objectLayer.getInsertedTiles();
for (const tile of inserted) {
Expand Down

0 comments on commit 39f8ffa

Please sign in to comment.