Skip to content

Commit

Permalink
remove mini-game from main app.component
Browse files Browse the repository at this point in the history
  • Loading branch information
l-brendle committed Oct 19, 2023
1 parent 51d27c1 commit 920b608
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
1 change: 0 additions & 1 deletion angular-frontend/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<bal-app class="has-sticky-footer" style="position: relative;" (mousemove)="mouseMoved($event)">
<bal-icon *ngFor="let cursor of cursors" name="edit" style="z-index: 1000; position: absolute;" [ngStyle]="{'top': cursor.posY + 'px', 'left': cursor.posX + 'px'}" [color]="cursor.color"></bal-icon>
<bal-icon *ngFor="let char of characters" name="account" style="z-index: 1000; position: absolute;" [ngStyle]="{'top': char.posY + 'px', 'left': char.posX + 'px'}" [color]="char.color"></bal-icon>
<header>
<!-- Header content -->
<bal-navbar interface="app">
Expand Down
18 changes: 0 additions & 18 deletions angular-frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ export class AppComponent implements OnDestroy {
cursors: Cursor[] = [];
inventories?: Inventory[];

// Game stuff
characters: Character[] = []

constructor() {
this.httpService = new HttpService();
this.client = new Client();
Expand All @@ -42,8 +39,6 @@ export class AppComponent implements OnDestroy {
this.client.subscribe("/topic/cursor", (payload => this.updateCursors(JSON.parse(payload.body))));
this.client.subscribe("/app/inventory", (payload => this.updateInventory(JSON.parse(payload.body))));
this.client.subscribe("/topic/inventory", (payload => this.updateInventory(JSON.parse(payload.body))));
this.client.subscribe("/topic/game/character", (payload => this.updateCharacter(JSON.parse(payload.body))))
this.client.subscribe("/topic/game/character_removal", (payload => this.removeCharacter(JSON.parse(payload.body))))
};

this.client.onWebSocketError = (error) => {
Expand Down Expand Up @@ -147,17 +142,4 @@ export class AppComponent implements OnDestroy {
});
}

updateCharacter(character : Character) {
const characterIndexToUpdate = this.characters.findIndex((char) => char.name === character.name);

if (characterIndexToUpdate === -1) {
this.characters.push(character);
} else {
this.characters[characterIndexToUpdate] = character;
}
}

removeCharacter(character : Character) {
this.characters = this.characters.filter(char => char.name != character.name)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<bal-icon *ngFor="let char of characters" name="account" style="z-index: 1000; position: absolute;" [ngStyle]="{'top': char.posY + 'px', 'left': char.posX + 'px'}" [color]="char.color"></bal-icon>
<bal-card class="mt-medium">
<bal-card-content class="is-flex fg-small">
<bal-heading level="medium">Mini-Game</bal-heading>
Expand Down
21 changes: 20 additions & 1 deletion angular-frontend/src/app/components/game/game.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Component, HostListener, Input, OnDestroy, OnInit} from '@angular/core';

import { Client } from '@stomp/stompjs';
import {Character} from "../../../model";

@Component({
selector: 'app-game',
Expand All @@ -14,9 +15,13 @@ export class GameComponent implements OnInit, OnDestroy {

connected : boolean = false;

// Game stuff
characters: Character[] = [];

ngOnInit(): void {
if (this.client.connected) {
//this.client.subscribe("/topic/chat", payload => this.addMessage(payload));
this.client.subscribe("/topic/game/character", (payload => this.updateCharacter(JSON.parse(payload.body))))
this.client.subscribe("/topic/game/character_removal", (payload => this.removeCharacter(JSON.parse(payload.body))))
}
}

Expand Down Expand Up @@ -71,4 +76,18 @@ export class GameComponent implements OnInit, OnDestroy {

}

updateCharacter(character : Character) {
const characterIndexToUpdate = this.characters.findIndex((char) => char.name === character.name);
console.log("Character update");
if (characterIndexToUpdate === -1) {
this.characters.push(character);
} else {
this.characters[characterIndexToUpdate] = character;
}
}

removeCharacter(character : Character) {
this.characters = this.characters.filter(char => char.name != character.name)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class CharacterController {

private final SimpMessagingTemplate messageSender;

private final int spawnX = 500;
private final int spawnY = 500;
private final int spawnX = 0;
private final int spawnY = 0;

public CharacterDTO createCharacterForUser(UserDTO user) {
var characterForUser = getActiveCharacterForName(user.name());
Expand Down

0 comments on commit 920b608

Please sign in to comment.