Skip to content

Commit

Permalink
Backend connection is now workign!
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederick Behringer committed Feb 21, 2024
1 parent 3f01c75 commit 3dbce39
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/src/models/MauMau.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class MauMau {
action: 'drawCard',
data: {
card: card,
markerId: data.data.markerid,
markerId: data.data.markerId,
handcards: user.handcards,
nextActions: [ 'endTurn', 'playCard' ]
}
Expand Down
16 changes: 12 additions & 4 deletions frontend-vue/src/components/ar-component/ArComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,23 @@ function isCardBack(marker) {
function turnCard(marker) {
const imageEl = marker.querySelector('#card');
imageEl.setAttribute('src', props.cardService.cardBack);
const cardState = imageEl.getAttribute('data-state');
if (cardState !== 'back') {
imageEl.setAttribute('data-state', 'back');
imageEl.setAttribute('src', props.cardService.cardBack);
}
}
function showCard(marker) {
const imageEl = marker.querySelector('#card');
const cardState = imageEl.getAttribute('data-state');
let id = marker.getAttribute('id');
props.cardService.getCardByMarker(id).then((card) => {
imageEl.setAttribute('src', card.url);
});
if (cardState !== 'front') {
imageEl.setAttribute('data-state', 'front');
props.cardService.getCardByMarker(id).then((card) => {
imageEl.setAttribute('src', card.url);
});
}
}
function addFoundMarker(marker, markerList) {
Expand Down
1 change: 1 addition & 0 deletions frontend-vue/src/components/ar-component/CardService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class CardService {
this.cardCallbacks = new Map<string, Function>();
// conService.onConnection(() => this.numberOfCards = conService.game.value!.deck.length);
conService.onConnection(() => this.numberOfCards = 40); // Todo: Marker Anzahl?!
conService.onCardDrawed((markerId, cardName) => this.registerMarker(markerId, cardName));
}

private getCardUrl(cardName: string) {
Expand Down
7 changes: 6 additions & 1 deletion frontend-vue/src/services/ConnectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class ConnectionService {
store: any;
cookies = useCookies(['username', 'roomId', 'userId']);
connectionCallbacks: (() => void)[] = [ ];
drawCardCallbacks: ((markerId: string, cardName: string) => void)[] = [ ];

public room = ref<Room>();
public game = ref<Game>();
Expand Down Expand Up @@ -108,7 +109,7 @@ export class ConnectionService {
this.router.push(`/${this.room.value.selectedGame}?roomId=${data.data.roomId}`);
break;
case 'drawCard':
// registerMarker(data.data.markerId, data.data.card);
this.drawCardCallbacks.forEach((callback) => callback(data.data.markerId, data.data.card))
break;
default:
console.warn('Unhandled action', data.action, data);
Expand Down Expand Up @@ -141,4 +142,8 @@ export class ConnectionService {
}
this.connectionCallbacks.push(callback);
}

public onCardDrawed(callback: (markerId: string, cardName: string) => void) {
this.drawCardCallbacks.push(callback);
}
}

0 comments on commit 3dbce39

Please sign in to comment.