File tree Expand file tree Collapse file tree 5 files changed +24
-16
lines changed Expand file tree Collapse file tree 5 files changed +24
-16
lines changed Original file line number Diff line number Diff line change @@ -226,13 +226,10 @@ function clickPack(cardName) {
226226 // There may be duplicate cards in a pack, but only one copy of a card is
227227 // shown in the pick view. We must be sure to mark them all since we don't
228228 // know which one is being displayed.
229- rawPack . forEach ( card => card . isSelected = card . name == cardName ) ;
229+ rawPack . forEach ( card => card . isAutopick = card . name === cardName )
230230 App . update ( )
231+ App . send ( 'autopick' , index )
231232 return clicked
232- } else if ( card . hasOwnProperty ( 'isSelected' ) ) {
233- // Don't leave the is-selected overlay when moving the card to a different
234- // zone.
235- delete card [ 'isSelected' ]
236233 }
237234
238235 clicked = null
Original file line number Diff line number Diff line change @@ -15,11 +15,13 @@ function zone(zoneName) {
1515 let values = _ . values ( zone )
1616 let cards = _ . flat ( values )
1717
18+ let isAutopickable = card => zoneName === 'pack' && card . isAutopick
19+
1820 let items = cards . map ( card =>
1921 d . span (
2022 {
21- className : card . isSelected ? 'selected -card' : 'unselected-card' ,
22- title : card . isSelected ? 'This card will be automatically picked if your time expires.' : '' ,
23+ className : ` card ${ isAutopickable ( card ) ? 'autopick -card' : '' } ` ,
24+ title : isAutopickable ( card ) ? 'This card will be automatically picked if your time expires.' : '' ,
2325 onClick : App . _emit ( 'click' , zoneName , card . name ) ,
2426 } ,
2527 d . img ( {
Original file line number Diff line number Diff line change @@ -39,15 +39,14 @@ time {
3939 color : white;
4040}
4141
42- /* Tint the card blue when selected. */
43- .selected-card , .unselected-card {
42+ .card {
4443 display : inline-block;
4544 position : relative;
4645 margin : 0 ;
4746 cursor : pointer;
4847}
4948
50- .selected- card: before , .unselected -card: hover : before {
49+ .card : hover : before , .autopick -card: before {
5150 content : '' ;
5251
5352 display : block;
6463 background : rgba (200 , 200 , 200 , 0.25 );
6564}
6665
67- .selected -card: after {
66+ .autopick -card: after {
6867 content : 'Autopick' ;
6968
7069 display : inline-block;
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ var games = {}
1717 continue
1818 for ( var p of game . players )
1919 if ( p . time && ! -- p . time )
20- p . pickRand ( )
20+ p . pickOnTimeout ( )
2121 }
2222 setTimeout ( playerTimer , SECOND )
2323} ) ( )
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ module.exports = class extends EventEmitter {
1010 name : sock . name ,
1111 time : 0 ,
1212 packs : [ ] ,
13+ autopick_index : - 1 ,
1314 pool : [ ]
1415 } )
1516 this . attach ( sock )
@@ -19,6 +20,7 @@ module.exports = class extends EventEmitter {
1920 this . sock . ws . close ( )
2021
2122 sock . mixin ( this )
23+ sock . on ( 'autopick' , this . _autopick . bind ( this ) )
2224 sock . on ( 'pick' , this . _pick . bind ( this ) )
2325 sock . on ( 'hash' , this . _hash . bind ( this ) )
2426
@@ -34,6 +36,11 @@ module.exports = class extends EventEmitter {
3436 this . hash = hash ( deck )
3537 this . emit ( 'meta' )
3638 }
39+ _autopick ( index ) {
40+ var [ pack ] = this . packs
41+ if ( pack && index < pack . length )
42+ this . autopick_index = index
43+ }
3744 _pick ( index ) {
3845 var [ pack ] = this . packs
3946 if ( pack && index < pack . length )
@@ -65,17 +72,20 @@ module.exports = class extends EventEmitter {
6572 else
6673 this . sendPack ( next )
6774
75+ this . autopick_index = - 1
6876 this . emit ( 'pass' , pack )
6977 }
70- pickRand ( ) {
71- var index = _ . rand ( this . packs [ 0 ] . length )
78+ pickOnTimeout ( ) {
79+ let index = this . autopick_index
80+ if ( index === - 1 )
81+ index = _ . rand ( this . packs [ 0 ] . length )
7282 this . pick ( index )
7383 }
7484 kick ( ) {
7585 this . send = ( ) => { }
7686 while ( this . packs . length )
77- this . pickRand ( )
78- this . sendPack = this . pickRand
87+ this . pickOnTimeout ( )
88+ this . sendPack = this . pickOnTimeout
7989 this . isBot = true
8090 }
8191}
You can’t perform that action at this time.
0 commit comments