11<template >
22 <div >
33 <div >
4- <h3 >P2の手牌({{p2Hand.length}})</h3 >
4+ <h3 >P2の手牌({{ p2Hand.length }})</h3 >
55 <draggable v-model =" p2Hand" group =" myGroup" :options =" options" >
66 <div
77 class =" tile"
88 v-for =" tile in p2Hand"
99 :key =" tile.id"
1010 :class =" isFixed(false)"
11- >{{tile.name}}</div >
11+ >
12+ {{ tile.name }}
13+ </div >
1214 </draggable >
1315 </div >
1416 <div >
15- <h3 >P2の打牌候補({{p2Pool.length}})</h3 >
17+ <h3 >P2の打牌候補({{ p2Pool.length }})</h3 >
1618 <draggable v-model =" p2Pool" group =" myGroup" :options =" options" >
1719 <div
1820 class =" tile"
1921 v-for =" tile in p2Pool"
2022 :key =" tile.id"
2123 :class =" isFixed(false)"
22- >{{tile.name}}</div >
24+ >
25+ {{ tile.name }}
26+ </div >
2327 </draggable >
2428 </div >
2529 <div >
26- <h3 >P2の河({{p2River.length - 1}})</h3 >
27- <draggable v-model =" p2River" group =" myGroup" :options =" options" @add =" onP2Add" >
30+ <h3 >P2の河({{ p2River.length - 1 }})</h3 >
31+ <draggable
32+ v-model =" p2River"
33+ group =" myGroup"
34+ :options =" options"
35+ @add =" onP2Add"
36+ >
2837 <div
2938 class =" tile"
3039 v-for =" tile in p2River"
3140 :key =" tile.id"
3241 :class =" isFixed(true)"
33- >{{tile.name}}</div >
42+ >
43+ {{ tile.name }}
44+ </div >
3445 </draggable >
3546 </div >
3647 <div class =" dora" >
3748 <h3 >ドラ表</h3 >
38- <div class =" tile" >{{dora}}</div >
49+ <div class =" tile" >{{ dora }}</div >
3950 </div >
4051 <div class =" dora" >
4152 <h3 >裏ドラ表</h3 >
42- <div class =" tile" >{{uradora}}</div >
53+ <div class =" tile" >{{ uradora }}</div >
4354 </div >
4455 <div >
45- <h3 >P1の河({{p1River.length - 1}})</h3 >
46- <draggable v-model =" p1River" group =" myGroup" :options =" options" @add =" onP1Add" >
56+ <h3 >P1の河({{ p1River.length - 1 }})</h3 >
57+ <draggable
58+ v-model =" p1River"
59+ group =" myGroup"
60+ :options =" options"
61+ @add =" onP1Add"
62+ >
4763 <div
4864 class =" tile"
4965 v-for =" tile in p1River"
5066 :key =" tile.id"
5167 :class =" isFixed(true)"
52- >{{tile.name}}</div >
68+ >
69+ {{ tile.name }}
70+ </div >
5371 </draggable >
5472 </div >
5573 <div >
56- <h3 >P1の打牌候補 ({{p1Pool.length}})</h3 >
74+ <h3 >P1の打牌候補 ({{ p1Pool.length }})</h3 >
5775 <draggable v-model =" p1Pool" group =" myGroup" :options =" options" >
5876 <div
5977 class =" tile"
6078 v-for =" tile in p1Pool"
6179 :key =" tile.id"
6280 :class =" isFixed(false)"
63- >{{tile.name}}</div >
81+ >
82+ {{ tile.name }}
83+ </div >
6484 </draggable >
6585 </div >
6686 <div >
67- <h3 >P1の手牌({{p1Hand.length}})</h3 >
87+ <h3 >P1の手牌({{ p1Hand.length }})</h3 >
6888 <draggable v-model =" p1Hand" group =" myGroup" :options =" options" >
6989 <div
7090 class =" tile"
7191 v-for =" tile in p1Hand"
7292 :key =" tile.id"
7393 :class =" isFixed(false)"
74- >{{tile.name}}</div >
94+ >
95+ {{ tile.name }}
96+ </div >
7597 </draggable >
7698 </div >
7799
@@ -267,6 +289,8 @@ export default {
267289 console .log (" test" );
268290 },
269291 initialize () {
292+ resetRef ();
293+
270294 const mm = [" m1" , " m2" , " m3" , " m4" , " m5" , " m6" , " m7" , " m8" , " m9" ];
271295 const pp = [" p1" , " p2" , " p3" , " p4" , " p5" , " p6" , " p7" , " p8" , " p9" ];
272296 const ss = [" s1" , " s2" , " s3" , " s4" , " s5" , " s6" , " s7" , " s8" , " s9" ];
@@ -307,16 +331,23 @@ export default {
307331 p2Hand: p2Tiles .slice (21 ),
308332 p2River: this .initialRiver ,
309333 });
334+
310335 console .log (" initialize finish." );
311336 },
312337 p1Start () {
338+ resetRef ();
339+
313340 const gameRef = firebase .database ().ref (" /game" );
314341 gameRef .once (" value" , (snapshot ) => {
315342 this .dora = snapshot .val ()[" dora" ];
316343 this .p1Pool = snapshot .val ()[" p1Pool" ];
317344 this .p1Hand = snapshot .val ()[" p1Hand" ];
318345 });
319- this .riverConnect ();
346+
347+ p2Ref .on (" value" , (snapshot ) => {
348+ this .p2River = snapshot .val ();
349+ console .log (" p2RiverRef" );
350+ });
320351
321352 this .p2Pool = this .initialPool ;
322353 this .p2Hand = this .initialHand ;
@@ -325,52 +356,58 @@ export default {
325356 console .log (" start as p1." );
326357 },
327358 p2Start () {
359+ resetRef ();
360+
328361 const gameRef = firebase .database ().ref (" /game" );
329362 gameRef .once (" value" , (snapshot ) => {
330363 this .dora = snapshot .val ()[" dora" ];
331364 this .p2Pool = snapshot .val ()[" p2Pool" ];
332365 this .p2Hand = snapshot .val ()[" p2Hand" ];
333366 });
334- this .riverConnect ();
367+
368+ const p1Ref = firebase .database ().ref (" /game/p1River" );
369+ p1Ref .off ();
370+ p1Ref .on (" value" , (snapshot ) => {
371+ this .p1River = snapshot .val ();
372+ console .log (" p1RiverRef" );
373+ });
335374
336375 this .p1Pool = this .initialPool ;
337376 this .p1Hand = this .initialHand ;
338377 this .uradora = " ??" ;
339378
340379 console .log (" start as p2." );
341380 },
342- riverConnect () {
343- const p1Ref = firebase .database ().ref (" /game/p1River" );
344- p1Ref .on (" value" , (snapshot ) => {
345- this .p1River = snapshot .val ();
346- });
347- const p2Ref = firebase .database ().ref (" /game/p2River" );
348- p2Ref .on (" value" , (snapshot ) => {
349- this .p2River = snapshot .val ();
350- });
351- },
352- async win () {
381+ win () {
382+ resetRef ();
383+
353384 const gameRef = firebase .database ().ref (" /game" );
354385 gameRef .update ({
355386 p1Hand: this .p1Hand ,
356387 p2Hand: this .p2Hand ,
357388 });
358- const snapshot = await gameRef .once (" value" );
359- if (snapshot .val ()) {
389+ gameRef .once (" value" , (snapshot ) => {
360390 this .uradora = snapshot .val ()[" uradora" ];
361- }
391+ });
362392 console .log (" I win." );
363393 },
364- async lose () {
394+ lose () {
395+ resetRef ();
396+
365397 const gameRef = firebase .database ().ref (" /game" );
366- const snapshot = await gameRef .once (" value" );
367- if (snapshot .val ()) {
398+ gameRef .once (" value" , (snapshot ) => {
368399 this .uradora = snapshot .val ()[" uradora" ];
369400 this .p1Hand = snapshot .val ()[" p1Hand" ];
370401 this .p2Hand = snapshot .val ()[" p2Hand" ];
371- }
402+ });
372403 console .log (" I lose." );
373404 },
405+ resetRef () {
406+ const p1Ref = firebase .database ().ref (" /game/p1River" );
407+ p1Ref .off ();
408+ const p2Ref = firebase .database ().ref (" /game/p2River" );
409+ p2Ref .off ();
410+ },
374411 // フィルタされている要素を選択した時(filterイベント)
375412 onFilter () {
376413 console .log (" onFilter" );
0 commit comments