Skip to content

Commit 3dbce39

Browse files
author
Frederick Behringer
committed
Backend connection is now workign!
1 parent 3f01c75 commit 3dbce39

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

backend/src/models/MauMau.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class MauMau {
9595
action: 'drawCard',
9696
data: {
9797
card: card,
98-
markerId: data.data.markerid,
98+
markerId: data.data.markerId,
9999
handcards: user.handcards,
100100
nextActions: [ 'endTurn', 'playCard' ]
101101
}

frontend-vue/src/components/ar-component/ArComponent.vue

+12-4
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,23 @@ function isCardBack(marker) {
153153
154154
function turnCard(marker) {
155155
const imageEl = marker.querySelector('#card');
156-
imageEl.setAttribute('src', props.cardService.cardBack);
156+
const cardState = imageEl.getAttribute('data-state');
157+
if (cardState !== 'back') {
158+
imageEl.setAttribute('data-state', 'back');
159+
imageEl.setAttribute('src', props.cardService.cardBack);
160+
}
157161
}
158162
159163
function showCard(marker) {
160164
const imageEl = marker.querySelector('#card');
165+
const cardState = imageEl.getAttribute('data-state');
161166
let id = marker.getAttribute('id');
162-
props.cardService.getCardByMarker(id).then((card) => {
163-
imageEl.setAttribute('src', card.url);
164-
});
167+
if (cardState !== 'front') {
168+
imageEl.setAttribute('data-state', 'front');
169+
props.cardService.getCardByMarker(id).then((card) => {
170+
imageEl.setAttribute('src', card.url);
171+
});
172+
}
165173
}
166174
167175
function addFoundMarker(marker, markerList) {

frontend-vue/src/components/ar-component/CardService.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class CardService {
1919
this.cardCallbacks = new Map<string, Function>();
2020
// conService.onConnection(() => this.numberOfCards = conService.game.value!.deck.length);
2121
conService.onConnection(() => this.numberOfCards = 40); // Todo: Marker Anzahl?!
22+
conService.onCardDrawed((markerId, cardName) => this.registerMarker(markerId, cardName));
2223
}
2324

2425
private getCardUrl(cardName: string) {

frontend-vue/src/services/ConnectionService.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class ConnectionService {
1313
store: any;
1414
cookies = useCookies(['username', 'roomId', 'userId']);
1515
connectionCallbacks: (() => void)[] = [ ];
16+
drawCardCallbacks: ((markerId: string, cardName: string) => void)[] = [ ];
1617

1718
public room = ref<Room>();
1819
public game = ref<Game>();
@@ -108,7 +109,7 @@ export class ConnectionService {
108109
this.router.push(`/${this.room.value.selectedGame}?roomId=${data.data.roomId}`);
109110
break;
110111
case 'drawCard':
111-
// registerMarker(data.data.markerId, data.data.card);
112+
this.drawCardCallbacks.forEach((callback) => callback(data.data.markerId, data.data.card))
112113
break;
113114
default:
114115
console.warn('Unhandled action', data.action, data);
@@ -141,4 +142,8 @@ export class ConnectionService {
141142
}
142143
this.connectionCallbacks.push(callback);
143144
}
145+
146+
public onCardDrawed(callback: (markerId: string, cardName: string) => void) {
147+
this.drawCardCallbacks.push(callback);
148+
}
144149
}

0 commit comments

Comments
 (0)