-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: made seperate components / fixed routing etc.
- Loading branch information
1 parent
2c02421
commit f65f00b
Showing
6 changed files
with
85 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1 @@ | ||
<canvas id="canvas"></canvas> | ||
<button (click)="onSleep()" class="btn btn-primary"> | ||
<div *ngIf="isAsleep;else other_content"> | ||
<span>Aufwachen</span> | ||
</div> | ||
<ng-template #other_content> | ||
<span>Schlafen</span> | ||
</ng-template> | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
<p>sleep-scene works!</p> | ||
<app-show-sygotchi></app-show-sygotchi> | ||
<button (click)="onSleep()" class="btn btn-primary"> | ||
<div *ngIf="isAsleep;else goSleep"> | ||
<span>Aufwachen</span> | ||
</div> | ||
<ng-template #goSleep> | ||
<span>Schlafen</span> | ||
</ng-template> | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |