fixed linting

This commit is contained in:
Johannes Berthel 2021-04-09 22:09:36 +02:00 committed by Thomas Basler
parent a0f1f0c04b
commit 5ae8bfe06b
1 changed files with 16 additions and 14 deletions

View File

@ -11,7 +11,11 @@ interface SpriteEntity {
animation: string|false; animation: string|false;
sprite: Sprite; sprite: Sprite;
state: boolean; state: boolean;
properties: { reverseInactive: boolean; } | undefined; properties: TileProperties | undefined;
}
interface TileProperties {
reverseInactive: boolean;
} }
interface TileAnimation { interface TileAnimation {
@ -216,8 +220,8 @@ export class InteractiveLayer extends Container {
if (animation !== null) { if (animation !== null) {
// if an animation was found, add each frame to the image (if it doesn't already exist) // if an animation was found, add each frame to the image (if it doesn't already exist)
if (typeof scene.anims.get(key) === "undefined") { if (typeof scene.anims.get(key) === "undefined") {
for (const j in animation) { for (const anim of animation) {
this.addFrameToTilesetImage(tileset, String(animation[j].tileid), animation[j].tileid + tileset.firstgid); this.addFrameToTilesetImage(tileset, String(anim.tileid), anim.tileid + tileset.firstgid);
} }
scene.anims.create({ scene.anims.create({
@ -246,7 +250,7 @@ export class InteractiveLayer extends Container {
animation: animation === null ? false : key, animation: animation === null ? false : key,
sprite, sprite,
state: false, state: false,
properties: tileset.getTileProperties(index) as any properties: tileset.getTileProperties(index) as TileProperties | undefined
}); });
} }
} }
@ -263,9 +267,7 @@ export class InteractiveLayer extends Container {
private getTilesetContainingTile(index: number): Tileset|null { private getTilesetContainingTile(index: number): Tileset|null {
const scene = this.getScene(); const scene = this.getScene();
for (const i in scene.Map.tilesets) { for (const tileset of scene.Map.tilesets) {
const tileset = scene.Map.tilesets[i];
if (tileset.getTileData(index) !== null) { if (tileset.getTileData(index) !== null) {
return tileset; return tileset;
} }
@ -282,10 +284,10 @@ export class InteractiveLayer extends Container {
* @returns {TileAnimation[]|null} * @returns {TileAnimation[]|null}
*/ */
private getAnimationFromTile(tileset: Tileset, index: number): TileAnimation[]|null { private getAnimationFromTile(tileset: Tileset, index: number): TileAnimation[]|null {
const data = tileset.getTileData(index); const data = tileset.getTileData(index) as { animation: Array<TileAnimation> } | null;
if (typeof data === "object" && data !== null && Array.isArray((data as any).animation)) { if (typeof data === "object" && data !== null && Array.isArray(data.animation)) {
const animation: Array<TileAnimation> = (data as any).animation; const animation: Array<TileAnimation> = data.animation;
return animation; return animation;
} }
@ -309,7 +311,7 @@ export class InteractiveLayer extends Container {
* @returns {number} * @returns {number}
*/ */
private getInteractionRadius(): number { private getInteractionRadius(): number {
const radius = this.getLayerProperty("interactionRadius"); const radius = this.getLayerProperty("interactionRadius") as number | undefined;
if (typeof radius === "undefined" || isNaN(radius)) { if (typeof radius === "undefined" || isNaN(radius)) {
return 0; return 0;
@ -327,9 +329,9 @@ export class InteractiveLayer extends Container {
* If the propertry wasn't found, it will return undefined. * If the propertry wasn't found, it will return undefined.
* *
* @param {string} name * @param {string} name
* @returns {any} * @returns {string|boolean|number|undefined}
*/ */
private getLayerProperty(name: string): any { private getLayerProperty(name: string): string|boolean|number|undefined {
const properties: ITiledMapLayerProperty[] = this.layer.properties; const properties: ITiledMapLayerProperty[] = this.layer.properties;
if (!properties) { if (!properties) {
@ -397,7 +399,7 @@ export class InteractiveLayer extends Container {
*/ */
private addFrameToTilesetImage(tileset: Tileset, key: string, index: number): void { private addFrameToTilesetImage(tileset: Tileset, key: string, index: number): void {
if (!tileset.image.has(key)) { if (!tileset.image.has(key)) {
const coordinates = (tileset.getTileTextureCoordinates(index) as any); const coordinates = (tileset.getTileTextureCoordinates(index) as { x: number, y: number });
tileset.image.add(key, 0, coordinates.x, coordinates.y, tileset.tileWidth, tileset.tileHeight); tileset.image.add(key, 0, coordinates.x, coordinates.y, tileset.tileWidth, tileset.tileHeight);
} }
} }