| Server IP : 217.154.3.148 / Your IP : 216.73.216.90 Web Server : Apache System : Linux blissful-wright.217-154-3-148.plesk.page 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64 User : gracious-boyd_hfhh1h8vo9n ( 10000) PHP Version : 8.3.31 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/gracious-boyd.217-154-3-148.plesk.page/nextjs/src/utils/ |
Upload File : |
import type { TileAssignment, TileScene } from '@/src/types/tiles';
export type TileSetConfig = {
sceneId: string;
grid: {
cols: number;
rows: number;
};
mode: 'single' | 'random';
tiles: TileAssignment[];
};
export function createEmptyAssignments(scene: Pick<TileScene, 'cols' | 'rows'>): TileAssignment[] {
const assignments: TileAssignment[] = [];
for (let row = 0; row < scene.rows; row += 1) {
for (let col = 0; col < scene.cols; col += 1) {
assignments.push({ row, col, designId: null });
}
}
return assignments;
}
export function applySingleDesign(
assignments: TileAssignment[],
designId: number | null,
): TileAssignment[] {
return assignments.map((tile) => ({ ...tile, designId }));
}
export function randomizeAssignments(
scene: Pick<TileScene, 'cols' | 'rows'>,
designIds: number[],
): TileAssignment[] {
if (designIds.length === 0) {
return createEmptyAssignments(scene);
}
const assignments: TileAssignment[] = [];
for (let row = 0; row < scene.rows; row += 1) {
for (let col = 0; col < scene.cols; col += 1) {
const randomIdx = Math.floor(Math.random() * designIds.length);
assignments.push({ row, col, designId: designIds[randomIdx] });
}
}
return assignments;
}
export function countTilesPerDesign(assignments: TileAssignment[]): Record<number, number> {
const counts: Record<number, number> = {};
for (const tile of assignments) {
if (tile.designId == null) continue;
counts[tile.designId] = (counts[tile.designId] ?? 0) + 1;
}
return counts;
}
export function tileKey(row: number, col: number): string {
return `${row}-${col}`;
}
// Alias for readability if needed elsewhere
export const initAssignments = createEmptyAssignments;
export function getTileVariation(row: number, col: number) {
const seed = (row + 1) * 17 + (col + 1) * 31;
const rand = Math.sin(seed) * 10000;
const value = rand - Math.floor(rand);
const rotateDeg = (value - 0.5) * 0.8; // ~ -0.4° to +0.4°
const scale = 1 + (value - 0.5) * 0.02; // +/- 1%
return { rotateDeg, scale };
}
export function buildConfig(
sceneId: string,
scene: Pick<TileScene, 'cols' | 'rows'>,
mode: 'single' | 'random',
tiles: TileAssignment[],
): TileSetConfig {
return {
sceneId,
grid: {
cols: scene.cols,
rows: scene.rows,
},
mode,
tiles,
};
}