1
1
import Sound from './sound'
2
- import { Rect , Vec2 } from 'blah'
2
+ import { Rect , Time , Vec2 } from 'blah'
3
3
import { Play } from './play'
4
4
import { Anim } from './anim'
5
5
import { Clickable } from './game'
@@ -15,6 +15,8 @@ import { HitStock, Recycle,
15
15
FoundationToTableu ,
16
16
} from 'lsolitaire'
17
17
import { SolitaireStore } from './store'
18
+ import { ticks } from './shared'
19
+ import { appr } from './lerp'
18
20
19
21
export type TableuDrag = {
20
22
tableu : number ,
@@ -344,6 +346,9 @@ export class SolitaireGame extends Play {
344
346
return this . back_res . cmd
345
347
}
346
348
349
+
350
+ trigger_auto : number = - 2
351
+
347
352
_init ( ) {
348
353
349
354
@@ -380,6 +385,20 @@ export class SolitaireGame extends Play {
380
385
381
386
this . stock = this . make ( Stock , Vec2 . make ( stock_x , stock_y ) , {
382
387
on_waste_click ( ) {
388
+
389
+ if ( self . click_source === 'waste' ) {
390
+ self . _release_cancel_highlight ( )
391
+ let hint_data = WasteToFoundation . auto_can ( self . pov )
392
+ if ( hint_data ) {
393
+ self . trigger_auto = - 1
394
+ self . cmd ( WasteToFoundation , hint_data )
395
+ }
396
+
397
+ return
398
+ }
399
+
400
+
401
+
383
402
self . _release_cancel_highlight ( )
384
403
self . stock . waste . top_card . set_highlight ( true )
385
404
self . click_source = 'waste'
@@ -430,6 +449,19 @@ export class SolitaireGame extends Play {
430
449
let { tableu, i : _i } = self . click_source
431
450
432
451
if ( tableu === i ) {
452
+
453
+ if ( e === 1 ) {
454
+ self . _release_cancel_highlight ( )
455
+ let hint_data = TableuToFoundation . auto_can ( self . pov , { tableu} )
456
+ if ( hint_data ) {
457
+ self . trigger_auto = - 1
458
+ self . cmd ( TableuToFoundation , hint_data )
459
+ }
460
+
461
+ return
462
+ }
463
+
464
+
433
465
self . _release_cancel_highlight ( )
434
466
self . tableus [ i ] . fronts . set_highlight ( e , true )
435
467
self . click_source = { tableu : i , i : e }
@@ -830,6 +862,13 @@ export class SolitaireGame extends Play {
830
862
this . cards . shadow_group = undefined
831
863
} )
832
864
}
865
+
866
+ if ( res instanceof TableuToFoundation || res instanceof WasteToFoundation ) {
867
+ if ( this . trigger_auto === - 3 ) {
868
+ this . trigger_auto = - 1
869
+ }
870
+ }
871
+
833
872
}
834
873
835
874
apply_pov ( cmd : IMoveType < SolitairePov , Solitaire > , data : any ) {
@@ -865,6 +904,29 @@ export class SolitaireGame extends Play {
865
904
request_new_game ( ) {
866
905
this . back_res . new_game ( )
867
906
}
868
- }
869
907
870
- export { card_sort_key } from 'lsolitaire'
908
+
909
+ _update ( ) {
910
+ if ( this . trigger_auto === - 1 ) {
911
+ this . trigger_auto = ticks . half + ticks . thirds
912
+ } else if ( this . trigger_auto > 0 ) {
913
+ this . trigger_auto = appr ( this . trigger_auto , 0 , Time . delta )
914
+ } else if ( this . trigger_auto === 0 ) {
915
+ this . trigger_auto = - 2
916
+ let hint_data = WasteToFoundation . auto_can ( this . pov )
917
+ if ( hint_data ) {
918
+ this . cmd ( WasteToFoundation , hint_data )
919
+ this . trigger_auto = - 3
920
+ } else {
921
+ for ( let i = 0 ; i < 7 ; i ++ ) {
922
+ let hint_data = TableuToFoundation . auto_can ( this . pov , { tableu : i } )
923
+ if ( hint_data ) {
924
+ this . cmd ( TableuToFoundation , hint_data )
925
+ this . trigger_auto = - 3
926
+ break
927
+ }
928
+ }
929
+ }
930
+ }
931
+ }
932
+ }
0 commit comments