@@ -23,23 +23,56 @@ export const fillerStacks = (
23
23
return { length : i * j - 15 } ;
24
24
} ;
25
25
26
- export const calculateFontSize = (
26
+ const calculateTableEmSize = (
27
+ size : ICardSize ,
28
+ columns : number ,
29
+ rows : number ,
30
+ ) : [ number , number ] => {
31
+ const tableWidthEm =
32
+ stackWidthEm ( 4 , size ) * columns +
33
+ ( size !== "small" ? 0.666 : 0.333 ) * columns * 2 ;
34
+ const tableHeightEm =
35
+ getCardDimensionsEm ( size ) . height * rows +
36
+ ( size !== "small" ? 0.5 : 0.25 ) * rows * 2 ;
37
+
38
+ return [ tableWidthEm , tableHeightEm ] ;
39
+ } ;
40
+
41
+ interface TableDimensions {
42
+ fontSize : number ;
43
+ columns : number ;
44
+ rows : number ;
45
+ tableWidthEm : number ;
46
+ tableHeightEm : number ;
47
+ }
48
+
49
+ export const calculateDimensions = (
27
50
size : ICardSize ,
28
51
mainWidth : number ,
29
52
mainHeight : number ,
30
53
innerHeight : number ,
31
- ) : number => {
32
- const [ i , j ] = getStacksGrid ( mainWidth , innerHeight ) ;
33
- const tableWidthEm =
34
- stackWidthEm ( 4 , size ) * i + ( size !== "small" ? 0.666 : 0.333 ) * 10 ;
35
- const fontSizeW = ( mainWidth * 0.95 ) / tableWidthEm ;
36
-
37
- const tableHeightEm =
38
- getCardDimensionsEm ( size ) . height * j + ( size !== "small" ? 0.5 : 0.25 ) * 6 ;
54
+ ) : TableDimensions => {
55
+ // Limit play area aspect ratio to 16:9
39
56
const tableHeight = mainHeight > 600 ? mainHeight : innerHeight ;
57
+ const tableWidth = Math . min ( mainWidth , tableHeight * ( 16 / 9 ) ) ;
58
+
59
+ const [ columns , rows ] = getStacksGrid ( mainWidth , innerHeight ) ;
60
+ const [ tableWidthEm , tableHeightEm ] = calculateTableEmSize (
61
+ size ,
62
+ columns ,
63
+ rows ,
64
+ ) ;
65
+
66
+ const fontSizeW = ( tableWidth * 0.95 ) / tableWidthEm ;
40
67
const fontSizeH = ( tableHeight * 0.95 ) / tableHeightEm ;
41
68
42
- return Math . min ( fontSizeW , fontSizeH ) ;
69
+ return {
70
+ fontSize : Math . min ( fontSizeW , fontSizeH ) ,
71
+ columns,
72
+ rows,
73
+ tableWidthEm,
74
+ tableHeightEm,
75
+ } ;
43
76
} ;
44
77
45
78
export type Piles = Card [ ] [ ] ;
0 commit comments