From af2606c1a5ed579694df6ae4e0262cc32f47cf12 Mon Sep 17 00:00:00 2001 From: Jan Steppacher Date: Fri, 4 Aug 2023 13:07:05 +0200 Subject: [PATCH 1/2] fix: console errors --- .../clean-function.component.ts | 10 ++++++---- .../gym-function/gym-function.component.ts | 12 ++++++----- .../kitchen-function.component.ts | 20 ++++++++++--------- src/app/needs/needs.component.html | 2 +- src/app/needs/needs.component.ts | 4 ---- src/app/sleep-scene/sleep-scene.component.ts | 6 ++++-- 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/app/clean-function/clean-function.component.ts b/src/app/clean-function/clean-function.component.ts index 482d9f7..0c70b03 100644 --- a/src/app/clean-function/clean-function.component.ts +++ b/src/app/clean-function/clean-function.component.ts @@ -20,8 +20,10 @@ export class CleanFunctionComponent implements OnInit { ngOnInit(): void { this.store.select(selectSygotchi).subscribe(SyGotchi => { - this.isDirty = SyGotchi.dirty - this.sygotchi = SyGotchi + if(SyGotchi) { + this.isDirty = SyGotchi.dirty + this.sygotchi = SyGotchi + } }) } clean(){ @@ -34,14 +36,14 @@ export class CleanFunctionComponent implements OnInit { () => { this.message.Error = true this.message.text = "Sygotchi ist nicht dreckig genug!" - this.messageHandler() + this.messageHandler() } ) }else{ this.message.Error = true this.message.text = "Sygotchi ist nicht dreckig genug!" - this.messageHandler() + this.messageHandler() } } messageHandler() { diff --git a/src/app/gym-function/gym-function.component.ts b/src/app/gym-function/gym-function.component.ts index d2e847d..c15cefa 100644 --- a/src/app/gym-function/gym-function.component.ts +++ b/src/app/gym-function/gym-function.component.ts @@ -1,4 +1,4 @@ -import { Component } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; import { SyGotchi } from '../entities/syGotchi'; import { ActionsService } from '../services/actions.service'; import { Store } from '@ngrx/store'; @@ -10,7 +10,7 @@ import { setSygotchi } from '../store/sygotchi.actions'; templateUrl: './gym-function.component.html', styleUrls: ['./gym-function.component.scss'] }) -export class GymFunctionComponent { +export class GymFunctionComponent implements OnInit { isTired: number = 0 isBored: number message = {text: '', error: false} @@ -23,9 +23,11 @@ export class GymFunctionComponent { this.store.select(selectSygotchi) .subscribe( syGotchi => { - this.isTired = syGotchi.tired - this.isBored = syGotchi.bored - this.sygotchi = syGotchi + if(syGotchi) { + this.isTired = syGotchi.tired + this.isBored = syGotchi.bored + this.sygotchi = syGotchi + } } ) } diff --git a/src/app/kitchen-function/kitchen-function.component.ts b/src/app/kitchen-function/kitchen-function.component.ts index 66c5b6e..be2c4d6 100644 --- a/src/app/kitchen-function/kitchen-function.component.ts +++ b/src/app/kitchen-function/kitchen-function.component.ts @@ -25,16 +25,18 @@ export class KitchenFunctionComponent implements OnInit{ this.store.select(selectSygotchi) .subscribe( syGotchi => { - this.isHungry = syGotchi.hunger - this.isThirsty = syGotchi.thirst - this.feedCooldown = syGotchi.feedCooldown - this.drinkCooldown = syGotchi.drinkCooldown - this.sygotchi = syGotchi + if(syGotchi) { + this.isHungry = syGotchi.hunger + this.isThirsty = syGotchi.thirst + this.feedCooldown = syGotchi.feedCooldown + this.drinkCooldown = syGotchi.drinkCooldown + this.sygotchi = syGotchi + } } ) } feed(){ - + if(this.isHungry <= 90){ if(this.feedCooldown > 0){ this.message.error = true @@ -55,7 +57,7 @@ export class KitchenFunctionComponent implements OnInit{ this.messageHandler() }) } - + } } drink(){ @@ -78,7 +80,7 @@ export class KitchenFunctionComponent implements OnInit{ this.messageHandler() }) } - + } } messageHandler() { @@ -90,4 +92,4 @@ export class KitchenFunctionComponent implements OnInit{ }, 7000) } } -} \ No newline at end of file +} diff --git a/src/app/needs/needs.component.html b/src/app/needs/needs.component.html index 601ed4c..810f142 100644 --- a/src/app/needs/needs.component.html +++ b/src/app/needs/needs.component.html @@ -25,7 +25,7 @@
-