File tree 4 files changed +20
-6
lines changed
4 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ export class MauMau {
95
95
action : 'drawCard' ,
96
96
data : {
97
97
card : card ,
98
- markerId : data . data . markerid ,
98
+ markerId : data . data . markerId ,
99
99
handcards : user . handcards ,
100
100
nextActions : [ 'endTurn' , 'playCard' ]
101
101
}
Original file line number Diff line number Diff line change @@ -153,15 +153,23 @@ function isCardBack(marker) {
153
153
154
154
function turnCard (marker ) {
155
155
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
+ }
157
161
}
158
162
159
163
function showCard (marker ) {
160
164
const imageEl = marker .querySelector (' #card' );
165
+ const cardState = imageEl .getAttribute (' data-state' );
161
166
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
+ }
165
173
}
166
174
167
175
function addFoundMarker (marker , markerList ) {
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ export class CardService {
19
19
this . cardCallbacks = new Map < string , Function > ( ) ;
20
20
// conService.onConnection(() => this.numberOfCards = conService.game.value!.deck.length);
21
21
conService . onConnection ( ( ) => this . numberOfCards = 40 ) ; // Todo: Marker Anzahl?!
22
+ conService . onCardDrawed ( ( markerId , cardName ) => this . registerMarker ( markerId , cardName ) ) ;
22
23
}
23
24
24
25
private getCardUrl ( cardName : string ) {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ export class ConnectionService {
13
13
store : any ;
14
14
cookies = useCookies ( [ 'username' , 'roomId' , 'userId' ] ) ;
15
15
connectionCallbacks : ( ( ) => void ) [ ] = [ ] ;
16
+ drawCardCallbacks : ( ( markerId : string , cardName : string ) => void ) [ ] = [ ] ;
16
17
17
18
public room = ref < Room > ( ) ;
18
19
public game = ref < Game > ( ) ;
@@ -108,7 +109,7 @@ export class ConnectionService {
108
109
this . router . push ( `/${ this . room . value . selectedGame } ?roomId=${ data . data . roomId } ` ) ;
109
110
break ;
110
111
case 'drawCard' :
111
- // registerMarker (data.data.markerId, data.data.card);
112
+ this . drawCardCallbacks . forEach ( ( callback ) => callback ( data . data . markerId , data . data . card ) )
112
113
break ;
113
114
default :
114
115
console . warn ( 'Unhandled action' , data . action , data ) ;
@@ -141,4 +142,8 @@ export class ConnectionService {
141
142
}
142
143
this . connectionCallbacks . push ( callback ) ;
143
144
}
145
+
146
+ public onCardDrawed ( callback : ( markerId : string , cardName : string ) => void ) {
147
+ this . drawCardCallbacks . push ( callback ) ;
148
+ }
144
149
}
You can’t perform that action at this time.
0 commit comments