From d4525378f5f1d04b29ce02645f0243c86ee336be Mon Sep 17 00:00:00 2001 From: Henrik04 Date: Wed, 2 Aug 2023 09:58:22 +0200 Subject: [PATCH 01/10] add show component --- src/app/app.module.ts | 4 +++- src/app/misc/app.routes.ts | 7 +++++-- src/app/show-sygotchi/show-sygotchi.component.html | 1 + src/app/show-sygotchi/show-sygotchi.component.scss | 0 src/app/show-sygotchi/show-sygotchi.component.ts | 10 ++++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/app/show-sygotchi/show-sygotchi.component.html create mode 100644 src/app/show-sygotchi/show-sygotchi.component.scss create mode 100644 src/app/show-sygotchi/show-sygotchi.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 16ea6e5..5bdfb80 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -15,6 +15,7 @@ import {sygotchiReducer} from "./store/sygotchi.reducer"; import { TeamSComponent } from './team-s/team-s.component'; import { DsgvoPageComponent } from './dsgvo-page/dsgvo-page.component'; import { ImpressumComponent } from './impressum/impressum.component'; +import { ShowSygotchiComponent } from './show-sygotchi/show-sygotchi.component'; @NgModule({ declarations: [ @@ -23,7 +24,8 @@ import { ImpressumComponent } from './impressum/impressum.component'; CreationPageComponent, TeamSComponent, DsgvoPageComponent, - ImpressumComponent + ImpressumComponent, + ShowSygotchiComponent ], imports: [ BrowserModule, diff --git a/src/app/misc/app.routes.ts b/src/app/misc/app.routes.ts index 9076161..1747b47 100644 --- a/src/app/misc/app.routes.ts +++ b/src/app/misc/app.routes.ts @@ -5,6 +5,7 @@ import {AuthGuard} from "./auth.guard"; import { TeamSComponent } from "../team-s/team-s.component"; import { DsgvoPageComponent } from "../dsgvo-page/dsgvo-page.component"; import { ImpressumComponent } from "../impressum/impressum.component"; +import { ShowSygotchiComponent } from "../show-sygotchi/show-sygotchi.component"; export const APP_ROUTES: Routes = [ {path: '', redirectTo: 'auth', pathMatch: 'full'}, @@ -12,6 +13,8 @@ export const APP_ROUTES: Routes = [ {path: 'creation', component: CreationPageComponent, canActivate: [AuthGuard]}, {path: 'team-site', component: TeamSComponent}, {path: 'dsgvo', component: DsgvoPageComponent}, - {path: 'impressum', component: ImpressumComponent}, - {path: '**', redirectTo: 'auth'} + {path: 'impressum', component: ImpressumComponent }, + {path: 'sygotchi', component: ShowSygotchiComponent, canActivate: [AuthGuard]}, + {path: '**', redirectTo: 'auth' } + ] diff --git a/src/app/show-sygotchi/show-sygotchi.component.html b/src/app/show-sygotchi/show-sygotchi.component.html new file mode 100644 index 0000000..e330165 --- /dev/null +++ b/src/app/show-sygotchi/show-sygotchi.component.html @@ -0,0 +1 @@ +

show-sygotchi works!

diff --git a/src/app/show-sygotchi/show-sygotchi.component.scss b/src/app/show-sygotchi/show-sygotchi.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/show-sygotchi/show-sygotchi.component.ts b/src/app/show-sygotchi/show-sygotchi.component.ts new file mode 100644 index 0000000..6a69edf --- /dev/null +++ b/src/app/show-sygotchi/show-sygotchi.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-show-sygotchi', + templateUrl: './show-sygotchi.component.html', + styleUrls: ['./show-sygotchi.component.scss'] +}) +export class ShowSygotchiComponent { + +} From a9dbffba2761da0d6fe146873b0a4aca79f06a30 Mon Sep 17 00:00:00 2001 From: Jan Steppacher Date: Wed, 2 Aug 2023 10:01:46 +0200 Subject: [PATCH 02/10] fix: pr conflicts --- src/app/app.module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 1f5c2e3..ffb2e42 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -27,7 +27,7 @@ import { HeaderComponent } from './header/header.component'; TeamSComponent, DsgvoPageComponent, ImpressumComponent, - ShowSygotchiComponent + ShowSygotchiComponent, ImpressumComponent, SygotchiErstellenComponent, ImpressumComponent, From 1dfb361d4f33c36833314d19402c19e3e855b7b7 Mon Sep 17 00:00:00 2001 From: woddel0 <67361878+woddel0@users.noreply.github.com> Date: Wed, 2 Aug 2023 10:24:44 +0200 Subject: [PATCH 03/10] feat: websocket impl. --- src/app/auth-page/auth-page.component.ts | 8 +++++++- src/app/services/actions.service.ts | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/app/services/actions.service.ts diff --git a/src/app/auth-page/auth-page.component.ts b/src/app/auth-page/auth-page.component.ts index 354d2d6..df0028a 100644 --- a/src/app/auth-page/auth-page.component.ts +++ b/src/app/auth-page/auth-page.component.ts @@ -5,6 +5,8 @@ import { AuthService } from '../services/auth.service'; import { Store, resultMemoize } from '@ngrx/store'; import { WebsocketService } from '../services/websocket.service'; import { HttpStatusCode } from '@angular/common/http'; +import { setSygotchi } from '../store/sygotchi.actions'; +import { SyGotchi } from '../entities/syGotchi'; @Component({ selector: 'app-auth-page', @@ -17,7 +19,7 @@ export class AuthPageComponent implements OnInit { showError: boolean = false errorMessage: string = '' - constructor(private fb: FormBuilder, private router: Router, private authService: AuthService, private store: Store, private wsService: WebsocketService) {} + constructor(private fb: FormBuilder, private router: Router, private authService: AuthService, private store: Store, private wsService: WebsocketService, private actionsService) {} ngOnInit() { localStorage.clear() @@ -59,6 +61,10 @@ export class AuthPageComponent implements OnInit { localStorage.setItem('token', result["token"]) localStorage.setItem('id', result["id"]), + this.actionsService.getSyGotchi().subscribe(result =>{ + this.store.dispatch(setSygotchi({sygotchi:result as SyGotchi})) + this.wsService.initializeWebSocketConnection(result.id) + }); () => { this.router.navigate(['/creation']) } diff --git a/src/app/services/actions.service.ts b/src/app/services/actions.service.ts new file mode 100644 index 0000000..849d278 --- /dev/null +++ b/src/app/services/actions.service.ts @@ -0,0 +1,24 @@ +import { HttpClient } from "@angular/common/http"; +import { Injectable } from "@angular/core"; +import { Observable } from "rxjs"; +import { environment } from "src/environments/environment"; +import { SyGotchi } from "../entities/syGotchi"; +import { setSygotchi } from "../store/sygotchi.actions"; + +@Injectable({ + providedIn:'root' +}) +export class ActionsService{ + apiUrl=environment.apiUrl + + constructor(private http: HttpClient) {} + + getAccountInfo { + const id= localStorage.getItem('id') + return this.http.get('${this.apiUrl}/user/${id}') + } + + getSygotchi(): Observable { + return.this.http.get('$({this.apiUrl}/tamagotchi') + } +} From b1e2217d8cea9baa4e95953ff816d954994bf0c5 Mon Sep 17 00:00:00 2001 From: "@akg" Date: Wed, 2 Aug 2023 10:31:01 +0200 Subject: [PATCH 04/10] fix: auth-page websocket impl. --- src/app/auth-page/auth-page.component.ts | 17 ++++++------ src/app/services/actions.service.ts | 35 ++++++++++++------------ 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/app/auth-page/auth-page.component.ts b/src/app/auth-page/auth-page.component.ts index df0028a..d93216b 100644 --- a/src/app/auth-page/auth-page.component.ts +++ b/src/app/auth-page/auth-page.component.ts @@ -46,7 +46,7 @@ export class AuthPageComponent implements OnInit { this.errorMessage = 'Unerwarteter Fehler' this.showError = true; } - } + } ); } else { this.errorMessage = 'Passwörter stimmen nicht überein.' @@ -60,14 +60,15 @@ export class AuthPageComponent implements OnInit { result => { localStorage.setItem('token', result["token"]) localStorage.setItem('id', result["id"]), - - this.actionsService.getSyGotchi().subscribe(result =>{ - this.store.dispatch(setSygotchi({sygotchi:result as SyGotchi})) - this.wsService.initializeWebSocketConnection(result.id) - }); + + this.actionsService.getSygotchi().subscribe(result => { + this.store.dispatch(setSygotchi({sygotchi: result as SyGotchi})) + + this.wsService.initializeWebSocketConnection(result.id) + }, () => { this.router.navigate(['/creation']) - } + }) }, err => { if (err.status === HttpStatusCode.BadRequest) { @@ -94,4 +95,4 @@ export class AuthPageComponent implements OnInit { -} \ No newline at end of file +} diff --git a/src/app/services/actions.service.ts b/src/app/services/actions.service.ts index 849d278..09ce36d 100644 --- a/src/app/services/actions.service.ts +++ b/src/app/services/actions.service.ts @@ -1,24 +1,25 @@ -import { HttpClient } from "@angular/common/http"; -import { Injectable } from "@angular/core"; -import { Observable } from "rxjs"; -import { environment } from "src/environments/environment"; -import { SyGotchi } from "../entities/syGotchi"; -import { setSygotchi } from "../store/sygotchi.actions"; +import { Injectable } from '@angular/core'; +import {HttpClient} from "@angular/common/http"; +import {Observable} from "rxjs"; +import {SyGotchi} from "../entities/syGotchi"; +import {environment} from "../../environments/environment"; @Injectable({ - providedIn:'root' + providedIn: 'root' }) -export class ActionsService{ - apiUrl=environment.apiUrl +export class ActionsService { + apiUrl = environment.apiUrl - constructor(private http: HttpClient) {} + constructor(private http: HttpClient) { + } - getAccountInfo { - const id= localStorage.getItem('id') - return this.http.get('${this.apiUrl}/user/${id}') - } + getAccountInfo() { + const id = localStorage.getItem('id') - getSygotchi(): Observable { - return.this.http.get('$({this.apiUrl}/tamagotchi') - } + return this.http.get(`${this.apiUrl}/user/${id}`) + } + + getSygotchi(): Observable { + return this.http.get(`${this.apiUrl}/tamagotchi`) + } } From 2d83a5e2ab2292276a65232872cf87af7914abba Mon Sep 17 00:00:00 2001 From: Henrik04 Date: Wed, 2 Aug 2023 10:40:48 +0200 Subject: [PATCH 05/10] added show sygotchi --- src/app/services/actions.service.ts | 4 + .../show-sygotchi.component.html | 2 +- .../show-sygotchi/show-sygotchi.component.ts | 104 +++++++++++++++++- .../sygotchi-erstellen.component.ts | 15 ++- 4 files changed, 121 insertions(+), 4 deletions(-) diff --git a/src/app/services/actions.service.ts b/src/app/services/actions.service.ts index 297a197..c55229f 100644 --- a/src/app/services/actions.service.ts +++ b/src/app/services/actions.service.ts @@ -15,4 +15,8 @@ export class ActionsService { createSygotchi(name, eyes, shape, color, height, width): Observable { return this.http.post(`${this.apiUrl}/tamagotchi`, { name, eyes, shape, color, height, width }) } + + getSygotchi(): Observable { + return this.http.get(`${this.apiUrl}/tamagotchi`) + } } diff --git a/src/app/show-sygotchi/show-sygotchi.component.html b/src/app/show-sygotchi/show-sygotchi.component.html index e330165..c06ca25 100644 --- a/src/app/show-sygotchi/show-sygotchi.component.html +++ b/src/app/show-sygotchi/show-sygotchi.component.html @@ -1 +1 @@ -

show-sygotchi works!

+ diff --git a/src/app/show-sygotchi/show-sygotchi.component.ts b/src/app/show-sygotchi/show-sygotchi.component.ts index 6a69edf..77f0b8b 100644 --- a/src/app/show-sygotchi/show-sygotchi.component.ts +++ b/src/app/show-sygotchi/show-sygotchi.component.ts @@ -1,10 +1,110 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; +import { ActionsService } from '../services/actions.service'; +import { SyGotchi } from '../entities/syGotchi'; +import * as paper from 'paper'; +import { Eye } from '../enums/eye.enum'; +import { Project } from "paper"; @Component({ selector: 'app-show-sygotchi', templateUrl: './show-sygotchi.component.html', styleUrls: ['./show-sygotchi.component.scss'] }) -export class ShowSygotchiComponent { +export class ShowSygotchiComponent implements OnInit { + sygotchi: SyGotchi + canvas: any + shapePath: any + shape: any + constructor(private actonsService: ActionsService) { } + + ngOnInit(): void { + window['paper'] = paper; + new Project('canvas'); + + this.canvas = paper.project.activeLayer; + + this.actonsService.getSygotchi().subscribe(result => { + this.sygotchi = result + + this.buildSygotchi() + }) + } + + buildSygotchi() { + const shapeType = this.sygotchi.shape; + const color = this.sygotchi.color; + const width = this.sygotchi.width; + const height = this.sygotchi.height; + const eyes = this.sygotchi.eyes; + let eyeSize; + let pupilSize; + + switch(eyes){ + + case Eye.SMALL: + eyeSize = Math.min(width, height) * 0.1; + pupilSize = eyeSize * 0.5; + break; + + case Eye.MEDIUM: + eyeSize = Math.min(width, height) * 0.2; + pupilSize = eyeSize * 0.5; + break; + + case Eye.LARGE: + eyeSize = Math.min(width, height) * 0.3; + pupilSize = eyeSize * 0.5; + break; + } + switch(shapeType){ + case 'TRIANGLE': + this.shape = new paper.Path.RegularPolygon({ + center: paper.view.center, + sides: 3, + radius: width / 2, + fillColor: color + }); + break; + + case 'RECTANGLE': + this.shape = new paper.Path.Rectangle({ + point: paper.view.center.subtract(new paper.Point(width / 2, height / 2)), + size: [width, height], + fillColor: color + }); + break; + case 'CIRCLE': + this.shape = new paper.Path.Circle({ + center: paper.view.center, + radius: width / 2, + fillColor: color + }); + break; + } + const eyeLeft = new paper.Path.Circle({ + center: this.shape.position.subtract(new paper .Point(width / 4, height / 10)), + radius: eyeSize, + fillColor: 'white' + }) + const eyeRight = new paper.Path.Circle({ + center: this.shape.position.subtract(new paper .Point(-width / 4, height / 10)), + radius: eyeSize, + fillColor: 'white' + }) + const pupilLeft = new paper.Path.Circle({ + center: eyeLeft.position.add(new paper.Point(0, eyeSize * 0.1)), + radius: pupilSize, + fillColor: 'black' + }) + const pupilRight = new paper.Path.Circle({ + center: eyeRight.position.add(new paper.Point(0, eyeSize * 0.1)), + radius: pupilSize, + fillColor: 'black' + }) + this.shapePath = new paper.Group({ + children: [this.shape, eyeLeft, eyeRight, pupilRight, pupilLeft] + }) + this.canvas.addChild(this.shapePath); + } } diff --git a/src/app/sygotchi-erstellen/sygotchi-erstellen.component.ts b/src/app/sygotchi-erstellen/sygotchi-erstellen.component.ts index 4c61f4a..0e39083 100644 --- a/src/app/sygotchi-erstellen/sygotchi-erstellen.component.ts +++ b/src/app/sygotchi-erstellen/sygotchi-erstellen.component.ts @@ -126,7 +126,20 @@ export class SygotchiErstellenComponent implements OnInit{ createShape() { const characterData = this.characterForm.value; - this.actionsService.createSygotchi(characterData.name, characterData.eyes, characterData.shape, characterData.color, characterData.height, characterData.width).subscribe(result => { + let eye: Eye = Eye.SMALL + switch (characterData.eyes) { + case 1: + eye = Eye.SMALL + break; + case 2: + eye = Eye.MEDIUM + break; + case 3: + eye = Eye.LARGE + break; + } + + this.actionsService.createSygotchi(characterData.name, eye, characterData.shape, characterData.color, characterData.height, characterData.width).subscribe(result => { this.store.dispatch(setSygotchi({sygotchi: result as any})) this.wsService.initializeWebSocketConnection(result.id) From 2c02421a00497deb667709ffdd0fb8ec98c72aa6 Mon Sep 17 00:00:00 2001 From: Henrik04 Date: Wed, 2 Aug 2023 12:14:46 +0200 Subject: [PATCH 06/10] added sleep function --- src/app/app.module.ts | 4 +- src/app/services/actions.service.ts | 9 ++++ .../show-sygotchi.component.html | 8 ++++ .../show-sygotchi/show-sygotchi.component.ts | 42 +++++++++++++++++-- .../sleep-scene/sleep-scene.component.html | 1 + .../sleep-scene/sleep-scene.component.scss | 0 src/app/sleep-scene/sleep-scene.component.ts | 10 +++++ 7 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 src/app/sleep-scene/sleep-scene.component.html create mode 100644 src/app/sleep-scene/sleep-scene.component.scss create mode 100644 src/app/sleep-scene/sleep-scene.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index ffb2e42..f06ce5b 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -18,6 +18,7 @@ import { ImpressumComponent } from './impressum/impressum.component'; import { ShowSygotchiComponent } from './show-sygotchi/show-sygotchi.component'; import { SygotchiErstellenComponent } from './sygotchi-erstellen/sygotchi-erstellen.component'; import { HeaderComponent } from './header/header.component'; +import { SleepSceneComponent } from './sleep-scene/sleep-scene.component'; @NgModule({ declarations: [ @@ -31,7 +32,8 @@ import { HeaderComponent } from './header/header.component'; ImpressumComponent, SygotchiErstellenComponent, ImpressumComponent, - HeaderComponent + HeaderComponent, + SleepSceneComponent ], imports: [ BrowserModule, diff --git a/src/app/services/actions.service.ts b/src/app/services/actions.service.ts index c55229f..ce9c04a 100644 --- a/src/app/services/actions.service.ts +++ b/src/app/services/actions.service.ts @@ -19,4 +19,13 @@ export class ActionsService { getSygotchi(): Observable { return this.http.get(`${this.apiUrl}/tamagotchi`) } + + sleep(): Observable { + return this.http.post(`${this.apiUrl}/tamagotchi`, null) + } + + wakeUp(): Observable { + return this.http.post(`${this.apiUrl}/tamagotchi`, null) + } + } diff --git a/src/app/show-sygotchi/show-sygotchi.component.html b/src/app/show-sygotchi/show-sygotchi.component.html index c06ca25..eeead02 100644 --- a/src/app/show-sygotchi/show-sygotchi.component.html +++ b/src/app/show-sygotchi/show-sygotchi.component.html @@ -1 +1,9 @@ + \ No newline at end of file diff --git a/src/app/show-sygotchi/show-sygotchi.component.ts b/src/app/show-sygotchi/show-sygotchi.component.ts index 77f0b8b..5087c48 100644 --- a/src/app/show-sygotchi/show-sygotchi.component.ts +++ b/src/app/show-sygotchi/show-sygotchi.component.ts @@ -4,6 +4,9 @@ import { SyGotchi } from '../entities/syGotchi'; import * as paper from 'paper'; import { Eye } from '../enums/eye.enum'; import { Project } from "paper"; +import { WebsocketService } from '../services/websocket.service'; +import { selectSygotchi } from '../store/sygotchi.selectors'; +import { setSygotchi } from '../store/sygotchi.actions'; @Component({ selector: 'app-show-sygotchi', @@ -15,8 +18,9 @@ export class ShowSygotchiComponent implements OnInit { canvas: any shapePath: any shape: any + isAsleep: boolean = false - constructor(private actonsService: ActionsService) { } + constructor(private actionsService: ActionsService, private store: Store, private wsService: WebsocketService) { } ngOnInit(): void { window['paper'] = paper; @@ -24,12 +28,26 @@ export class ShowSygotchiComponent implements OnInit { this.canvas = paper.project.activeLayer; - this.actonsService.getSygotchi().subscribe(result => { + this.actionsService.getSygotchi().subscribe(result => { this.sygotchi = result + this.store.select(selectSygotchi).subscribe(result => { + this.sygotchi = result - this.buildSygotchi() + if (this.sygotchi === null) { + this.actionsService.getSygotchi().subscribe(result => { + this.sygotchi = result + this.store.dispach(setSygotchi({ sygotchi: result as SyGotchi })) + this.buildSygotchi() + }) + } + + + this.buildSygotchi() + this.getSleepStatus() + }) }) } + buildSygotchi() { const shapeType = this.sygotchi.shape; @@ -107,4 +125,22 @@ export class ShowSygotchiComponent implements OnInit { }) this.canvas.addChild(this.shapePath); } + + onSleep() { + if (this.isAsleep) { + this.isAsleep = false + this.actonsService.sleep().subscribe(sygotchi => { + this.sygotchi = sygotchi + }) + } else { + this.isAsleep = true + this.actonsService.wakeUp().subscribe(sygotchi => { + this.sygotchi = sygotchi + }) + } + } + + getSleepStatus() { + + } } diff --git a/src/app/sleep-scene/sleep-scene.component.html b/src/app/sleep-scene/sleep-scene.component.html new file mode 100644 index 0000000..03bd63f --- /dev/null +++ b/src/app/sleep-scene/sleep-scene.component.html @@ -0,0 +1 @@ +

sleep-scene works!

diff --git a/src/app/sleep-scene/sleep-scene.component.scss b/src/app/sleep-scene/sleep-scene.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/sleep-scene/sleep-scene.component.ts b/src/app/sleep-scene/sleep-scene.component.ts new file mode 100644 index 0000000..b00d254 --- /dev/null +++ b/src/app/sleep-scene/sleep-scene.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-sleep-scene', + templateUrl: './sleep-scene.component.html', + styleUrls: ['./sleep-scene.component.scss'] +}) +export class SleepSceneComponent { + +} From f65f00bb836a0df82b33e0704e03613e33434806 Mon Sep 17 00:00:00 2001 From: Jan Steppacher Date: Wed, 2 Aug 2023 12:49:49 +0200 Subject: [PATCH 07/10] feat: made seperate components / fixed routing etc. --- src/app/misc/app.routes.ts | 5 +- src/app/services/actions.service.ts | 6 +- .../show-sygotchi.component.html | 8 --- .../show-sygotchi/show-sygotchi.component.ts | 33 ++-------- .../sleep-scene/sleep-scene.component.html | 10 ++- src/app/sleep-scene/sleep-scene.component.ts | 66 ++++++++++++++++++- 6 files changed, 85 insertions(+), 43 deletions(-) diff --git a/src/app/misc/app.routes.ts b/src/app/misc/app.routes.ts index eee3494..d483f3f 100644 --- a/src/app/misc/app.routes.ts +++ b/src/app/misc/app.routes.ts @@ -5,7 +5,7 @@ import { SygotchiErstellenComponent } from "../sygotchi-erstellen/sygotchi-erste import { TeamSComponent } from "../team-s/team-s.component"; import { DsgvoPageComponent } from "../dsgvo-page/dsgvo-page.component"; import { ImpressumComponent } from "../impressum/impressum.component"; -import { ShowSygotchiComponent } from "../show-sygotchi/show-sygotchi.component"; +import {SleepSceneComponent} from "../sleep-scene/sleep-scene.component"; export const APP_ROUTES: Routes = [ {path: '', redirectTo: 'auth', pathMatch: 'full'}, @@ -14,7 +14,6 @@ export const APP_ROUTES: Routes = [ {path: 'team-site', component: TeamSComponent}, {path: 'dsgvo', component: DsgvoPageComponent}, {path: 'impressum', component: ImpressumComponent }, - {path: 'sygotchi', component: ShowSygotchiComponent, canActivate: [AuthGuard]}, + {path: 'sleep', component: SleepSceneComponent, canActivate: [AuthGuard]}, {path: '**', redirectTo: 'auth' } - ] diff --git a/src/app/services/actions.service.ts b/src/app/services/actions.service.ts index ce9c04a..545db48 100644 --- a/src/app/services/actions.service.ts +++ b/src/app/services/actions.service.ts @@ -21,11 +21,11 @@ export class ActionsService { } sleep(): Observable { - return this.http.post(`${this.apiUrl}/tamagotchi`, null) - } + return this.http.post(`${this.apiUrl}/tamagotchi/sleep`, null) + } wakeUp(): Observable { - return this.http.post(`${this.apiUrl}/tamagotchi`, null) + return this.http.post(`${this.apiUrl}/tamagotchi/wakeUp`, null) } } diff --git a/src/app/show-sygotchi/show-sygotchi.component.html b/src/app/show-sygotchi/show-sygotchi.component.html index eeead02..c06ca25 100644 --- a/src/app/show-sygotchi/show-sygotchi.component.html +++ b/src/app/show-sygotchi/show-sygotchi.component.html @@ -1,9 +1 @@ - \ No newline at end of file diff --git a/src/app/show-sygotchi/show-sygotchi.component.ts b/src/app/show-sygotchi/show-sygotchi.component.ts index 5087c48..7e2b3ea 100644 --- a/src/app/show-sygotchi/show-sygotchi.component.ts +++ b/src/app/show-sygotchi/show-sygotchi.component.ts @@ -7,6 +7,7 @@ import { Project } from "paper"; import { WebsocketService } from '../services/websocket.service'; import { selectSygotchi } from '../store/sygotchi.selectors'; import { setSygotchi } from '../store/sygotchi.actions'; +import {Store} from "@ngrx/store"; @Component({ selector: 'app-show-sygotchi', @@ -18,10 +19,9 @@ export class ShowSygotchiComponent implements OnInit { canvas: any shapePath: any shape: any - isAsleep: boolean = false constructor(private actionsService: ActionsService, private store: Store, private wsService: WebsocketService) { } - + ngOnInit(): void { window['paper'] = paper; new Project('canvas'); @@ -36,18 +36,17 @@ export class ShowSygotchiComponent implements OnInit { if (this.sygotchi === null) { this.actionsService.getSygotchi().subscribe(result => { this.sygotchi = result - this.store.dispach(setSygotchi({ sygotchi: result as SyGotchi })) + this.store.dispatch(setSygotchi({ sygotchi: result as SyGotchi })) this.buildSygotchi() }) + } else { + this.wsService.initializeWebSocketConnection(this.sygotchi.id) + this.buildSygotchi() } - - - this.buildSygotchi() - this.getSleepStatus() }) }) } - + buildSygotchi() { const shapeType = this.sygotchi.shape; @@ -125,22 +124,4 @@ export class ShowSygotchiComponent implements OnInit { }) this.canvas.addChild(this.shapePath); } - - onSleep() { - if (this.isAsleep) { - this.isAsleep = false - this.actonsService.sleep().subscribe(sygotchi => { - this.sygotchi = sygotchi - }) - } else { - this.isAsleep = true - this.actonsService.wakeUp().subscribe(sygotchi => { - this.sygotchi = sygotchi - }) - } - } - - getSleepStatus() { - - } } diff --git a/src/app/sleep-scene/sleep-scene.component.html b/src/app/sleep-scene/sleep-scene.component.html index 03bd63f..e0ea197 100644 --- a/src/app/sleep-scene/sleep-scene.component.html +++ b/src/app/sleep-scene/sleep-scene.component.html @@ -1 +1,9 @@ -

sleep-scene works!

+ + diff --git a/src/app/sleep-scene/sleep-scene.component.ts b/src/app/sleep-scene/sleep-scene.component.ts index b00d254..e31f230 100644 --- a/src/app/sleep-scene/sleep-scene.component.ts +++ b/src/app/sleep-scene/sleep-scene.component.ts @@ -1,10 +1,72 @@ -import { Component } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; +import {ActionsService} from "../services/actions.service"; +import {Store} from "@ngrx/store"; +import {SyGotchi} from "../entities/syGotchi"; +import {setSygotchi} from "../store/sygotchi.actions"; +import {selectSygotchi} from "../store/sygotchi.selectors"; @Component({ selector: 'app-sleep-scene', templateUrl: './sleep-scene.component.html', styleUrls: ['./sleep-scene.component.scss'] }) -export class SleepSceneComponent { +export class SleepSceneComponent implements OnInit { + isAsleep: boolean = false + message = {text: '', error: false} + sygotchi: SyGotchi + showMessage: boolean = false + constructor(private actionsService: ActionsService, private store: Store) {} + + ngOnInit() { + this.store.select(selectSygotchi) + .subscribe( + syGotchi => { + this.isAsleep = syGotchi.sleeping + this.sygotchi = syGotchi + } + ) + } + + onSleep() { + if(!this.isAsleep) { + this.actionsService.sleep() + .subscribe( + result => { + this.message.text = 'SyGotchi schläft nun.' + this.messageHandler() + + this.store.dispatch(setSygotchi({sygotchi: result as SyGotchi})) + }, + () => { + this.message.error = true + this.message.text = "SyGotchi ist nicht müde genug." + this.messageHandler() + } + ) + } else { + this.actionsService.wakeUp() + .subscribe( + result => { + this.message.text = 'SyGotchi ist wieder aufgewacht.' + this.messageHandler() + + this.store.dispatch(setSygotchi({sygotchi: result as SyGotchi})) + }, + () => { + this.message.error = true + this.message.text = "SyGotchi kann nicht aufwachen." + this.messageHandler() + } + ) + } + } + + messageHandler() { + this.showMessage = true + + setTimeout(() => { + this.showMessage = false + }, 7000) + } } From 57bdd18e14087bf4e3f830f2b734cea94838c7a7 Mon Sep 17 00:00:00 2001 From: Jan Steppacher Date: Wed, 2 Aug 2023 14:01:30 +0200 Subject: [PATCH 08/10] fix: fix sygotchi object being null --- .../show-sygotchi/show-sygotchi.component.ts | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/app/show-sygotchi/show-sygotchi.component.ts b/src/app/show-sygotchi/show-sygotchi.component.ts index 7e2b3ea..b03a661 100644 --- a/src/app/show-sygotchi/show-sygotchi.component.ts +++ b/src/app/show-sygotchi/show-sygotchi.component.ts @@ -28,22 +28,20 @@ export class ShowSygotchiComponent implements OnInit { this.canvas = paper.project.activeLayer; - this.actionsService.getSygotchi().subscribe(result => { + this.canvas = paper.project.activeLayer; + this.store.select(selectSygotchi).subscribe(result => { this.sygotchi = result - this.store.select(selectSygotchi).subscribe(result => { - this.sygotchi = result - if (this.sygotchi === null) { - this.actionsService.getSygotchi().subscribe(result => { - this.sygotchi = result - this.store.dispatch(setSygotchi({ sygotchi: result as SyGotchi })) - this.buildSygotchi() - }) - } else { - this.wsService.initializeWebSocketConnection(this.sygotchi.id) + if(this.sygotchi === null) { + this.actionsService.getSygotchi().subscribe(result => { + this.sygotchi = result + this.store.dispatch(setSygotchi({sygotchi: result as SyGotchi})) this.buildSygotchi() - } - }) + }) + } else { + this.wsService.initializeWebSocketConnection(this.sygotchi.id) + this.buildSygotchi() + } }) } From 48cb1bd9ea50b2dbcccaa7eb4727694d994bf43f Mon Sep 17 00:00:00 2001 From: Henrik04 Date: Wed, 2 Aug 2023 14:36:24 +0200 Subject: [PATCH 09/10] update routing --- src/app/auth-page/auth-page.component.ts | 4 ++-- src/app/sygotchi-erstellen/sygotchi-erstellen.component.ts | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/auth-page/auth-page.component.ts b/src/app/auth-page/auth-page.component.ts index d93216b..de189fd 100644 --- a/src/app/auth-page/auth-page.component.ts +++ b/src/app/auth-page/auth-page.component.ts @@ -36,7 +36,7 @@ export class AuthPageComponent implements OnInit { result => { localStorage.setItem('token', result["token"]) localStorage.setItem('id', result["id"]) - this.router.navigate(['/creation']); + this.router.navigate(['/create']); }, err => { if (err.status === HttpStatusCode.Unauthorized) { @@ -67,7 +67,7 @@ export class AuthPageComponent implements OnInit { this.wsService.initializeWebSocketConnection(result.id) }, () => { - this.router.navigate(['/creation']) + this.router.navigate(['/create']) }) }, err => { diff --git a/src/app/sygotchi-erstellen/sygotchi-erstellen.component.ts b/src/app/sygotchi-erstellen/sygotchi-erstellen.component.ts index 0e39083..bccee78 100644 --- a/src/app/sygotchi-erstellen/sygotchi-erstellen.component.ts +++ b/src/app/sygotchi-erstellen/sygotchi-erstellen.component.ts @@ -7,6 +7,7 @@ import {Store} from "@ngrx/store"; import {setSygotchi} from "../store/sygotchi.actions"; import {ActionsService} from "../services/actions.service"; import {WebsocketService} from "../services/websocket.service"; +import { Router } from '@angular/router'; @Component({ @@ -21,7 +22,7 @@ export class SygotchiErstellenComponent implements OnInit{ shape: any; shapePath: any; - constructor(private formBuilder: FormBuilder, private store: Store, private actionsService: ActionsService, private wsService: WebsocketService){ + constructor(private formBuilder: FormBuilder, private store: Store, private actionsService: ActionsService, private wsService: WebsocketService, private router: Router){ this.characterForm = this.formBuilder.group({ name: ['',Validators.required], shape: ['RECTANGLE',Validators.required], @@ -144,7 +145,7 @@ export class SygotchiErstellenComponent implements OnInit{ this.store.dispatch(setSygotchi({sygotchi: result as any})) this.wsService.initializeWebSocketConnection(result.id) - // TODO: Routing + this.router.navigate(['/sleep']); }) } } From f83a0cfb29a215ba2c8f2074fa4b1a61a8952dc3 Mon Sep 17 00:00:00 2001 From: Jan Steppacher Date: Wed, 2 Aug 2023 14:53:45 +0200 Subject: [PATCH 10/10] chore: add routing to things yo mr white --- src/app/auth-page/auth-page.component.ts | 16 +++++++++------- src/app/services/actions.service.ts | 3 --- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/app/auth-page/auth-page.component.ts b/src/app/auth-page/auth-page.component.ts index de189fd..5ec4665 100644 --- a/src/app/auth-page/auth-page.component.ts +++ b/src/app/auth-page/auth-page.component.ts @@ -7,6 +7,7 @@ import { WebsocketService } from '../services/websocket.service'; import { HttpStatusCode } from '@angular/common/http'; import { setSygotchi } from '../store/sygotchi.actions'; import { SyGotchi } from '../entities/syGotchi'; +import {ActionsService} from "../services/actions.service"; @Component({ selector: 'app-auth-page', @@ -19,7 +20,7 @@ export class AuthPageComponent implements OnInit { showError: boolean = false errorMessage: string = '' - constructor(private fb: FormBuilder, private router: Router, private authService: AuthService, private store: Store, private wsService: WebsocketService, private actionsService) {} + constructor(private fb: FormBuilder, private router: Router, private authService: AuthService, private store: Store, private wsService: WebsocketService, private actionsService: ActionsService) {} ngOnInit() { localStorage.clear() @@ -59,16 +60,17 @@ export class AuthPageComponent implements OnInit { .subscribe( result => { localStorage.setItem('token', result["token"]) - localStorage.setItem('id', result["id"]), + localStorage.setItem('id', result["id"]) this.actionsService.getSygotchi().subscribe(result => { - this.store.dispatch(setSygotchi({sygotchi: result as SyGotchi})) - + this.store.dispatch(setSygotchi({sygotchi: result as SyGotchi})) this.wsService.initializeWebSocketConnection(result.id) + + this.router.navigate(['/sleep']) }, - () => { - this.router.navigate(['/create']) - }) + () => { + this.router.navigate(['/create']) + }) }, err => { if (err.status === HttpStatusCode.BadRequest) { diff --git a/src/app/services/actions.service.ts b/src/app/services/actions.service.ts index 52d319f..21d004e 100644 --- a/src/app/services/actions.service.ts +++ b/src/app/services/actions.service.ts @@ -18,9 +18,6 @@ export class ActionsService { return this.http.get(`${this.apiUrl}/user/${id}`) } - getSygotchi(): Observable { - return this.http.get(`${this.apiUrl}/tamagotchi`) - createSygotchi(name, eyes, shape, color, height, width): Observable { return this.http.post(`${this.apiUrl}/tamagotchi`, { name, eyes, shape, color, height, width }) }