Skip to content

Commit ec09d95

Browse files
committed
Limit play area aspect-ratio
1 parent 04ee50c commit ec09d95

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

src/utils/pileon.ts

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,56 @@ export const fillerStacks = (
2323
return { length: i * j - 15 };
2424
};
2525

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 = (
2750
size: ICardSize,
2851
mainWidth: number,
2952
mainHeight: number,
3053
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
3956
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;
4067
const fontSizeH = (tableHeight * 0.95) / tableHeightEm;
4168

42-
return Math.min(fontSizeW, fontSizeH);
69+
return {
70+
fontSize: Math.min(fontSizeW, fontSizeH),
71+
columns,
72+
rows,
73+
tableWidthEm,
74+
tableHeightEm,
75+
};
4376
};
4477

4578
export type Piles = Card[][];

src/views/Pileon/Pileon.svelte

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
drop,
1717
autoMove,
1818
getEqualValues,
19-
calculateFontSize,
19+
calculateDimensions,
2020
fillerStacks,
2121
} from "../../utils/pileon";
2222
import { getStackDataTransfer } from "../../utils/stack";
@@ -137,8 +137,7 @@
137137
};
138138
139139
$: size = $appearance.size;
140-
$: fontSize = calculateFontSize(size, mainWidth, mainHeight, innerHeight);
141-
$: style = `font-size: ${fontSize}px`;
140+
$: d = calculateDimensions(size, mainWidth, mainHeight, innerHeight);
142141
143142
onMount(() => {
144143
actions.update((prev) => ({ ...prev, help, shuffle, undo }));
@@ -160,7 +159,8 @@
160159
bind:clientHeight={mainHeight}
161160
bind:clientWidth={mainWidth}
162161
class="pileon"
163-
{style}
162+
style:font-size="{d.fontSize}px"
163+
style:width="{d.tableWidthEm * 1.25}em"
164164
>
165165
{#each piles as pile, index}
166166
<div class="pile" class:small={size === "small"}>
@@ -196,12 +196,17 @@
196196
flex-wrap: wrap
197197
font-size: 0.7em
198198
display: flex
199+
align-content: center
199200
align-items: center
200201
justify-content: center
201202
max-width: 100vw
203+
row-gap: 0.5em
204+
margin: auto
205+
206+
@media (max-aspect-ratio: 9/17)
207+
row-gap: 1em
202208
203209
.pile
204-
margin: 0.5em 0.666em
205210
flex-basis: 16.7% /* Just above 1/6 */
206211
207212
&.small

0 commit comments

Comments
 (0)