@@ -672,7 +672,9 @@ export function areMyDiceAtDomPos(
672
672
myPlayerIndex : cg . PlayerIndex ,
673
673
bounds : ClientRect ,
674
674
variant : cg . Variant = 'chess' ,
675
+ cubeActions : cg . CubeAction [ ] = [ ] ,
675
676
) : boolean {
677
+ if ( cubeActions && cubeActions . length > 0 ) return false ;
676
678
if ( turnPlayerIndex !== myPlayerIndex ) return false ;
677
679
const correctWidth =
678
680
( orientation === 'p1' && turnPlayerIndex === 'p2' ) || ( orientation === 'p1vflip' && turnPlayerIndex === 'p1' )
@@ -683,22 +685,97 @@ export function areMyDiceAtDomPos(
683
685
return ( variant === 'backgammon' || variant === 'hyper' || variant === 'nackgammon' ) && correctWidth && correctHeight ;
684
686
}
685
687
686
- export function isButtonAtDomPos (
688
+ function isButtonAtPos (
687
689
pos : cg . NumberPair ,
688
690
orientation : cg . Orientation ,
689
691
turnPlayerIndex : cg . PlayerIndex ,
690
- myPlayerIndex : cg . PlayerIndex ,
691
692
bounds : ClientRect ,
692
- variant : cg . Variant = 'chess ',
693
+ placement : 'left' | 'right ',
693
694
) : boolean {
694
- if ( turnPlayerIndex !== myPlayerIndex ) return false ;
695
+ const rightBound = placement === 'left' ? [ 9.875 / 15 , 12.125 / 15 ] : [ 2.875 / 15 , 5.125 / 15 ] ;
696
+ const leftBound = placement === 'left' ? [ 2.875 / 15 , 5.125 / 15 ] : [ 9.875 / 15 , 12.125 / 15 ] ;
695
697
const correctWidth =
696
698
( orientation === 'p1' && turnPlayerIndex === 'p2' ) || ( orientation === 'p1vflip' && turnPlayerIndex === 'p1' )
697
- ? ( pos [ 0 ] - bounds . left ) / bounds . width > 8 / 15 && ( pos [ 0 ] - bounds . left ) / bounds . width < 14 / 15
698
- : ( pos [ 0 ] - bounds . left ) / bounds . width > 1 / 15 && ( pos [ 0 ] - bounds . left ) / bounds . width < 7 / 15 ;
699
+ ? ( pos [ 0 ] - bounds . left ) / bounds . width > rightBound [ 0 ] && ( pos [ 0 ] - bounds . left ) / bounds . width < rightBound [ 1 ]
700
+ : ( pos [ 0 ] - bounds . left ) / bounds . width > leftBound [ 0 ] && ( pos [ 0 ] - bounds . left ) / bounds . width < leftBound [ 1 ] ;
699
701
const correctHeight =
700
- ( pos [ 1 ] - bounds . top ) / bounds . height > 6.5 / 15 && ( pos [ 1 ] - bounds . top ) / bounds . height < 8.5 / 15 ;
701
- return ( variant === 'backgammon' || variant === 'hyper' || variant === 'nackgammon' ) && correctWidth && correctHeight ;
702
+ ( pos [ 1 ] - bounds . top ) / bounds . height > 6.95 / 15 && ( pos [ 1 ] - bounds . top ) / bounds . height < 8.05 / 15 ;
703
+ return correctWidth && correctHeight ;
704
+ }
705
+
706
+ export function isUndoButtonAtDomPos (
707
+ pos : cg . NumberPair ,
708
+ orientation : cg . Orientation ,
709
+ turnPlayerIndex : cg . PlayerIndex ,
710
+ myPlayerIndex : cg . PlayerIndex ,
711
+ bounds : ClientRect ,
712
+ variant : cg . Variant = 'chess' ,
713
+ cubeActions : cg . CubeAction [ ] = [ ] ,
714
+ ) : boolean {
715
+ if ( cubeActions && cubeActions . length > 0 ) return false ;
716
+ if ( turnPlayerIndex !== myPlayerIndex ) return false ;
717
+ const correctPlacement = isButtonAtPos ( pos , orientation , turnPlayerIndex , bounds , 'left' ) ;
718
+ return ( variant === 'backgammon' || variant === 'hyper' || variant === 'nackgammon' ) && correctPlacement ;
719
+ }
720
+
721
+ export function isDoubleButtonAtDomPos (
722
+ pos : cg . NumberPair ,
723
+ orientation : cg . Orientation ,
724
+ turnPlayerIndex : cg . PlayerIndex ,
725
+ myPlayerIndex : cg . PlayerIndex ,
726
+ bounds : ClientRect ,
727
+ variant : cg . Variant = 'chess' ,
728
+ cubeActions : cg . CubeAction [ ] = [ ] ,
729
+ ) : boolean {
730
+ if ( ! ( cubeActions && cubeActions . includes ( 'offer' ) ) ) return false ;
731
+ if ( turnPlayerIndex !== myPlayerIndex ) return false ;
732
+ const correctPlacement = isButtonAtPos ( pos , orientation , turnPlayerIndex , bounds , 'left' ) ;
733
+ return ( variant === 'backgammon' || variant === 'hyper' || variant === 'nackgammon' ) && correctPlacement ;
734
+ }
735
+
736
+ export function isRollButtonAtDomPos (
737
+ pos : cg . NumberPair ,
738
+ orientation : cg . Orientation ,
739
+ turnPlayerIndex : cg . PlayerIndex ,
740
+ myPlayerIndex : cg . PlayerIndex ,
741
+ bounds : ClientRect ,
742
+ variant : cg . Variant = 'chess' ,
743
+ cubeActions : cg . CubeAction [ ] = [ ] ,
744
+ ) : boolean {
745
+ if ( ! ( cubeActions && cubeActions . includes ( 'offer' ) ) ) return false ;
746
+ if ( turnPlayerIndex !== myPlayerIndex ) return false ;
747
+ const correctPlacement = isButtonAtPos ( pos , orientation , turnPlayerIndex , bounds , 'right' ) ;
748
+ return ( variant === 'backgammon' || variant === 'hyper' || variant === 'nackgammon' ) && correctPlacement ;
749
+ }
750
+
751
+ export function isDropButtonAtDomPos (
752
+ pos : cg . NumberPair ,
753
+ orientation : cg . Orientation ,
754
+ turnPlayerIndex : cg . PlayerIndex ,
755
+ myPlayerIndex : cg . PlayerIndex ,
756
+ bounds : ClientRect ,
757
+ variant : cg . Variant = 'chess' ,
758
+ cubeActions : cg . CubeAction [ ] = [ ] ,
759
+ ) : boolean {
760
+ if ( ! ( cubeActions && cubeActions . includes ( 'reject' ) ) ) return false ;
761
+ if ( turnPlayerIndex !== myPlayerIndex ) return false ;
762
+ const correctPlacement = isButtonAtPos ( pos , orientation , turnPlayerIndex , bounds , 'left' ) ;
763
+ return ( variant === 'backgammon' || variant === 'hyper' || variant === 'nackgammon' ) && correctPlacement ;
764
+ }
765
+
766
+ export function isTakeButtonAtDomPos (
767
+ pos : cg . NumberPair ,
768
+ orientation : cg . Orientation ,
769
+ turnPlayerIndex : cg . PlayerIndex ,
770
+ myPlayerIndex : cg . PlayerIndex ,
771
+ bounds : ClientRect ,
772
+ variant : cg . Variant = 'chess' ,
773
+ cubeActions : cg . CubeAction [ ] = [ ] ,
774
+ ) : boolean {
775
+ if ( ! ( cubeActions && cubeActions . includes ( 'accept' ) ) ) return false ;
776
+ if ( turnPlayerIndex !== myPlayerIndex ) return false ;
777
+ const correctPlacement = isButtonAtPos ( pos , orientation , turnPlayerIndex , bounds , 'right' ) ;
778
+ return ( variant === 'backgammon' || variant === 'hyper' || variant === 'nackgammon' ) && correctPlacement ;
702
779
}
703
780
704
781
export function isPocketAtDomPos (
@@ -711,8 +788,8 @@ export function isPocketAtDomPos(
711
788
const correctWidth = ( pos [ 0 ] - bounds . left ) / bounds . width < 8 / 15 && ( pos [ 0 ] - bounds . left ) / bounds . width > 7 / 15 ;
712
789
const correctHeight =
713
790
( orientation === 'p1' && turnPlayerIndex === 'p1' ) || ( orientation === 'p1vflip' && turnPlayerIndex === 'p2' )
714
- ? ( pos [ 1 ] - bounds . top ) / bounds . height > 2 / 15 && ( pos [ 1 ] - bounds . top ) / bounds . height < 7.4 / 15
715
- : ( pos [ 1 ] - bounds . top ) / bounds . height > 7.6 / 15 && ( pos [ 1 ] - bounds . top ) / bounds . height < 13 / 15 ;
791
+ ? ( pos [ 1 ] - bounds . top ) / bounds . height > 1.6 / 15 && ( pos [ 1 ] - bounds . top ) / bounds . height < 7 / 15
792
+ : ( pos [ 1 ] - bounds . top ) / bounds . height > 8 / 15 && ( pos [ 1 ] - bounds . top ) / bounds . height < 13.4 / 15 ;
716
793
return ( variant === 'backgammon' || variant === 'hyper' || variant === 'nackgammon' ) && correctWidth && correctHeight ;
717
794
}
718
795
@@ -725,9 +802,9 @@ export function reorderDice(state: HeadlessState): void {
725
802
}
726
803
}
727
804
728
- export function undoButtonPressed ( state : HeadlessState ) : void {
805
+ export function buttonPressed ( state : HeadlessState , button : cg . Button ) : void {
729
806
if ( state . gameButtonsActive ) {
730
- callUserFunction ( state . events . undoButton ) ;
807
+ callUserFunction ( state . events . buttonClick , button ) ;
731
808
}
732
809
}
733
810
0 commit comments