feat: add difficulty and dirty flag to result image
This commit is contained in:
@@ -213,6 +213,8 @@ input[type="range"]::-moz-range-thumb {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
height: 1.5em; /* Reserve space for one line of text */
|
||||||
}
|
}
|
||||||
|
|
||||||
.difficulty-indicator .label {
|
.difficulty-indicator .label {
|
||||||
@@ -224,6 +226,9 @@ input[type="range"]::-moz-range-thumb {
|
|||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
text-shadow: 0 0 10px currentColor;
|
text-shadow: 0 0 10px currentColor;
|
||||||
transition: color 0.3s ease;
|
transition: color 0.3s ease;
|
||||||
|
display: inline-block;
|
||||||
|
min-width: 120px; /* Reserve space for longest text */
|
||||||
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.error {
|
.error {
|
||||||
|
|||||||
@@ -88,8 +88,9 @@ const buildShareCanvas = () => {
|
|||||||
const padding = 28;
|
const padding = 28;
|
||||||
const headerHeight = 64;
|
const headerHeight = 64;
|
||||||
const footerHeight = 28;
|
const footerHeight = 28;
|
||||||
|
const infoHeight = 40; // New space for difficulty/guide info
|
||||||
const width = boardSize + padding * 2;
|
const width = boardSize + padding * 2;
|
||||||
const height = boardSize + padding * 2 + headerHeight + footerHeight;
|
const height = boardSize + padding * 2 + headerHeight + footerHeight + infoHeight;
|
||||||
const scale = window.devicePixelRatio || 1;
|
const scale = window.devicePixelRatio || 1;
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
canvas.width = width * scale;
|
canvas.width = width * scale;
|
||||||
@@ -109,6 +110,25 @@ const buildShareCanvas = () => {
|
|||||||
ctx.fillText(t('app.title'), padding, padding + 10);
|
ctx.fillText(t('app.title'), padding, padding + 10);
|
||||||
ctx.font = '600 16px "Segoe UI", sans-serif';
|
ctx.font = '600 16px "Segoe UI", sans-serif';
|
||||||
ctx.fillText(`${t('win.time')} ${formattedTime.value}`, padding, padding + 34);
|
ctx.fillText(`${t('win.time')} ${formattedTime.value}`, padding, padding + 34);
|
||||||
|
|
||||||
|
// Difficulty & Density Info
|
||||||
|
const densityPercent = Math.round(store.currentDensity * 100);
|
||||||
|
const dist = Math.abs(densityPercent - 50);
|
||||||
|
let difficultyKey = 'easy';
|
||||||
|
let diffColor = '#33ff33';
|
||||||
|
if (dist <= 5) { difficultyKey = 'extreme'; diffColor = '#ff3333'; }
|
||||||
|
else if (dist <= 15) { difficultyKey = 'hardest'; diffColor = '#ff9933'; }
|
||||||
|
else if (dist <= 25) { difficultyKey = 'harder'; diffColor = '#ffff33'; }
|
||||||
|
|
||||||
|
const difficultyText = t(`difficulty.${difficultyKey}`);
|
||||||
|
ctx.font = '600 14px "Segoe UI", sans-serif';
|
||||||
|
|
||||||
|
// Right aligned difficulty info
|
||||||
|
const diffLabel = `${t('win.difficulty')} ${difficultyText} (${densityPercent}%)`;
|
||||||
|
const diffWidth = ctx.measureText(diffLabel).width;
|
||||||
|
ctx.fillStyle = diffColor;
|
||||||
|
ctx.fillText(diffLabel, width - padding - diffWidth, padding + 34);
|
||||||
|
|
||||||
const gridX = padding;
|
const gridX = padding;
|
||||||
const gridY = padding + headerHeight;
|
const gridY = padding + headerHeight;
|
||||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.06)';
|
ctx.fillStyle = 'rgba(255, 255, 255, 0.06)';
|
||||||
@@ -152,6 +172,15 @@ const buildShareCanvas = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Guide Usage Info (Dirty Flag)
|
||||||
|
if (store.guideUsageCount > 0) {
|
||||||
|
ctx.fillStyle = '#ff4d4d';
|
||||||
|
ctx.font = '600 14px "Segoe UI", sans-serif';
|
||||||
|
const guideText = t('win.usedGuide', { count: store.guideUsageCount });
|
||||||
|
ctx.fillText(`⚠️ ${guideText}`, padding, height - padding - footerHeight + 10);
|
||||||
|
}
|
||||||
|
|
||||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.75)';
|
ctx.fillStyle = 'rgba(255, 255, 255, 0.75)';
|
||||||
ctx.font = '500 14px "Segoe UI", sans-serif';
|
ctx.font = '500 14px "Segoe UI", sans-serif';
|
||||||
ctx.fillText(appUrl, padding, height - padding + 6);
|
ctx.fillText(appUrl, padding, height - padding + 6);
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ const messages = {
|
|||||||
'win.shareFacebook': 'Facebook',
|
'win.shareFacebook': 'Facebook',
|
||||||
'win.shareWhatsapp': 'WhatsApp',
|
'win.shareWhatsapp': 'WhatsApp',
|
||||||
'win.shareDownload': 'Pobierz zrzut',
|
'win.shareDownload': 'Pobierz zrzut',
|
||||||
|
'win.difficulty': 'Poziom:',
|
||||||
|
'win.usedGuide': 'Użyto podpowiedzi: {count}',
|
||||||
'pwa.installTitle': 'Zainstaluj aplikację i graj offline',
|
'pwa.installTitle': 'Zainstaluj aplikację i graj offline',
|
||||||
'pwa.installMobile': 'Dodaj do ekranu głównego',
|
'pwa.installMobile': 'Dodaj do ekranu głównego',
|
||||||
'pwa.installDesktop': 'Zainstaluj na komputerze',
|
'pwa.installDesktop': 'Zainstaluj na komputerze',
|
||||||
@@ -150,6 +152,8 @@ const messages = {
|
|||||||
'win.shareFacebook': 'Facebook',
|
'win.shareFacebook': 'Facebook',
|
||||||
'win.shareWhatsapp': 'WhatsApp',
|
'win.shareWhatsapp': 'WhatsApp',
|
||||||
'win.shareDownload': 'Download screenshot',
|
'win.shareDownload': 'Download screenshot',
|
||||||
|
'win.difficulty': 'Difficulty:',
|
||||||
|
'win.usedGuide': 'Guide used: {count}',
|
||||||
'pwa.installTitle': 'Install the app and play offline',
|
'pwa.installTitle': 'Install the app and play offline',
|
||||||
'pwa.installMobile': 'Add to home screen',
|
'pwa.installMobile': 'Add to home screen',
|
||||||
'pwa.installDesktop': 'Install on desktop',
|
'pwa.installDesktop': 'Install on desktop',
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
const playerGrid = ref([]); // 0: empty, 1: filled, 2: cross
|
const playerGrid = ref([]); // 0: empty, 1: filled, 2: cross
|
||||||
const isGameWon = ref(false);
|
const isGameWon = ref(false);
|
||||||
const hasUsedGuide = ref(false);
|
const hasUsedGuide = ref(false);
|
||||||
|
const guideUsageCount = ref(0);
|
||||||
|
const currentDifficulty = ref(null); // 'easy', 'medium', 'hard', 'custom' or object { density: 0.5 }
|
||||||
|
const currentDensity = ref(0);
|
||||||
const size = ref(5);
|
const size = ref(5);
|
||||||
const startTime = ref(null);
|
const startTime = ref(null);
|
||||||
const elapsedTime = ref(0);
|
const elapsedTime = ref(0);
|
||||||
@@ -118,6 +121,8 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
resetGrid();
|
resetGrid();
|
||||||
isGameWon.value = false;
|
isGameWon.value = false;
|
||||||
hasUsedGuide.value = false;
|
hasUsedGuide.value = false;
|
||||||
|
guideUsageCount.value = 0;
|
||||||
|
currentDensity.value = totalCellsToFill.value / (size.value * size.value);
|
||||||
elapsedTime.value = 0;
|
elapsedTime.value = 0;
|
||||||
startTimer();
|
startTimer();
|
||||||
saveState();
|
saveState();
|
||||||
@@ -134,8 +139,11 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
resetGrid();
|
resetGrid();
|
||||||
isGameWon.value = false;
|
isGameWon.value = false;
|
||||||
hasUsedGuide.value = false;
|
hasUsedGuide.value = false;
|
||||||
|
guideUsageCount.value = 0;
|
||||||
|
currentDensity.value = density;
|
||||||
elapsedTime.value = 0;
|
elapsedTime.value = 0;
|
||||||
startTimer();
|
startTimer();
|
||||||
|
saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetGrid() {
|
function resetGrid() {
|
||||||
@@ -243,6 +251,8 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
playerGrid: playerGrid.value,
|
playerGrid: playerGrid.value,
|
||||||
isGameWon: isGameWon.value,
|
isGameWon: isGameWon.value,
|
||||||
hasUsedGuide: hasUsedGuide.value,
|
hasUsedGuide: hasUsedGuide.value,
|
||||||
|
guideUsageCount: guideUsageCount.value,
|
||||||
|
currentDensity: currentDensity.value,
|
||||||
elapsedTime: elapsedTime.value,
|
elapsedTime: elapsedTime.value,
|
||||||
moves: moves.value,
|
moves: moves.value,
|
||||||
history: history.value
|
history: history.value
|
||||||
@@ -260,6 +270,9 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
solution.value = parsed.solution;
|
solution.value = parsed.solution;
|
||||||
playerGrid.value = parsed.playerGrid;
|
playerGrid.value = parsed.playerGrid;
|
||||||
isGameWon.value = parsed.isGameWon;
|
isGameWon.value = parsed.isGameWon;
|
||||||
|
hasUsedGuide.value = parsed.hasUsedGuide || false;
|
||||||
|
guideUsageCount.value = parsed.guideUsageCount || 0;
|
||||||
|
currentDensity.value = parsed.currentDensity || 0;
|
||||||
elapsedTime.value = parsed.elapsedTime || 0;
|
elapsedTime.value = parsed.elapsedTime || 0;
|
||||||
moves.value = parsed.moves || 0;
|
moves.value = parsed.moves || 0;
|
||||||
history.value = parsed.history || [];
|
history.value = parsed.history || [];
|
||||||
@@ -287,6 +300,7 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
resetGrid();
|
resetGrid();
|
||||||
isGameWon.value = false;
|
isGameWon.value = false;
|
||||||
hasUsedGuide.value = false;
|
hasUsedGuide.value = false;
|
||||||
|
guideUsageCount.value = 0;
|
||||||
elapsedTime.value = 0;
|
elapsedTime.value = 0;
|
||||||
startTimer();
|
startTimer();
|
||||||
saveState();
|
saveState();
|
||||||
@@ -298,6 +312,7 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
function markGuideUsed() {
|
function markGuideUsed() {
|
||||||
if (isGameWon.value) return;
|
if (isGameWon.value) return;
|
||||||
hasUsedGuide.value = true;
|
hasUsedGuide.value = true;
|
||||||
|
guideUsageCount.value++;
|
||||||
saveState();
|
saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,6 +341,8 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
|||||||
undo,
|
undo,
|
||||||
closeWinModal,
|
closeWinModal,
|
||||||
hasUsedGuide,
|
hasUsedGuide,
|
||||||
|
guideUsageCount,
|
||||||
|
currentDensity,
|
||||||
markGuideUsed
|
markGuideUsed
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user