From 9a577cadd3d10e75efc94d4e0ba03a8f79084482 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:00:01 +0200 Subject: [PATCH 01/24] fix: naming issue in code --- src/app/popups/navigation-popup.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app/popups/navigation-popup.ts b/src/app/popups/navigation-popup.ts index bd00d41..36ddf6e 100644 --- a/src/app/popups/navigation-popup.ts +++ b/src/app/popups/navigation-popup.ts @@ -7,7 +7,7 @@ export class NavigationPopup extends Container { private readonly background: Sprite; private readonly panel: Sprite; private readonly title: Text; - private readonly doneButton: Button; + private readonly startButton: Button; private readonly panelBase: Container; constructor(gameService: PixiGameService) { @@ -35,18 +35,18 @@ export class NavigationPopup extends Container { this.title.anchor.set(0.5, 0.5); this.panel.addChild(this.title); - this.doneButton = new Button(Sprite.from('assets/ui/yellow_button00.png')); - this.doneButton.view.width = 190; - this.doneButton.view.height = 49; - this.doneButton.view.y = -50; - this.doneButton.view.x = -95; + this.startButton = new Button(Sprite.from('assets/ui/yellow_button00.png')); + this.startButton.view.width = 190; + this.startButton.view.height = 49; + this.startButton.view.y = -50; + this.startButton.view.x = -95; const text = new Text('Spiel starten!', { fontFamily: 'DefaultFont', dropShadowColor: '000000', fontSize: 14 }); text.anchor.set(0.5, 0.5); text.x = 100; text.y = 20; - this.doneButton.view.addChild(text); - this.doneButton.onPress.connect(() => gameService.start(this)); - this.panel.addChild(this.doneButton.view); + this.startButton.view.addChild(text); + this.startButton.onPress.connect(() => gameService.start(this)); + this.panel.addChild(this.startButton.view); } /** Present the popup, animated */ From 5a97568f1ff692754c37a6ea7e1acd814a4750cd Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:04:07 +0200 Subject: [PATCH 02/24] refactor: shorten constructor --- src/app/popups/navigation-popup.ts | 31 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/app/popups/navigation-popup.ts b/src/app/popups/navigation-popup.ts index 36ddf6e..f15a52b 100644 --- a/src/app/popups/navigation-popup.ts +++ b/src/app/popups/navigation-popup.ts @@ -7,10 +7,9 @@ export class NavigationPopup extends Container { private readonly background: Sprite; private readonly panel: Sprite; private readonly title: Text; - private readonly startButton: Button; private readonly panelBase: Container; - constructor(gameService: PixiGameService) { + constructor(private readonly gameService: PixiGameService) { super(); this.background = Sprite.from(Texture.WHITE); @@ -35,18 +34,7 @@ export class NavigationPopup extends Container { this.title.anchor.set(0.5, 0.5); this.panel.addChild(this.title); - this.startButton = new Button(Sprite.from('assets/ui/yellow_button00.png')); - this.startButton.view.width = 190; - this.startButton.view.height = 49; - this.startButton.view.y = -50; - this.startButton.view.x = -95; - const text = new Text('Spiel starten!', { fontFamily: 'DefaultFont', dropShadowColor: '000000', fontSize: 14 }); - text.anchor.set(0.5, 0.5); - text.x = 100; - text.y = 20; - this.startButton.view.addChild(text); - this.startButton.onPress.connect(() => gameService.start(this)); - this.panel.addChild(this.startButton.view); + this.addStartButton(this.panel); } /** Present the popup, animated */ @@ -73,4 +61,19 @@ export class NavigationPopup extends Container { this.panel.x = width * 0.5; this.panel.y = height * 0.5; } + + private addStartButton(panel: Sprite): void { + const startButton = new Button(Sprite.from('assets/ui/yellow_button00.png')); + startButton.view.width = 190; + startButton.view.height = 49; + startButton.view.y = -50; + startButton.view.x = -95; + const text = new Text('Spiel starten!', { fontFamily: 'DefaultFont', dropShadowColor: '000000', fontSize: 14 }); + text.anchor.set(0.5, 0.5); + text.x = 100; + text.y = 20; + startButton.view.addChild(text); + startButton.onPress.connect(() => this.gameService.start(this)); + panel.addChild(startButton.view); + } } From 406449aefbbaa8c47b62ba556fbbfc6d72df335e Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:20:14 +0200 Subject: [PATCH 03/24] feat: credits dialog --- src/app/popups/credits-popup.ts | 95 +++++++++++++++++++++++++++ src/app/popups/navigation-popup.ts | 17 +++++ src/app/services/pixi-game.service.ts | 11 ++++ 3 files changed, 123 insertions(+) create mode 100644 src/app/popups/credits-popup.ts diff --git a/src/app/popups/credits-popup.ts b/src/app/popups/credits-popup.ts new file mode 100644 index 0000000..5b77896 --- /dev/null +++ b/src/app/popups/credits-popup.ts @@ -0,0 +1,95 @@ +import { Button } from '@pixi/ui'; +import gsap from 'gsap'; +import { Container, Sprite, Text, Texture } from 'pixi.js'; +import { PixiGameService } from '../services/pixi-game.service'; + +export class CreditsPopup extends Container { + private readonly background: Sprite; + private readonly panel: Sprite; + private readonly title: Text; + private readonly panelBase: Container; + + constructor(private readonly gameService: PixiGameService) { + super(); + + this.background = Sprite.from(Texture.WHITE); + this.background.tint = 0xffcc55; + this.background.eventMode = 'none'; + this.addChild(this.background); + + this.panel = Sprite.from('assets/ui/navigation-popup.png'); + this.panel.anchor.set(0.5); + this.panel.width = 265; + this.panel.height = 230; + this.addChild(this.panel); + + this.panelBase = new Container(); + this.panelBase.height = 400; + this.panelBase.width = 400; + this.panel.addChild(this.panelBase); + + this.title = new Text('Credits', { fontFamily: 'DefaultFont', dropShadowColor: '000000', fontSize: 14 }); + this.title.x = 0; + this.title.y = -96; + this.title.anchor.set(0.5, 0.5); + this.panel.addChild(this.title); + + + this.addText(this.panel, 'Idee & Programmierung', 14, -60); + this.addText(this.panel, 'Thomas Renger', 12, -40); + this.addText(this.panel, 'Grafiken', 14, -10); + this.addText(this.panel, 'Kenney (www.kenney.nl)', 12, 10); + + this.addCloseButton(this.panel); + } + + public async show() { + gsap.killTweensOf(this.background); + gsap.killTweensOf(this.panel.pivot); + this.background.alpha = 0; + this.panel.pivot.y = -400; + gsap.to(this.background, { alpha: 0.8, duration: 0.2, ease: 'linear' }); + await gsap.to(this.panel.pivot, { y: 0, duration: 0.3, ease: 'back.out' }); + } + + public async hide() { + gsap.killTweensOf(this.background); + gsap.killTweensOf(this.panel.pivot); + gsap.to(this.background, { alpha: 0, duration: 0.2, ease: 'linear' }); + await gsap.to(this.panel.pivot, { y: -500, duration: 0.3, ease: 'back.in' }); + } + + public resize(width: number, height: number) { + this.background.width = width; + this.background.height = height; + this.panel.x = width * 0.5; + this.panel.y = height * 0.5; + } + + private addCloseButton(panel: Sprite) { + const creditButton = new Button(Sprite.from('assets/ui/yellow_button00.png')); + creditButton.view.width = 190; + creditButton.view.height = 49; + creditButton.view.y = 55; + creditButton.view.x = -95; + const text = new Text('Schließen', { fontFamily: 'DefaultFont', dropShadowColor: '000000', fontSize: 14 }); + text.anchor.set(0.5, 0.5); + text.x = 100; + text.y = 20; + creditButton.view.addChild(text); + creditButton.onPress.connect(() => this.gameService.navigation(this)); + panel.addChild(creditButton.view); + } + + addText(panel: Sprite, content: string, size: number, positionY: number): void { + const text = new Text(content, { + fontFamily: 'DefaultFont', + dropShadowColor: '000000', + fontSize: size, + }); + text.x = 0; + text.y = positionY; + text.anchor.set(0.5, 0.5); + panel.addChild(text); + } +} diff --git a/src/app/popups/navigation-popup.ts b/src/app/popups/navigation-popup.ts index f15a52b..c0babc0 100644 --- a/src/app/popups/navigation-popup.ts +++ b/src/app/popups/navigation-popup.ts @@ -35,6 +35,8 @@ export class NavigationPopup extends Container { this.panel.addChild(this.title); this.addStartButton(this.panel); + + this.addCreditsButton(this.panel); } /** Present the popup, animated */ @@ -76,4 +78,19 @@ export class NavigationPopup extends Container { startButton.onPress.connect(() => this.gameService.start(this)); panel.addChild(startButton.view); } + + private addCreditsButton(panel: Sprite) { + const creditButton = new Button(Sprite.from('assets/ui/yellow_button00.png')); + creditButton.view.width = 190; + creditButton.view.height = 49; + creditButton.view.y = 10; + creditButton.view.x = -95; + const text = new Text('Credits', { fontFamily: 'DefaultFont', dropShadowColor: '000000', fontSize: 14 }); + text.anchor.set(0.5, 0.5); + text.x = 100; + text.y = 20; + creditButton.view.addChild(text); + creditButton.onPress.connect(() => this.gameService.credits(this)); + panel.addChild(creditButton.view); + } } diff --git a/src/app/services/pixi-game.service.ts b/src/app/services/pixi-game.service.ts index 0aa0c0d..358c66c 100644 --- a/src/app/services/pixi-game.service.ts +++ b/src/app/services/pixi-game.service.ts @@ -4,6 +4,7 @@ import { BehaviorSubject, distinctUntilChanged, filter } from 'rxjs'; import { tap } from 'rxjs/operators'; import { AppScreen, AppScreenConstructor } from '../models/pixijs/app-screen'; import { GameSprite } from '../models/pixijs/game-sprite'; +import { CreditsPopup } from '../popups/credits-popup'; import { NavigationPopup } from '../popups/navigation-popup'; import { PixiGameCollectableService } from './pixi-game-collectable.service'; import { PixiGameEnemyService } from './pixi-game-enemy.service'; @@ -181,4 +182,14 @@ export class PixiGameService { await this.hideAndRemoveScreen(requester); this.started = true; } + + async credits(requester: AppScreen): Promise { + await this.hideAndRemoveScreen(requester); + await this.presentPopup(CreditsPopup); + } + + async navigation(requester: AppScreen): Promise { + await this.hideAndRemoveScreen(requester); + await this.presentPopup(NavigationPopup); + } } From 3e5958b38970f2488aaa3a172590588f78446852 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:24:34 +0200 Subject: [PATCH 04/24] refactor: to use a base screen class --- src/app/popups/credits-popup.ts | 71 ++---------------------------- src/app/popups/popup.ts | 77 +++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 67 deletions(-) create mode 100644 src/app/popups/popup.ts diff --git a/src/app/popups/credits-popup.ts b/src/app/popups/credits-popup.ts index 5b77896..dd11232 100644 --- a/src/app/popups/credits-popup.ts +++ b/src/app/popups/credits-popup.ts @@ -1,39 +1,11 @@ import { Button } from '@pixi/ui'; -import gsap from 'gsap'; -import { Container, Sprite, Text, Texture } from 'pixi.js'; +import { Sprite, Text } from 'pixi.js'; import { PixiGameService } from '../services/pixi-game.service'; +import { Popup } from './popup'; -export class CreditsPopup extends Container { - private readonly background: Sprite; - private readonly panel: Sprite; - private readonly title: Text; - private readonly panelBase: Container; - +export class CreditsPopup extends Popup { constructor(private readonly gameService: PixiGameService) { - super(); - - this.background = Sprite.from(Texture.WHITE); - this.background.tint = 0xffcc55; - this.background.eventMode = 'none'; - this.addChild(this.background); - - this.panel = Sprite.from('assets/ui/navigation-popup.png'); - this.panel.anchor.set(0.5); - this.panel.width = 265; - this.panel.height = 230; - this.addChild(this.panel); - - this.panelBase = new Container(); - this.panelBase.height = 400; - this.panelBase.width = 400; - this.panel.addChild(this.panelBase); - - this.title = new Text('Credits', { fontFamily: 'DefaultFont', dropShadowColor: '000000', fontSize: 14 }); - this.title.x = 0; - this.title.y = -96; - this.title.anchor.set(0.5, 0.5); - this.panel.addChild(this.title); - + super('Credits'); this.addText(this.panel, 'Idee & Programmierung', 14, -60); this.addText(this.panel, 'Thomas Renger', 12, -40); @@ -43,29 +15,6 @@ export class CreditsPopup extends Container { this.addCloseButton(this.panel); } - public async show() { - gsap.killTweensOf(this.background); - gsap.killTweensOf(this.panel.pivot); - this.background.alpha = 0; - this.panel.pivot.y = -400; - gsap.to(this.background, { alpha: 0.8, duration: 0.2, ease: 'linear' }); - await gsap.to(this.panel.pivot, { y: 0, duration: 0.3, ease: 'back.out' }); - } - - public async hide() { - gsap.killTweensOf(this.background); - gsap.killTweensOf(this.panel.pivot); - gsap.to(this.background, { alpha: 0, duration: 0.2, ease: 'linear' }); - await gsap.to(this.panel.pivot, { y: -500, duration: 0.3, ease: 'back.in' }); - } - - public resize(width: number, height: number) { - this.background.width = width; - this.background.height = height; - this.panel.x = width * 0.5; - this.panel.y = height * 0.5; - } - private addCloseButton(panel: Sprite) { const creditButton = new Button(Sprite.from('assets/ui/yellow_button00.png')); creditButton.view.width = 190; @@ -80,16 +29,4 @@ export class CreditsPopup extends Container { creditButton.onPress.connect(() => this.gameService.navigation(this)); panel.addChild(creditButton.view); } - - addText(panel: Sprite, content: string, size: number, positionY: number): void { - const text = new Text(content, { - fontFamily: 'DefaultFont', - dropShadowColor: '000000', - fontSize: size, - }); - text.x = 0; - text.y = positionY; - text.anchor.set(0.5, 0.5); - panel.addChild(text); - } } diff --git a/src/app/popups/popup.ts b/src/app/popups/popup.ts new file mode 100644 index 0000000..827e768 --- /dev/null +++ b/src/app/popups/popup.ts @@ -0,0 +1,77 @@ +import gsap from 'gsap'; +import { Container, Sprite, Text, Texture } from 'pixi.js'; + +export abstract class Popup extends Container { + protected readonly panel: Sprite; + + private readonly background: Sprite; + private readonly title: Text; + private readonly panelBase: Container; + + constructor(title: string) { + super(); + + this.background = Sprite.from(Texture.WHITE); + this.background.tint = 0xffcc55; + this.background.eventMode = 'none'; + this.addChild(this.background); + + this.panel = Sprite.from('assets/ui/navigation-popup.png'); + this.panel.anchor.set(0.5); + this.panel.width = 265; + this.panel.height = 230; + this.addChild(this.panel); + + this.panelBase = new Container(); + this.panelBase.height = 400; + this.panelBase.width = 400; + this.panel.addChild(this.panelBase); + + this.title = new Text(title, { fontFamily: 'DefaultFont', dropShadowColor: '000000', fontSize: 14 }); + this.title.x = 0; + this.title.y = -96; + this.title.anchor.set(0.5, 0.5); + this.panel.addChild(this.title); + + + this.addText(this.panel, 'Idee & Programmierung', 14, -60); + this.addText(this.panel, 'Thomas Renger', 12, -40); + this.addText(this.panel, 'Grafiken', 14, -10); + this.addText(this.panel, 'Kenney (www.kenney.nl)', 12, 10); + } + + async show() { + gsap.killTweensOf(this.background); + gsap.killTweensOf(this.panel.pivot); + this.background.alpha = 0; + this.panel.pivot.y = -400; + gsap.to(this.background, { alpha: 0.8, duration: 0.2, ease: 'linear' }); + await gsap.to(this.panel.pivot, { y: 0, duration: 0.3, ease: 'back.out' }); + } + + async hide() { + gsap.killTweensOf(this.background); + gsap.killTweensOf(this.panel.pivot); + gsap.to(this.background, { alpha: 0, duration: 0.2, ease: 'linear' }); + await gsap.to(this.panel.pivot, { y: -500, duration: 0.3, ease: 'back.in' }); + } + + resize(width: number, height: number) { + this.background.width = width; + this.background.height = height; + this.panel.x = width * 0.5; + this.panel.y = height * 0.5; + } + + protected addText(panel: Sprite, content: string, size: number, positionY: number): void { + const text = new Text(content, { + fontFamily: 'DefaultFont', + dropShadowColor: '000000', + fontSize: size, + }); + text.x = 0; + text.y = positionY; + text.anchor.set(0.5, 0.5); + panel.addChild(text); + } +} From b1f825097cf17f12675c1ff4486996593380987f Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:25:54 +0200 Subject: [PATCH 05/24] refactor: navigation screen --- src/app/popups/navigation-popup.ts | 60 ++---------------------------- src/app/popups/popup.ts | 6 --- 2 files changed, 4 insertions(+), 62 deletions(-) diff --git a/src/app/popups/navigation-popup.ts b/src/app/popups/navigation-popup.ts index c0babc0..3022498 100644 --- a/src/app/popups/navigation-popup.ts +++ b/src/app/popups/navigation-popup.ts @@ -1,69 +1,17 @@ import { Button } from '@pixi/ui'; -import gsap from 'gsap'; -import { Container, Sprite, Text, Texture } from 'pixi.js'; +import { Sprite, Text } from 'pixi.js'; import { PixiGameService } from '../services/pixi-game.service'; +import { Popup } from './popup'; -export class NavigationPopup extends Container { - private readonly background: Sprite; - private readonly panel: Sprite; - private readonly title: Text; - private readonly panelBase: Container; +export class NavigationPopup extends Popup { constructor(private readonly gameService: PixiGameService) { - super(); - - this.background = Sprite.from(Texture.WHITE); - this.background.tint = 0xffcc55; - this.background.eventMode = 'none'; - this.addChild(this.background); - - this.panel = Sprite.from('assets/ui/navigation-popup.png'); - this.panel.anchor.set(0.5); - this.panel.width = 265; - this.panel.height = 230; - this.addChild(this.panel); - - this.panelBase = new Container(); - this.panelBase.height = 400; - this.panelBase.width = 400; - this.panel.addChild(this.panelBase); - - this.title = new Text('Solarstriker', { fontFamily: 'DefaultFont', dropShadowColor: '000000', fontSize: 14 }); - this.title.x = 0; - this.title.y = -96; - this.title.anchor.set(0.5, 0.5); - this.panel.addChild(this.title); + super('Solarstriker'); this.addStartButton(this.panel); - this.addCreditsButton(this.panel); } - /** Present the popup, animated */ - public async show() { - gsap.killTweensOf(this.background); - gsap.killTweensOf(this.panel.pivot); - this.background.alpha = 0; - this.panel.pivot.y = -400; - gsap.to(this.background, { alpha: 0.8, duration: 0.2, ease: 'linear' }); - await gsap.to(this.panel.pivot, { y: 0, duration: 0.3, ease: 'back.out' }); - } - - /** Dismiss the popup, animated */ - public async hide() { - gsap.killTweensOf(this.background); - gsap.killTweensOf(this.panel.pivot); - gsap.to(this.background, { alpha: 0, duration: 0.2, ease: 'linear' }); - await gsap.to(this.panel.pivot, { y: -500, duration: 0.3, ease: 'back.in' }); - } - - public resize(width: number, height: number) { - this.background.width = width; - this.background.height = height; - this.panel.x = width * 0.5; - this.panel.y = height * 0.5; - } - private addStartButton(panel: Sprite): void { const startButton = new Button(Sprite.from('assets/ui/yellow_button00.png')); startButton.view.width = 190; diff --git a/src/app/popups/popup.ts b/src/app/popups/popup.ts index 827e768..64c9ba6 100644 --- a/src/app/popups/popup.ts +++ b/src/app/popups/popup.ts @@ -32,12 +32,6 @@ export abstract class Popup extends Container { this.title.y = -96; this.title.anchor.set(0.5, 0.5); this.panel.addChild(this.title); - - - this.addText(this.panel, 'Idee & Programmierung', 14, -60); - this.addText(this.panel, 'Thomas Renger', 12, -40); - this.addText(this.panel, 'Grafiken', 14, -10); - this.addText(this.panel, 'Kenney (www.kenney.nl)', 12, 10); } async show() { From de2bf95f55e95b47325869774bbd6119002fc583 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:34:10 +0200 Subject: [PATCH 06/24] chore: add important rule for eslint --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 7bff220..3a80696 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,6 +21,7 @@ ], "rules": { "@typescript-eslint/await-thenable": "error", + "@typescript-eslint/explicit-function-return-type": "error", "@typescript-eslint/require-await": "error", "@angular-eslint/directive-selector": [ "error", From ce557e7c80ab15ab422281ec2865c2df7384e7ec Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:37:01 +0200 Subject: [PATCH 07/24] fix: lint issues --- src/app/models/pixijs/background-sprite.ts | 2 +- src/app/models/pixijs/game-sprite.ts | 2 +- src/app/popups/credits-popup.ts | 2 +- src/app/popups/navigation-popup.ts | 2 +- src/app/popups/popup.ts | 6 +++--- src/app/services/game.service.ts | 6 +++--- src/app/services/pixi-game-enemy.service.ts | 4 ++-- src/app/services/pixi-game.service.ts | 11 +++-------- 8 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/app/models/pixijs/background-sprite.ts b/src/app/models/pixijs/background-sprite.ts index 2017327..cd61086 100644 --- a/src/app/models/pixijs/background-sprite.ts +++ b/src/app/models/pixijs/background-sprite.ts @@ -15,7 +15,7 @@ export class BackgroundSprite extends TilingSprite { this.speedTilepositionX = speedTilepositionX; } - update(delta: number) { + update(delta: number): void { this.tilePosition.y += delta * this.speedTilepositionY; this.tilePosition.x += delta * this.speedTilepositionX; diff --git a/src/app/models/pixijs/game-sprite.ts b/src/app/models/pixijs/game-sprite.ts index 4814cdd..8056efa 100644 --- a/src/app/models/pixijs/game-sprite.ts +++ b/src/app/models/pixijs/game-sprite.ts @@ -12,7 +12,7 @@ export class GameSprite extends AnimatedSprite { this.speed = speed; } - override update(delta: number) { + override update(delta: number): void { super.update(delta); this.y += delta * this.speed; diff --git a/src/app/popups/credits-popup.ts b/src/app/popups/credits-popup.ts index dd11232..59fc489 100644 --- a/src/app/popups/credits-popup.ts +++ b/src/app/popups/credits-popup.ts @@ -15,7 +15,7 @@ export class CreditsPopup extends Popup { this.addCloseButton(this.panel); } - private addCloseButton(panel: Sprite) { + private addCloseButton(panel: Sprite): void { const creditButton = new Button(Sprite.from('assets/ui/yellow_button00.png')); creditButton.view.width = 190; creditButton.view.height = 49; diff --git a/src/app/popups/navigation-popup.ts b/src/app/popups/navigation-popup.ts index 3022498..4ead4e9 100644 --- a/src/app/popups/navigation-popup.ts +++ b/src/app/popups/navigation-popup.ts @@ -27,7 +27,7 @@ export class NavigationPopup extends Popup { panel.addChild(startButton.view); } - private addCreditsButton(panel: Sprite) { + private addCreditsButton(panel: Sprite): void { const creditButton = new Button(Sprite.from('assets/ui/yellow_button00.png')); creditButton.view.width = 190; creditButton.view.height = 49; diff --git a/src/app/popups/popup.ts b/src/app/popups/popup.ts index 64c9ba6..7aad90d 100644 --- a/src/app/popups/popup.ts +++ b/src/app/popups/popup.ts @@ -34,7 +34,7 @@ export abstract class Popup extends Container { this.panel.addChild(this.title); } - async show() { + async show(): Promise { gsap.killTweensOf(this.background); gsap.killTweensOf(this.panel.pivot); this.background.alpha = 0; @@ -43,14 +43,14 @@ export abstract class Popup extends Container { await gsap.to(this.panel.pivot, { y: 0, duration: 0.3, ease: 'back.out' }); } - async hide() { + async hide(): Promise { gsap.killTweensOf(this.background); gsap.killTweensOf(this.panel.pivot); gsap.to(this.background, { alpha: 0, duration: 0.2, ease: 'linear' }); await gsap.to(this.panel.pivot, { y: -500, duration: 0.3, ease: 'back.in' }); } - resize(width: number, height: number) { + resize(width: number, height: number): void { this.background.width = width; this.background.height = height; this.panel.x = width * 0.5; diff --git a/src/app/services/game.service.ts b/src/app/services/game.service.ts index ae52f8f..81c08d5 100644 --- a/src/app/services/game.service.ts +++ b/src/app/services/game.service.ts @@ -51,11 +51,11 @@ export class GameService { this.player.shot(); } - private spawnCollectable(enemy: RenderObject) { + private spawnCollectable(enemy: RenderObject): void { this.collectable.push(new Collectable(enemy.x, enemy.y, 16, 16)); } - private spawnEnemy(position: number) { + private spawnEnemy(position: number): void { this.enemies.push(new RenderObject(position, 0, 32, 16)); } @@ -87,7 +87,7 @@ export class GameService { this.enemies = this.enemies.filter(enemy => !enemy.destroyed && enemy.y < 2000); } - private collect() { + private collect(): void { const collectable = this.collectable.find(collectable => !collectable.destroyed && collectable.collidate(this.player)); if (collectable) { collectable.destroyed = true; diff --git a/src/app/services/pixi-game-enemy.service.ts b/src/app/services/pixi-game-enemy.service.ts index d83c688..4c94004 100644 --- a/src/app/services/pixi-game-enemy.service.ts +++ b/src/app/services/pixi-game-enemy.service.ts @@ -55,7 +55,7 @@ export class PixiGameEnemyService { explosion.loop = false; explosion.x = enemy.x; explosion.y = enemy.y; - explosion.onComplete = () => { + explosion.onComplete = (): void => { void this.collectables.spawn(explosion.x, explosion.y); explosion.destroy(); }; @@ -82,7 +82,7 @@ export class PixiGameEnemyService { explosion.loop = false; explosion.x = enemy.x; explosion.y = enemy.y; - explosion.onComplete = () => { + explosion.onComplete = (): void => { explosion.destroy(); }; this.app.stage.addChild(explosion); diff --git a/src/app/services/pixi-game.service.ts b/src/app/services/pixi-game.service.ts index 358c66c..93b2fc0 100644 --- a/src/app/services/pixi-game.service.ts +++ b/src/app/services/pixi-game.service.ts @@ -119,7 +119,7 @@ export class PixiGameService { ); } - private async presentPopup(ctor: AppScreenConstructor) { + private async presentPopup(ctor: AppScreenConstructor): Promise { if (this.currentPopup) { await this.hideAndRemoveScreen(this.currentPopup); } @@ -128,7 +128,7 @@ export class PixiGameService { await this.addAndShowScreen(this.currentPopup); } - private async hideAndRemoveScreen(screen: AppScreen) { + private async hideAndRemoveScreen(screen: AppScreen): Promise { screen.interactiveChildren = false; if (screen.hide) { await screen.hide(); @@ -147,12 +147,7 @@ export class PixiGameService { } } - private async addAndShowScreen(screen: AppScreen) { - // Add navigation container to stage if it does not have a parent yet - //if (!this.container.parent) { - //this.app.stage.addChild(this.container); - //} - + private async addAndShowScreen(screen: AppScreen): Promise { // Add screen to stage this.app.stage.addChild(screen); From 6416aef3773b18f11f7a0d3012bad4081274c0a5 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:39:55 +0200 Subject: [PATCH 08/24] chore: rule for condition check --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 3a80696..5a5594d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -22,6 +22,7 @@ "rules": { "@typescript-eslint/await-thenable": "error", "@typescript-eslint/explicit-function-return-type": "error", + "@typescript-eslint/no-unnecessary-condition": "error", "@typescript-eslint/require-await": "error", "@angular-eslint/directive-selector": [ "error", From 50721831c193ba132a8fe326fe0a60c38a4bb3b0 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:46:54 +0200 Subject: [PATCH 09/24] fix: fix issues for rule --- src/app/models/ship.model.ts | 10 ++++------ src/app/services/pixi-game-collectable.service.ts | 2 +- src/app/services/pixi-game-enemy.service.ts | 2 +- src/app/services/pixi-game-ship.service.ts | 6 ------ src/app/services/pixi-game.service.ts | 10 ++++++---- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/app/models/ship.model.ts b/src/app/models/ship.model.ts index a455cb7..6b44926 100644 --- a/src/app/models/ship.model.ts +++ b/src/app/models/ship.model.ts @@ -34,12 +34,10 @@ export class Ship extends RenderObject { this.game.shots.push(new ShotObject(this.x + this.width - 7, this.y)); return; } - if (this.weapon === Weapon.Three) { - this.game.shots.push(new ShotObject(this.x + 7, this.y)); - this.game.shots.push(new ShotObject(this.x + this.width / 2, this.y)); - this.game.shots.push(new ShotObject(this.x + this.width - 7, this.y)); - return; - } + + this.game.shots.push(new ShotObject(this.x + 7, this.y)); + this.game.shots.push(new ShotObject(this.x + this.width / 2, this.y)); + this.game.shots.push(new ShotObject(this.x + this.width - 7, this.y)); } move(clientX: number): void { diff --git a/src/app/services/pixi-game-collectable.service.ts b/src/app/services/pixi-game-collectable.service.ts index c3ef42d..de6d2f3 100644 --- a/src/app/services/pixi-game-collectable.service.ts +++ b/src/app/services/pixi-game-collectable.service.ts @@ -38,7 +38,7 @@ export class PixiGameCollectableService { this.collectables.push(powerUp); } - collect(ship: Ship): void { + collect(ship: Ship | undefined): void { if (!ship || ship.destroyed) { return; } diff --git a/src/app/services/pixi-game-enemy.service.ts b/src/app/services/pixi-game-enemy.service.ts index 4c94004..b69ab3f 100644 --- a/src/app/services/pixi-game-enemy.service.ts +++ b/src/app/services/pixi-game-enemy.service.ts @@ -70,7 +70,7 @@ export class PixiGameEnemyService { return result; } - kill(ship: GameSprite): boolean { + kill(ship: GameSprite | undefined): boolean { if (!ship || ship.destroyed) { return false; } diff --git a/src/app/services/pixi-game-ship.service.ts b/src/app/services/pixi-game-ship.service.ts index 7fb32ac..b4e19d7 100644 --- a/src/app/services/pixi-game-ship.service.ts +++ b/src/app/services/pixi-game-ship.service.ts @@ -19,15 +19,9 @@ export class PixiGameShipService { async init(): Promise { const ship = await Assets.load('assets/game/ship.json'); - if (!ship) { - throw new Error('Where is my ship?'); - } this.shipAnimation = ship.animations['ship']; const laser = await Assets.load('assets/game/laser.json'); - if (!laser) { - throw new Error('Where is my laser'); - } this.laserAnimation = laser.animations['laser']; } diff --git a/src/app/services/pixi-game.service.ts b/src/app/services/pixi-game.service.ts index 93b2fc0..f6a621a 100644 --- a/src/app/services/pixi-game.service.ts +++ b/src/app/services/pixi-game.service.ts @@ -12,11 +12,14 @@ import { PixiGameLandscapeService } from './pixi-game-landscape.service'; import { PixiGameScreenService } from './pixi-game-screen.service'; import { PixiGameShipService } from './pixi-game-ship.service'; -function handleMouseMove(event: { data: { originalEvent: PointerEvent | TouchEvent } }, ship: GameSprite): void { +function handleMouseMove(event: { + data: { originalEvent: PointerEvent | TouchEvent } +}, ship: GameSprite | undefined): void { if (!ship || ship.destroyed) { return; } + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition ship.x = (event.data.originalEvent as PointerEvent).clientX ?? (event.data.originalEvent as TouchEvent).touches[0].clientX; } @@ -138,9 +141,8 @@ export class PixiGameService { this.app.ticker.remove(screen.update, screen); } - if (screen.parent) { - screen.parent.removeChild(screen); - } + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + screen.parent?.removeChild(screen); if (screen.reset) { screen.reset(); From 6cf0cc10a97f5fc218c6f464995f091f3e2f135e Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:49:46 +0200 Subject: [PATCH 10/24] chore: promise rule --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 5a5594d..300b736 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -22,6 +22,7 @@ "rules": { "@typescript-eslint/await-thenable": "error", "@typescript-eslint/explicit-function-return-type": "error", + "@typescript-eslint/no-floating-promises": "error", "@typescript-eslint/no-unnecessary-condition": "error", "@typescript-eslint/require-await": "error", "@angular-eslint/directive-selector": [ From 7ec467fcf9348b0dbd619c8cf613723463c15edd Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:49:53 +0200 Subject: [PATCH 11/24] fix: fix it --- src/app/services/sound.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/services/sound.service.ts b/src/app/services/sound.service.ts index a622d0e..ef9f96b 100644 --- a/src/app/services/sound.service.ts +++ b/src/app/services/sound.service.ts @@ -21,7 +21,7 @@ export class SoundService { const promises = [data1, data2].map( (data, index) => new Promise((resolve) => { setTimeout(() => { - this.playStringsAsSound(data.split(' '), types[index]); + void this.playStringsAsSound(data.split(' '), types[index]); resolve(); }, index * delay); }), From 089f5be39edcb85fef7cc928af1f77faee4f6a64 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:50:59 +0200 Subject: [PATCH 12/24] chore: define rule to avoid shadow --- .eslintrc.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.eslintrc.json b/.eslintrc.json index 300b736..a3ffb78 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -23,6 +23,8 @@ "@typescript-eslint/await-thenable": "error", "@typescript-eslint/explicit-function-return-type": "error", "@typescript-eslint/no-floating-promises": "error", + "no-shadow": "off", + "@typescript-eslint/no-shadow": "error", "@typescript-eslint/no-unnecessary-condition": "error", "@typescript-eslint/require-await": "error", "@angular-eslint/directive-selector": [ From 195ebbfe8c4647a262838b949e2fd4ebd918c035 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:55:01 +0200 Subject: [PATCH 13/24] fix: fix the eslint issues --- src/app/models/located-object.model.ts | 2 +- src/app/models/render-object.model.ts | 2 +- src/app/models/shot-object.model.ts | 2 +- src/app/services/game.service.ts | 20 ++++++++++---------- src/app/services/pixi-game-enemy.service.ts | 20 ++++++++++---------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/app/models/located-object.model.ts b/src/app/models/located-object.model.ts index 5aedc9c..fa356cf 100644 --- a/src/app/models/located-object.model.ts +++ b/src/app/models/located-object.model.ts @@ -4,5 +4,5 @@ export interface LocatedObject { width: number, height: number, update: () => void, - collidate: (item: LocatedObject) => boolean + collide: (item: LocatedObject) => boolean } diff --git a/src/app/models/render-object.model.ts b/src/app/models/render-object.model.ts index 2deafdf..688b86b 100644 --- a/src/app/models/render-object.model.ts +++ b/src/app/models/render-object.model.ts @@ -20,7 +20,7 @@ export class RenderObject implements LocatedObject { this.y += 0.25; } - collidate(item: LocatedObject): boolean { + collide(item: LocatedObject): boolean { const small = item.width < this.width ? item : this; const large = item.width >= this.width ? item : this; diff --git a/src/app/models/shot-object.model.ts b/src/app/models/shot-object.model.ts index 90fd10d..0f88713 100644 --- a/src/app/models/shot-object.model.ts +++ b/src/app/models/shot-object.model.ts @@ -17,7 +17,7 @@ export class ShotObject implements LocatedObject { this.y -= 2; } - collidate(item: LocatedObject): boolean { + collide(item: LocatedObject): boolean { return (item.x <= this.x && (item.x - 20) >= this.x) && (item.y <= this.y && (item.y - 20) >= this.y); } diff --git a/src/app/services/game.service.ts b/src/app/services/game.service.ts index 81c08d5..b5adb6a 100644 --- a/src/app/services/game.service.ts +++ b/src/app/services/game.service.ts @@ -67,30 +67,30 @@ export class GameService { private hitEnemy(): void { this.shots.forEach(shot => { - const enemy = this.enemies.find(enemy => enemy.collidate(shot)); - if (enemy) { - enemy.destroyed = true; + const collidedEnemy = this.enemies.find(enemy => enemy.collide(shot)); + if (collidedEnemy) { + collidedEnemy.destroyed = true; shot.destroyed = true; this.kills++; - this.spawnCollectable(enemy); + this.spawnCollectable(collidedEnemy); } }); this.shots = this.shots.filter(shot => !shot.destroyed && (shot.y > 0)); } private hitShip(): void { - const enemy = this.enemies.find(enemy => !enemy.destroyed && enemy.collidate(this.player)); - if (enemy) { - enemy.destroyed = true; + const collidedEnemy = this.enemies.find(enemy => !enemy.destroyed && enemy.collide(this.player)); + if (collidedEnemy) { + collidedEnemy.destroyed = true; this.deaths++; } this.enemies = this.enemies.filter(enemy => !enemy.destroyed && enemy.y < 2000); } private collect(): void { - const collectable = this.collectable.find(collectable => !collectable.destroyed && collectable.collidate(this.player)); - if (collectable) { - collectable.destroyed = true; + const collidedCollectable = this.collectable.find(collectable => !collectable.destroyed && collectable.collide(this.player)); + if (collidedCollectable) { + collidedCollectable.destroyed = true; this.player.weapon = (this.player.weapon + 1) % Weapon.Auto; } this.collectable = this.collectable.filter(collectable => !collectable.destroyed && collectable.y < 2000); diff --git a/src/app/services/pixi-game-enemy.service.ts b/src/app/services/pixi-game-enemy.service.ts index b69ab3f..ce9a763 100644 --- a/src/app/services/pixi-game-enemy.service.ts +++ b/src/app/services/pixi-game-enemy.service.ts @@ -47,20 +47,20 @@ export class PixiGameEnemyService { hit(shots: GameSprite[]): number { let result = 0; for (const shot of shots) { - const enemy = this.enemies.find(enemy => !enemy.destroyed && shot.hit(enemy)); - if (enemy) { + const hitEnemy = this.enemies.find(enemy => !enemy.destroyed && shot.hit(enemy)); + if (hitEnemy) { // explode const explosion = new AnimatedSprite(this.explosionSprite.animations['explosion']); explosion.animationSpeed = 0.167; explosion.loop = false; - explosion.x = enemy.x; - explosion.y = enemy.y; + explosion.x = hitEnemy.x; + explosion.y = hitEnemy.y; explosion.onComplete = (): void => { void this.collectables.spawn(explosion.x, explosion.y); explosion.destroy(); }; this.app.stage.addChild(explosion); - enemy.destroy(); + hitEnemy.destroy(); shot.destroy(); explosion.play(); result++; @@ -75,18 +75,18 @@ export class PixiGameEnemyService { return false; } - const enemy = this.enemies.find(enemy => !enemy.destroyed && ship.hit(enemy)); - if (enemy) { + const hitEnemy = this.enemies.find(enemy => !enemy.destroyed && ship.hit(enemy)); + if (hitEnemy) { const explosion = new AnimatedSprite(this.explosionSprite.animations['explosion']); explosion.animationSpeed = 0.167; explosion.loop = false; - explosion.x = enemy.x; - explosion.y = enemy.y; + explosion.x = hitEnemy.x; + explosion.y = hitEnemy.y; explosion.onComplete = (): void => { explosion.destroy(); }; this.app.stage.addChild(explosion); - enemy.destroy(); + hitEnemy.destroy(); explosion.play(); return true; } From 7417cd709f7b91be073a380e5d069b87e01e38d1 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:56:31 +0200 Subject: [PATCH 14/24] chore: rule for naming conventions --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index a3ffb78..6c92529 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -22,6 +22,7 @@ "rules": { "@typescript-eslint/await-thenable": "error", "@typescript-eslint/explicit-function-return-type": "error", + "@typescript-eslint/naming-convention": "error", "@typescript-eslint/no-floating-promises": "error", "no-shadow": "off", "@typescript-eslint/no-shadow": "error", From 37f504678af51fae94d7e1e0afb8d42f71f0345a Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 21:57:33 +0200 Subject: [PATCH 15/24] fix naming convention issues --- src/app/models/collectable.model.ts | 2 +- src/app/models/pixijs/power-up-sprite.ts | 6 +++--- src/app/models/ship.model.ts | 16 ++++++++-------- src/app/services/game.service.ts | 2 +- .../services/pixi-game-collectable.service.ts | 8 ++++---- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/app/models/collectable.model.ts b/src/app/models/collectable.model.ts index 49fbb79..8a00d98 100644 --- a/src/app/models/collectable.model.ts +++ b/src/app/models/collectable.model.ts @@ -2,7 +2,7 @@ import { RenderObject } from './render-object.model'; import { Weapon } from './ship.model'; export class Collectable extends RenderObject { - type = Weapon.Two; + type = Weapon.two; override update(): void { this.y += 0.125; diff --git a/src/app/models/pixijs/power-up-sprite.ts b/src/app/models/pixijs/power-up-sprite.ts index 47d756f..0bb9c40 100644 --- a/src/app/models/pixijs/power-up-sprite.ts +++ b/src/app/models/pixijs/power-up-sprite.ts @@ -2,12 +2,12 @@ import { FrameObject, Texture } from 'pixi.js'; import { GameSprite } from './game-sprite'; export enum PowerUp { - Speed, - Shot, + speed, + shot, } export class PowerUpSprite extends GameSprite { - readonly type: PowerUp = PowerUp.Speed; + readonly type: PowerUp = PowerUp.speed; constructor(speed: number, textures: Texture[] | FrameObject[], type: PowerUp) { super(speed, textures); diff --git a/src/app/models/ship.model.ts b/src/app/models/ship.model.ts index 6b44926..5bff092 100644 --- a/src/app/models/ship.model.ts +++ b/src/app/models/ship.model.ts @@ -4,32 +4,32 @@ import { RenderObject } from './render-object.model'; import { ShotObject } from './shot-object.model'; export enum Weapon { - One, - Two, - Three, - Auto + one, + two, + three, + auto } export class Ship extends RenderObject { - weapon: Weapon = Weapon.One; + weapon: Weapon = Weapon.one; constructor(x: number, y: number, private readonly game: GameService, private readonly sound: SoundService) { super(x, y); } override update(): void { - if (this.weapon === Weapon.Auto) { + if (this.weapon === Weapon.auto) { this.shot(); } } shot(): void { void this.sound.playSound(); - if (this.weapon === Weapon.One || this.weapon === Weapon.Auto) { + if (this.weapon === Weapon.one || this.weapon === Weapon.auto) { this.game.shots.push(new ShotObject(this.x + this.width / 2, this.y)); return; } - if (this.weapon === Weapon.Two) { + if (this.weapon === Weapon.two) { this.game.shots.push(new ShotObject(this.x + 7, this.y)); this.game.shots.push(new ShotObject(this.x + this.width - 7, this.y)); return; diff --git a/src/app/services/game.service.ts b/src/app/services/game.service.ts index b5adb6a..df3b661 100644 --- a/src/app/services/game.service.ts +++ b/src/app/services/game.service.ts @@ -91,7 +91,7 @@ export class GameService { const collidedCollectable = this.collectable.find(collectable => !collectable.destroyed && collectable.collide(this.player)); if (collidedCollectable) { collidedCollectable.destroyed = true; - this.player.weapon = (this.player.weapon + 1) % Weapon.Auto; + this.player.weapon = (this.player.weapon + 1) % Weapon.auto; } this.collectable = this.collectable.filter(collectable => !collectable.destroyed && collectable.y < 2000); } diff --git a/src/app/services/pixi-game-collectable.service.ts b/src/app/services/pixi-game-collectable.service.ts index de6d2f3..f281852 100644 --- a/src/app/services/pixi-game-collectable.service.ts +++ b/src/app/services/pixi-game-collectable.service.ts @@ -24,8 +24,8 @@ export class PixiGameCollectableService { if (rand > 0.1) { return; } - const type = Math.random() > 0.5 ? PowerUp.Speed : PowerUp.Shot; - const texture = (type === PowerUp.Speed) + const type = Math.random() > 0.5 ? PowerUp.speed : PowerUp.shot; + const texture = (type === PowerUp.speed) ? this.powerUpSpeedTexture : this.powerUpPowerTexture; const powerUp = new PowerUpSprite(1, texture, type); @@ -45,10 +45,10 @@ export class PixiGameCollectableService { const powerUp = this.collectables.find(collectable => !collectable.destroyed && ship.hit(collectable)); if (powerUp) { - if (powerUp.type === PowerUp.Speed) { + if (powerUp.type === PowerUp.speed) { ship.shotSpeed += 0.1; } - if (powerUp.type === PowerUp.Shot) { + if (powerUp.type === PowerUp.shot) { ship.shotPower++; } powerUp.destroy(); From 4acbfb9355177dde8c1ec789ca363d4ae1836d62 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 22:04:19 +0200 Subject: [PATCH 16/24] chore: configure rule for naming conventions --- .eslintrc.json | 16 ++++++++++++++++ package-lock.json | 29 +++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 46 insertions(+) diff --git a/.eslintrc.json b/.eslintrc.json index 6c92529..fd7dd51 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -14,12 +14,28 @@ ], "createDefaultProgram": true }, + "plugins": [ + "function-name" + ], "extends": [ "plugin:@typescript-eslint/recommended", "plugin:@angular-eslint/recommended", "plugin:@angular-eslint/template/process-inline-templates" ], "rules": { + "function-name/starts-with-verb": [ + "error", + { + "whitelist": [ + "ng", + "spawn", + "hit", + "shot", + "collide", + "resize" + ] + } + ], "@typescript-eslint/await-thenable": "error", "@typescript-eslint/explicit-function-return-type": "error", "@typescript-eslint/naming-convention": "error", diff --git a/package-lock.json b/package-lock.json index 1cd4193..a3c04c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,6 +43,7 @@ "@typescript-eslint/parser": "^6.5.0", "angular-cli-ghpages": "^1.0.0", "eslint": "^8.39.0", + "eslint-plugin-function-name": "^2.0.1", "jasmine-core": "~5.1.1", "karma": "~6.4.0", "karma-chrome-launcher": "~3.2.0", @@ -7667,6 +7668,19 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-plugin-function-name": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-function-name/-/eslint-plugin-function-name-2.0.1.tgz", + "integrity": "sha512-PAwKrMbz7rLX2HSZ9S3j+eTQnxP0C3FuCz6mD+ywbEFgB/USDsqkW97Mihie4WfBPrdAQoi7Psvv23t9N5ID9Q==", + "dev": true, + "dependencies": { + "requireindex": "~1.1.0", + "verb-corpus": "^3.1.3" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/eslint-scope": { "version": "7.2.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", @@ -13495,6 +13509,15 @@ "node": ">=0.10.0" } }, + "node_modules/requireindex": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.1.0.tgz", + "integrity": "sha512-LBnkqsDE7BZKvqylbmn7lTIVdpx4K/QCduRATpO5R+wtPmky/a8pN1bO2D6wXppn1497AJF9mNjqAXr6bdl9jg==", + "dev": true, + "engines": { + "node": ">=0.10.5" + } + }, "node_modules/requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", @@ -15436,6 +15459,12 @@ "node": ">= 0.8" } }, + "node_modules/verb-corpus": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/verb-corpus/-/verb-corpus-3.5.0.tgz", + "integrity": "sha512-HYkwsrFokp/3A+JDki6w8VU91J7eSDwtvo6iRHYOLnjKRZ6n8epgiNKjakj6IY0zkSEkjW64rUjGyD605rcukQ==", + "dev": true + }, "node_modules/vite": { "version": "4.4.7", "resolved": "https://registry.npmjs.org/vite/-/vite-4.4.7.tgz", diff --git a/package.json b/package.json index b9ae2b9..aa2de9d 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "@typescript-eslint/parser": "^6.5.0", "angular-cli-ghpages": "^1.0.0", "eslint": "^8.39.0", + "eslint-plugin-function-name": "^2.0.1", "jasmine-core": "~5.1.1", "karma": "~6.4.0", "karma-chrome-launcher": "~3.2.0", From 45f85e22b642e518d4ff8fb7fa03a9320425f09e Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 22:04:28 +0200 Subject: [PATCH 17/24] fix the issues found --- src/app/popups/credits-popup.ts | 2 +- src/app/popups/navigation-popup.ts | 2 +- src/app/services/pixi-game.service.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/popups/credits-popup.ts b/src/app/popups/credits-popup.ts index 59fc489..1e50bb3 100644 --- a/src/app/popups/credits-popup.ts +++ b/src/app/popups/credits-popup.ts @@ -26,7 +26,7 @@ export class CreditsPopup extends Popup { text.x = 100; text.y = 20; creditButton.view.addChild(text); - creditButton.onPress.connect(() => this.gameService.navigation(this)); + creditButton.onPress.connect(() => this.gameService.openNavigation(this)); panel.addChild(creditButton.view); } } diff --git a/src/app/popups/navigation-popup.ts b/src/app/popups/navigation-popup.ts index 4ead4e9..534098e 100644 --- a/src/app/popups/navigation-popup.ts +++ b/src/app/popups/navigation-popup.ts @@ -38,7 +38,7 @@ export class NavigationPopup extends Popup { text.x = 100; text.y = 20; creditButton.view.addChild(text); - creditButton.onPress.connect(() => this.gameService.credits(this)); + creditButton.onPress.connect(() => this.gameService.openCredits(this)); panel.addChild(creditButton.view); } } diff --git a/src/app/services/pixi-game.service.ts b/src/app/services/pixi-game.service.ts index f6a621a..7e65a83 100644 --- a/src/app/services/pixi-game.service.ts +++ b/src/app/services/pixi-game.service.ts @@ -180,12 +180,12 @@ export class PixiGameService { this.started = true; } - async credits(requester: AppScreen): Promise { + async openCredits(requester: AppScreen): Promise { await this.hideAndRemoveScreen(requester); await this.presentPopup(CreditsPopup); } - async navigation(requester: AppScreen): Promise { + async openNavigation(requester: AppScreen): Promise { await this.hideAndRemoveScreen(requester); await this.presentPopup(NavigationPopup); } From fc93e0ad1532c426301aa8efeb06100914d3a575 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 22:09:39 +0200 Subject: [PATCH 18/24] chore: eslint rule to avoid long functions --- .eslintrc.json | 4 ++++ src/app/models/pixijs/background-sprite.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/.eslintrc.json b/.eslintrc.json index fd7dd51..4ad2348 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -36,6 +36,10 @@ ] } ], + "max-params": [ + "error", + 4 + ], "@typescript-eslint/await-thenable": "error", "@typescript-eslint/explicit-function-return-type": "error", "@typescript-eslint/naming-convention": "error", diff --git a/src/app/models/pixijs/background-sprite.ts b/src/app/models/pixijs/background-sprite.ts index cd61086..8df1e9b 100644 --- a/src/app/models/pixijs/background-sprite.ts +++ b/src/app/models/pixijs/background-sprite.ts @@ -1,6 +1,7 @@ import { Texture, TilingSprite } from 'pixi.js'; export class BackgroundSprite extends TilingSprite { + // eslint-disable-next-line max-params constructor( private readonly speedTilepositionY: number, private readonly speedTilepositionX: number, From 458959f3696604bdc4e46d9e97d6d959c9212691 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 22:12:19 +0200 Subject: [PATCH 19/24] fix configuration --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 4ad2348..1c9249b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -47,6 +47,7 @@ "no-shadow": "off", "@typescript-eslint/no-shadow": "error", "@typescript-eslint/no-unnecessary-condition": "error", + "require-await": "off", "@typescript-eslint/require-await": "error", "@angular-eslint/directive-selector": [ "error", From 347956bc4541f92b972b3e639fd3f0fdf0a50f3a Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 22:13:56 +0200 Subject: [PATCH 20/24] chore new rule introduced --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 1c9249b..df669bc 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -44,6 +44,7 @@ "@typescript-eslint/explicit-function-return-type": "error", "@typescript-eslint/naming-convention": "error", "@typescript-eslint/no-floating-promises": "error", + "no-nested-ternary": "error", "no-shadow": "off", "@typescript-eslint/no-shadow": "error", "@typescript-eslint/no-unnecessary-condition": "error", From 9e867ef48cf71d09a40751bbcc2f96d243c9fc61 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 22:15:46 +0200 Subject: [PATCH 21/24] fix the issue --- src/app/services/pixi-game-ship.service.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/services/pixi-game-ship.service.ts b/src/app/services/pixi-game-ship.service.ts index b4e19d7..bfbbc76 100644 --- a/src/app/services/pixi-game-ship.service.ts +++ b/src/app/services/pixi-game-ship.service.ts @@ -56,11 +56,14 @@ export class PixiGameShipService { shot.animationSpeed = 0.167; shot.play(); shot.anchor.set(0.5); - shot.x = ((power === 1) || (power === 3 && i == 2)) - ? this.#ship.x - : (power > 1 && i == 1) - ? this.#ship.x - 5 - : this.#ship.x + 5; + if ((power === 1) || (power === 3 && i == 2)) { + shot.x = this.#ship.x; + } else if (power > 1 && i == 1) { + shot.x = this.#ship.x - 5; + } else { + shot.x = this.#ship.x + 5; + } + shot.y = this.#ship.y; this.#shots.push(shot); this.app.stage.addChild(shot); From 026f6ecf1a373f601d1358629d55a1710496d7c8 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 22:19:44 +0200 Subject: [PATCH 22/24] chore rule added to avoid == instead of === --- .eslintrc.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.eslintrc.json b/.eslintrc.json index df669bc..5c9e58b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -23,6 +23,10 @@ "plugin:@angular-eslint/template/process-inline-templates" ], "rules": { + "eqeqeq": [ + "error", + "always" + ], "function-name/starts-with-verb": [ "error", { From ba35a67d2fe3c528fea806303f5df1bce48323e0 Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 22:20:10 +0200 Subject: [PATCH 23/24] fix eqeqeq issues --- src/app/services/pixi-game-ship.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/services/pixi-game-ship.service.ts b/src/app/services/pixi-game-ship.service.ts index bfbbc76..8f3db38 100644 --- a/src/app/services/pixi-game-ship.service.ts +++ b/src/app/services/pixi-game-ship.service.ts @@ -56,9 +56,9 @@ export class PixiGameShipService { shot.animationSpeed = 0.167; shot.play(); shot.anchor.set(0.5); - if ((power === 1) || (power === 3 && i == 2)) { + if ((power === 1) || (power === 3 && i === 2)) { shot.x = this.#ship.x; - } else if (power > 1 && i == 1) { + } else if (power > 1 && i === 1) { shot.x = this.#ship.x - 5; } else { shot.x = this.#ship.x + 5; From 53a4455af536c2e5c1578732388cadfbf16bbcee Mon Sep 17 00:00:00 2001 From: Thomas Renger Date: Tue, 19 Sep 2023 22:25:56 +0200 Subject: [PATCH 24/24] chore define rul --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 5c9e58b..3dc7679 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -47,6 +47,7 @@ "@typescript-eslint/await-thenable": "error", "@typescript-eslint/explicit-function-return-type": "error", "@typescript-eslint/naming-convention": "error", + "@typescript-eslint/no-explicit-any": 0, "@typescript-eslint/no-floating-promises": "error", "no-nested-ternary": "error", "no-shadow": "off",