Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 19c4516d22 | |||
| 06c345e8f0 | |||
| d9ae630fe5 | |||
| 132c4ebced | |||
| 0b8dcacd18 | |||
| 4ef4f2b251 | |||
| 17d8cbfedd | |||
| a41e337c43 | |||
| 1f1de61044 | |||
| 7f22aa9198 | |||
| 133a676682 | |||
| 30318fafaf | |||
| 5549e24c17 | |||
| ca3193d07e | |||
| 41a36768cd | |||
| 315fb29eac | |||
| 395e9caff4 | |||
| e1c73181d4 | |||
| 874e35bba3 | |||
| 69b04d3336 | |||
| c5b212234a | |||
| 8e0ddf3a72 |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "vue-nonograms-solid",
|
||||
"version": "1.1.0",
|
||||
"version": "1.7.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "vue-nonograms-solid",
|
||||
"version": "1.1.0",
|
||||
"version": "1.7.0",
|
||||
"dependencies": {
|
||||
"fireworks-js": "^2.10.8",
|
||||
"flag-icons": "^7.5.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue-nonograms-solid",
|
||||
"version": "1.1.0",
|
||||
"version": "1.7.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import { ref, computed, onMounted, watch, nextTick } from 'vue';
|
||||
import { usePuzzleStore } from '@/stores/puzzle';
|
||||
import { useI18n } from '@/composables/useI18n';
|
||||
import { calculateDifficulty } from '@/utils/puzzleUtils';
|
||||
|
||||
const emit = defineEmits(['close']);
|
||||
const store = usePuzzleStore();
|
||||
@@ -10,6 +11,181 @@ const { t } = useI18n();
|
||||
const customSize = ref(10);
|
||||
const fillRate = ref(50);
|
||||
const errorMsg = ref('');
|
||||
const difficultyCanvas = ref(null);
|
||||
const isDragging = ref(false);
|
||||
|
||||
const drawMap = () => {
|
||||
const canvas = difficultyCanvas.value;
|
||||
if (!canvas) return;
|
||||
const ctx = canvas.getContext('2d');
|
||||
const width = canvas.width;
|
||||
const height = canvas.height;
|
||||
|
||||
// Clear
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
|
||||
// Draw Gradient Background
|
||||
// Optimization: Create an image data once if static, but here it's small enough.
|
||||
const imgData = ctx.createImageData(width, height);
|
||||
const data = imgData.data;
|
||||
|
||||
// Ranges:
|
||||
// X: Fill Rate 10% -> 90%
|
||||
// Y: Size 5 -> 80
|
||||
|
||||
for (let y = 0; y < height; y++) {
|
||||
for (let x = 0; x < width; x++) {
|
||||
// Map x, y to fillRate, size
|
||||
// y=0 -> size 80 (top), y=height -> size 5 (bottom)
|
||||
// x=0 -> fill 10%, x=width -> fill 90%
|
||||
|
||||
const normalizedX = x / width;
|
||||
const normalizedY = 1 - (y / height); // 0 at bottom, 1 at top
|
||||
|
||||
const fRate = 0.1 + normalizedX * 0.8; // 0.1 to 0.9
|
||||
const sSize = 5 + normalizedY * 75; // 5 to 80
|
||||
|
||||
const { value } = calculateDifficulty(fRate, sSize);
|
||||
|
||||
// Color Mapping:
|
||||
// Green (0%) -> Yellow (50%) -> Red (100%)
|
||||
// Hue: 120 -> 0
|
||||
const hue = 120 * (1 - value / 100);
|
||||
|
||||
// Convert HSL to RGB (Simplified)
|
||||
// Saturation 100%, Lightness 50%
|
||||
const [r, g, b] = hslToRgb(hue / 360, 1, 0.5);
|
||||
|
||||
const index = (y * width + x) * 4;
|
||||
data[index] = r;
|
||||
data[index + 1] = g;
|
||||
data[index + 2] = b;
|
||||
data[index + 3] = 255; // Alpha
|
||||
}
|
||||
}
|
||||
ctx.putImageData(imgData, 0, 0);
|
||||
|
||||
// Draw current position
|
||||
// Map current fillRate/size to x,y
|
||||
// Fill: 10..90. Size: 5..80.
|
||||
const currentFill = Math.max(10, Math.min(90, fillRate.value));
|
||||
const currentSize = Math.max(5, Math.min(80, customSize.value));
|
||||
|
||||
const posX = ((currentFill - 10) / 80) * width;
|
||||
const posY = (1 - (currentSize - 5) / 75) * height;
|
||||
|
||||
// Draw Crosshair/Circle
|
||||
ctx.beginPath();
|
||||
ctx.arc(posX, posY, 6, 0, Math.PI * 2);
|
||||
ctx.fillStyle = '#fff';
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2;
|
||||
ctx.strokeStyle = '#000';
|
||||
ctx.stroke();
|
||||
};
|
||||
|
||||
const hslToRgb = (h, s, l) => {
|
||||
let r, g, b;
|
||||
if (s === 0) {
|
||||
r = g = b = l; // achromatic
|
||||
} else {
|
||||
const hue2rgb = (p, q, t) => {
|
||||
if (t < 0) t += 1;
|
||||
if (t > 1) t -= 1;
|
||||
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
||||
if (t < 1 / 2) return q;
|
||||
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
||||
return p;
|
||||
};
|
||||
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
||||
const p = 2 * l - q;
|
||||
r = hue2rgb(p, q, h + 1 / 3);
|
||||
g = hue2rgb(p, q, h);
|
||||
b = hue2rgb(p, q, h - 1 / 3);
|
||||
}
|
||||
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
|
||||
};
|
||||
|
||||
const updateFromEvent = (e) => {
|
||||
const canvas = difficultyCanvas.value;
|
||||
if (!canvas) return;
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
|
||||
// Handle Touch or Mouse
|
||||
const clientX = e.touches ? e.touches[0].clientX : e.clientX;
|
||||
const clientY = e.touches ? e.touches[0].clientY : e.clientY;
|
||||
|
||||
let x = clientX - rect.left;
|
||||
let y = clientY - rect.top;
|
||||
|
||||
// Clamp
|
||||
x = Math.max(0, Math.min(rect.width, x));
|
||||
y = Math.max(0, Math.min(rect.height, y));
|
||||
|
||||
// Reverse Map
|
||||
// x / width -> fillRate (10..90)
|
||||
// 1 - y / height -> size (5..80)
|
||||
|
||||
const normalizedX = x / rect.width;
|
||||
const normalizedY = 1 - (y / rect.height);
|
||||
|
||||
const newFill = 10 + normalizedX * 80;
|
||||
const newSize = 5 + normalizedY * 75;
|
||||
|
||||
fillRate.value = Math.round(newFill);
|
||||
customSize.value = Math.round(newSize);
|
||||
};
|
||||
|
||||
const startDrag = (e) => {
|
||||
isDragging.value = true;
|
||||
updateFromEvent(e);
|
||||
};
|
||||
|
||||
const onDrag = (e) => {
|
||||
if (!isDragging.value) return;
|
||||
updateFromEvent(e);
|
||||
};
|
||||
|
||||
const stopDrag = () => {
|
||||
isDragging.value = false;
|
||||
};
|
||||
|
||||
const showAdvanced = ref(false);
|
||||
|
||||
const toggleAdvanced = () => {
|
||||
showAdvanced.value = !showAdvanced.value;
|
||||
if (showAdvanced.value) {
|
||||
nextTick(drawMap);
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
const savedSize = localStorage.getItem('nonograms_custom_size');
|
||||
if (savedSize && !isNaN(savedSize)) {
|
||||
customSize.value = Math.max(5, Math.min(80, Number(savedSize)));
|
||||
}
|
||||
|
||||
const savedFillRate = localStorage.getItem('nonograms_custom_fill_rate');
|
||||
if (savedFillRate && !isNaN(savedFillRate)) {
|
||||
fillRate.value = Math.max(10, Math.min(90, Number(savedFillRate)));
|
||||
}
|
||||
|
||||
// Don't draw map initially if hidden
|
||||
});
|
||||
|
||||
watch([customSize, fillRate], () => {
|
||||
if (showAdvanced.value) {
|
||||
drawMap();
|
||||
}
|
||||
});
|
||||
|
||||
watch(customSize, (newVal) => {
|
||||
localStorage.setItem('nonograms_custom_size', newVal);
|
||||
});
|
||||
|
||||
watch(fillRate, (newVal) => {
|
||||
localStorage.setItem('nonograms_custom_fill_rate', newVal);
|
||||
});
|
||||
|
||||
const snapToStep = (value, step) => {
|
||||
const rounded = Math.round(value / step) * step;
|
||||
@@ -20,18 +196,12 @@ const handleSnap = () => {
|
||||
customSize.value = snapToStep(Number(customSize.value), 5);
|
||||
};
|
||||
|
||||
const difficultyLevel = computed(() => {
|
||||
const rate = fillRate.value;
|
||||
const dist = Math.abs(rate - 50);
|
||||
|
||||
if (dist <= 5) return 'extreme';
|
||||
if (dist <= 15) return 'hardest';
|
||||
if (dist <= 25) return 'harder';
|
||||
return 'easy';
|
||||
const difficultyInfo = computed(() => {
|
||||
return calculateDifficulty(fillRate.value / 100, customSize.value);
|
||||
});
|
||||
|
||||
const difficultyColor = computed(() => {
|
||||
switch(difficultyLevel.value) {
|
||||
switch(difficultyInfo.value.level) {
|
||||
case 'extreme': return '#ff3333';
|
||||
case 'hardest': return '#ff9933';
|
||||
case 'harder': return '#ffff33';
|
||||
@@ -56,45 +226,75 @@ const confirm = () => {
|
||||
<div class="modal-overlay" @click.self="emit('close')">
|
||||
<div class="modal glass-panel">
|
||||
<h2>{{ t('custom.title') }}</h2>
|
||||
<p>{{ t('custom.prompt') }}</p>
|
||||
|
||||
<div class="input-group">
|
||||
<div class="range-value">{{ customSize }}</div>
|
||||
<input
|
||||
type="range"
|
||||
v-model="customSize"
|
||||
min="5"
|
||||
max="80"
|
||||
step="1"
|
||||
@change="handleSnap"
|
||||
/>
|
||||
<div class="range-scale">
|
||||
<span>5</span>
|
||||
<span>80</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-content">
|
||||
<div class="sliders-section">
|
||||
<div class="slider-container">
|
||||
<p>{{ t('custom.prompt') }}</p>
|
||||
<div class="input-group">
|
||||
<div class="range-value">{{ customSize }}</div>
|
||||
<input
|
||||
type="range"
|
||||
v-model="customSize"
|
||||
min="5"
|
||||
max="80"
|
||||
step="1"
|
||||
@change="handleSnap"
|
||||
/>
|
||||
<div class="range-scale">
|
||||
<span>5</span>
|
||||
<span>80</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>{{ t('custom.fillRate') }}</p>
|
||||
<div class="input-group">
|
||||
<div class="range-value">{{ fillRate }}%</div>
|
||||
<input
|
||||
type="range"
|
||||
v-model="fillRate"
|
||||
min="10"
|
||||
max="90"
|
||||
step="5"
|
||||
/>
|
||||
<div class="range-scale">
|
||||
<span>10%</span>
|
||||
<span>90%</span>
|
||||
<div class="slider-container">
|
||||
<p>{{ t('custom.fillRate') }}</p>
|
||||
<div class="input-group">
|
||||
<div class="range-value">{{ fillRate }}%</div>
|
||||
<input
|
||||
type="range"
|
||||
v-model="fillRate"
|
||||
min="10"
|
||||
max="90"
|
||||
step="1"
|
||||
/>
|
||||
<div class="range-scale">
|
||||
<span>10%</span>
|
||||
<span>90%</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="map-section" v-if="showAdvanced">
|
||||
<canvas
|
||||
ref="difficultyCanvas"
|
||||
width="200"
|
||||
height="200"
|
||||
@mousedown="startDrag"
|
||||
@mousemove="onDrag"
|
||||
@mouseup="stopDrag"
|
||||
@mouseleave="stopDrag"
|
||||
@touchstart.prevent="startDrag"
|
||||
@touchmove.prevent="onDrag"
|
||||
@touchend="stopDrag"
|
||||
></canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="difficulty-indicator">
|
||||
<span class="label">{{ t('custom.difficulty') }}:</span>
|
||||
<span class="value" :style="{ color: difficultyColor }">
|
||||
{{ t(`difficulty.${difficultyLevel}`) }}
|
||||
</span>
|
||||
<div class="label">{{ t('custom.difficulty') }}</div>
|
||||
<div class="difficulty-row">
|
||||
<div class="level" :style="{ color: difficultyColor }">{{ t(`difficulty.${difficultyInfo.level}`) }}</div>
|
||||
<div class="percentage" :style="{ color: difficultyColor }">({{ difficultyInfo.value }}%)</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="advanced-toggle">
|
||||
<button class="btn-text" @click="toggleAdvanced">
|
||||
{{ showAdvanced ? 'Ukryj mapę trudności' : 'Pokaż mapę trudności' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p v-if="errorMsg" class="error">{{ errorMsg }}</p>
|
||||
@@ -126,7 +326,7 @@ const confirm = () => {
|
||||
.modal {
|
||||
padding: 40px;
|
||||
text-align: center;
|
||||
max-width: 400px;
|
||||
max-width: 800px;
|
||||
width: 90%;
|
||||
border: 1px solid var(--accent-cyan);
|
||||
box-shadow: 0 0 50px rgba(0, 242, 255, 0.2);
|
||||
@@ -134,6 +334,44 @@ const confirm = () => {
|
||||
transition: all 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 40px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.modal-content {
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.sliders-section {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.map-section {
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
canvas {
|
||||
border: 2px solid var(--panel-border);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 0 20px rgba(0, 242, 255, 0.1);
|
||||
cursor: crosshair;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 2rem;
|
||||
color: var(--accent-cyan);
|
||||
@@ -147,6 +385,11 @@ p {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.slider-container {
|
||||
width: 100%;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
@@ -207,14 +450,38 @@ input[type="range"]::-moz-range-thumb {
|
||||
}
|
||||
|
||||
.difficulty-indicator {
|
||||
margin: 20px 0;
|
||||
font-size: 1.2rem;
|
||||
margin: 20px 0 40px 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.difficulty-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 8px;
|
||||
align-items: baseline;
|
||||
justify-content: center;
|
||||
white-space: nowrap;
|
||||
height: 1.5em; /* Reserve space for one line of text */
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 1rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.level {
|
||||
font-size: 1.4rem;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.percentage {
|
||||
font-size: 1rem;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.difficulty-indicator .label {
|
||||
@@ -236,6 +503,25 @@ input[type="range"]::-moz-range-thumb {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.btn-text {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--accent-cyan);
|
||||
font-size: 0.9rem;
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
opacity: 0.8;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.btn-text:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.advanced-toggle {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
|
||||
@@ -4,9 +4,8 @@ import { Fireworks } from 'fireworks-js';
|
||||
import { usePuzzleStore } from '@/stores/puzzle';
|
||||
import { useI18n } from '@/composables/useI18n';
|
||||
import { useTimer } from '@/composables/useTimer';
|
||||
import xIcon from '@/assets/brands/x.svg';
|
||||
import facebookIcon from '@/assets/brands/facebook.svg';
|
||||
import whatsappIcon from '@/assets/brands/whatsapp.svg';
|
||||
import { Download, FileCode } from 'lucide-vue-next';
|
||||
import { calculateDifficulty } from '@/utils/puzzleUtils';
|
||||
|
||||
const store = usePuzzleStore();
|
||||
const { t } = useI18n();
|
||||
@@ -42,30 +41,43 @@ const playFanfare = async () => {
|
||||
}
|
||||
}
|
||||
masterGain = audioContext.createGain();
|
||||
masterGain.gain.value = 0.18;
|
||||
masterGain.gain.value = 0.25; // Slightly louder but softer tone
|
||||
masterGain.connect(audioContext.destination);
|
||||
const notes = [
|
||||
{ time: 0.0, dur: 0.18, freqs: [523.25, 659.25, 783.99] },
|
||||
{ time: 0.2, dur: 0.18, freqs: [587.33, 740.0, 880.0] },
|
||||
{ time: 0.4, dur: 0.22, freqs: [659.25, 830.61, 987.77] },
|
||||
{ time: 0.7, dur: 0.35, freqs: [698.46, 880.0, 1046.5] }
|
||||
];
|
||||
|
||||
const now = audioContext.currentTime;
|
||||
notes.forEach(({ time, dur, freqs }) => {
|
||||
freqs.forEach((freq) => {
|
||||
const osc = audioContext.createOscillator();
|
||||
const gain = audioContext.createGain();
|
||||
osc.type = 'triangle';
|
||||
osc.frequency.value = freq;
|
||||
gain.gain.setValueAtTime(0.0001, now + time);
|
||||
gain.gain.linearRampToValueAtTime(0.8, now + time + 0.02);
|
||||
gain.gain.exponentialRampToValueAtTime(0.0001, now + time + dur);
|
||||
osc.connect(gain);
|
||||
gain.connect(masterGain);
|
||||
osc.start(now + time);
|
||||
osc.stop(now + time + dur + 0.05);
|
||||
});
|
||||
});
|
||||
|
||||
const playNote = (freq, startTime, duration) => {
|
||||
const osc = audioContext.createOscillator();
|
||||
const gain = audioContext.createGain();
|
||||
|
||||
// Mix of sine and triangle for a bell-like quality
|
||||
osc.type = 'sine';
|
||||
osc.frequency.value = freq;
|
||||
|
||||
// Envelope for elegant bell/chime sound
|
||||
gain.gain.setValueAtTime(0, startTime);
|
||||
gain.gain.linearRampToValueAtTime(0.4, startTime + 0.05); // Soft attack
|
||||
gain.gain.exponentialRampToValueAtTime(0.01, startTime + duration); // Long release
|
||||
|
||||
osc.connect(gain);
|
||||
gain.connect(masterGain);
|
||||
|
||||
osc.start(startTime);
|
||||
osc.stop(startTime + duration + 0.1);
|
||||
};
|
||||
|
||||
// C Major 7 Arpeggio sequence (C5, E5, G5, B5, C6) - Elegant & Uplifting
|
||||
const sequence = [
|
||||
{ freq: 523.25, time: 0.0, dur: 0.8 }, // C5
|
||||
{ freq: 659.25, time: 0.1, dur: 0.8 }, // E5
|
||||
{ freq: 783.99, time: 0.2, dur: 0.8 }, // G5
|
||||
{ freq: 987.77, time: 0.3, dur: 0.8 }, // B5 (Maj7)
|
||||
{ freq: 1046.50, time: 0.4, dur: 2.0 }, // C6 (High C resolve)
|
||||
// Add a bass root note at the end for fullness
|
||||
{ freq: 523.25, time: 0.4, dur: 2.0 } // C5
|
||||
];
|
||||
|
||||
sequence.forEach(note => playNote(note.freq, now + note.time, note.dur));
|
||||
};
|
||||
|
||||
const triggerVibration = () => {
|
||||
@@ -113,12 +125,11 @@ const buildShareCanvas = () => {
|
||||
|
||||
// Difficulty & Density Info
|
||||
const densityPercent = Math.round(store.currentDensity * 100);
|
||||
const dist = Math.abs(densityPercent - 50);
|
||||
let difficultyKey = 'easy';
|
||||
const difficultyKey = calculateDifficulty(store.currentDensity);
|
||||
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'; }
|
||||
if (difficultyKey === 'extreme') diffColor = '#ff3333';
|
||||
else if (difficultyKey === 'hardest') diffColor = '#ff9933';
|
||||
else if (difficultyKey === 'harder') diffColor = '#ffff33';
|
||||
|
||||
const difficultyText = t(`difficulty.${difficultyKey}`);
|
||||
ctx.font = '600 14px "Segoe UI", sans-serif';
|
||||
@@ -177,7 +188,11 @@ const buildShareCanvas = () => {
|
||||
if (store.guideUsageCount > 0) {
|
||||
ctx.fillStyle = '#ff4d4d';
|
||||
ctx.font = '600 14px "Segoe UI", sans-serif';
|
||||
const guideText = t('win.usedGuide', { count: store.guideUsageCount });
|
||||
|
||||
const totalCells = store.size * store.size;
|
||||
const percent = Math.min(100, Math.round((store.guideUsageCount / totalCells) * 100));
|
||||
const guideText = t('win.usedGuide', { count: store.guideUsageCount, percent });
|
||||
|
||||
ctx.fillText(`⚠️ ${guideText}`, padding, height - padding - footerHeight + 10);
|
||||
}
|
||||
|
||||
@@ -187,6 +202,125 @@ const buildShareCanvas = () => {
|
||||
return canvas;
|
||||
};
|
||||
|
||||
const buildShareSVG = () => {
|
||||
const grid = store.playerGrid;
|
||||
if (!grid || !grid.length) return null;
|
||||
|
||||
const appUrl = 'https://nonograms.7u.pl/';
|
||||
const size = store.size;
|
||||
const maxBoard = 640;
|
||||
const cellSize = Math.max(8, Math.floor(maxBoard / size));
|
||||
const boardSize = cellSize * size;
|
||||
const padding = 28;
|
||||
const headerHeight = 64;
|
||||
const footerHeight = 28;
|
||||
const infoHeight = 40;
|
||||
const width = boardSize + padding * 2;
|
||||
const height = boardSize + padding * 2 + headerHeight + footerHeight + infoHeight;
|
||||
|
||||
// Colors
|
||||
const bgGradientStart = '#1b2a4a';
|
||||
const bgGradientEnd = '#0a1324';
|
||||
const overlayColor = 'rgba(0, 0, 0, 0.35)';
|
||||
const textColor = '#e8fbff';
|
||||
const gridColor = 'rgba(255, 255, 255, 0.06)';
|
||||
const gridLineColor = 'rgba(255, 255, 255, 0.12)';
|
||||
const filledColor = '#00f2fe';
|
||||
const crossColor = 'rgba(255, 255, 255, 0.5)';
|
||||
const urlColor = 'rgba(255, 255, 255, 0.75)';
|
||||
|
||||
// Difficulty Logic
|
||||
const densityPercent = Math.round(store.currentDensity * 100);
|
||||
const diffInfo = calculateDifficulty(store.currentDensity, store.size);
|
||||
const difficultyKey = diffInfo.level;
|
||||
let diffColor = '#33ff33';
|
||||
if (difficultyKey === 'extreme') diffColor = '#ff3333';
|
||||
else if (difficultyKey === 'hardest') diffColor = '#ff9933';
|
||||
else if (difficultyKey === 'harder') diffColor = '#ffff33';
|
||||
const difficultyText = t(`difficulty.${difficultyKey}`);
|
||||
const diffLabel = `${t('win.difficulty')} ${difficultyText} (${densityPercent}%)`;
|
||||
|
||||
let svgContent = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}">`;
|
||||
|
||||
// Background
|
||||
svgContent += `
|
||||
<defs>
|
||||
<linearGradient id="bg" x1="0%" y1="0%" x2="100%" y2="100%">
|
||||
<stop offset="0%" stop-color="${bgGradientStart}"/>
|
||||
<stop offset="100%" stop-color="${bgGradientEnd}"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="url(#bg)"/>
|
||||
<rect x="12" y="12" width="${width - 24}" height="${height - 24}" fill="${overlayColor}"/>
|
||||
`;
|
||||
|
||||
// Text: Title & Time
|
||||
svgContent += `
|
||||
<text x="${padding}" y="${padding + 28}" font-family="Segoe UI, sans-serif" font-weight="700" font-size="26" fill="${textColor}">${t('app.title')}</text>
|
||||
<text x="${padding}" y="${padding + 56}" font-family="Segoe UI, sans-serif" font-weight="600" font-size="16" fill="${textColor}">${t('win.time')} ${formattedTime.value}</text>
|
||||
`;
|
||||
|
||||
// Text: Difficulty (Right Aligned - manual approx or end anchor)
|
||||
svgContent += `
|
||||
<text x="${width - padding}" y="${padding + 56}" font-family="Segoe UI, sans-serif" font-weight="600" font-size="14" fill="${diffColor}" text-anchor="end">${diffLabel}</text>
|
||||
`;
|
||||
|
||||
const gridX = padding;
|
||||
const gridY = padding + headerHeight;
|
||||
|
||||
// Grid Background
|
||||
svgContent += `<rect x="${gridX}" y="${gridY}" width="${boardSize}" height="${boardSize}" fill="${gridColor}"/>`;
|
||||
|
||||
// Grid Lines
|
||||
let gridLines = '';
|
||||
for (let i = 0; i <= size; i++) {
|
||||
const pos = i * cellSize;
|
||||
// Vertical
|
||||
gridLines += `<line x1="${gridX + pos}" y1="${gridY}" x2="${gridX + pos}" y2="${gridY + boardSize}" stroke="${gridLineColor}" stroke-width="1"/>`;
|
||||
// Horizontal
|
||||
gridLines += `<line x1="${gridX}" y1="${gridY + pos}" x2="${gridX + boardSize}" y2="${gridY + pos}" stroke="${gridLineColor}" stroke-width="1"/>`;
|
||||
}
|
||||
svgContent += gridLines;
|
||||
|
||||
// Cells
|
||||
let cells = '';
|
||||
const lineWidth = Math.max(1.5, Math.floor(cellSize * 0.12));
|
||||
|
||||
for (let r = 0; r < size; r++) {
|
||||
for (let c = 0; c < size; c++) {
|
||||
const state = grid[r]?.[c];
|
||||
const cx = gridX + c * cellSize;
|
||||
const cy = gridY + r * cellSize;
|
||||
|
||||
if (state === 1) { // Filled
|
||||
cells += `<rect x="${cx + 1}" y="${cy + 1}" width="${cellSize - 2}" height="${cellSize - 2}" fill="${filledColor}"/>`;
|
||||
} else if (state === 2) { // Cross
|
||||
const d = cellSize * 0.6;
|
||||
const off = cellSize * 0.2;
|
||||
cells += `
|
||||
<path d="M${cx + off} ${cy + off} L${cx + off + d} ${cy + off + d} M${cx + off + d} ${cy + off} L${cx + off} ${cy + off + d}"
|
||||
stroke="${crossColor}" stroke-width="${lineWidth}" stroke-linecap="round"/>
|
||||
`;
|
||||
}
|
||||
}
|
||||
}
|
||||
svgContent += cells;
|
||||
|
||||
// Guide Usage
|
||||
if (store.guideUsageCount > 0) {
|
||||
const totalCells = store.size * store.size;
|
||||
const percent = Math.min(100, Math.round((store.guideUsageCount / totalCells) * 100));
|
||||
const guideText = t('win.usedGuide', { count: store.guideUsageCount, percent });
|
||||
svgContent += `<text x="${padding}" y="${height - padding - footerHeight + 10}" font-family="Segoe UI, sans-serif" font-weight="600" font-size="14" fill="#ff4d4d">⚠️ ${guideText}</text>`;
|
||||
}
|
||||
|
||||
// URL
|
||||
svgContent += `<text x="${padding}" y="${height - padding + 6}" font-family="Segoe UI, sans-serif" font-weight="500" font-size="14" fill="${urlColor}">${appUrl}</text>`;
|
||||
|
||||
svgContent += '</svg>';
|
||||
return svgContent;
|
||||
};
|
||||
|
||||
const canvasToBlob = (canvas) => new Promise((resolve) => canvas.toBlob((blob) => resolve(blob), 'image/png'));
|
||||
|
||||
const createShareBlob = async () => {
|
||||
@@ -195,6 +329,20 @@ const createShareBlob = async () => {
|
||||
return canvasToBlob(canvas);
|
||||
};
|
||||
|
||||
const downloadShareSVG = () => {
|
||||
const svgString = buildShareSVG();
|
||||
if (!svgString) return;
|
||||
const blob = new Blob([svgString], { type: 'image/svg+xml' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = `nonogram-${store.size}x${store.size}.svg`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const downloadShareImage = async () => {
|
||||
const blob = await createShareBlob();
|
||||
if (!blob) return;
|
||||
@@ -212,7 +360,7 @@ const buildShareUrl = (target, text, url) => {
|
||||
const encodedText = encodeURIComponent(text);
|
||||
const encodedUrl = encodeURIComponent(url);
|
||||
if (target === 'x') {
|
||||
return `https://twitter.com/intent/tweet?text=${encodedText}&url=${encodedUrl}`;
|
||||
return `https://x.com/intent/tweet?text=${encodedText}&url=${encodedUrl}`;
|
||||
}
|
||||
if (target === 'facebook') {
|
||||
return `https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}"e=${encodedText}`;
|
||||
@@ -226,29 +374,48 @@ const buildShareUrl = (target, text, url) => {
|
||||
const shareTo = async (target) => {
|
||||
if (shareInProgress.value) return;
|
||||
shareInProgress.value = true;
|
||||
|
||||
const text = shareText.value;
|
||||
const url = window.location.href;
|
||||
const shareUrl = buildShareUrl(target, text, url);
|
||||
|
||||
try {
|
||||
const blob = await createShareBlob();
|
||||
if (!blob) return;
|
||||
const file = new File([blob], `nonogram-${store.size}x${store.size}.png`, { type: 'image/png' });
|
||||
const text = shareText.value;
|
||||
const url = window.location.href;
|
||||
if (navigator.share && navigator.canShare && navigator.canShare({ files: [file] })) {
|
||||
await navigator.share({
|
||||
files: [file],
|
||||
text,
|
||||
title: t('app.title'),
|
||||
url
|
||||
});
|
||||
return;
|
||||
// Try native share first if available (supports images)
|
||||
if (navigator.share && navigator.canShare) {
|
||||
const blob = await createShareBlob();
|
||||
if (blob) {
|
||||
const file = new File([blob], `nonogram-${store.size}x${store.size}.png`, { type: 'image/png' });
|
||||
if (navigator.canShare({ files: [file] })) {
|
||||
await navigator.share({
|
||||
files: [file],
|
||||
text,
|
||||
title: t('app.title'),
|
||||
url
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
await downloadShareImage();
|
||||
const shareUrl = buildShareUrl(target, text, url);
|
||||
if (shareUrl) {
|
||||
window.open(shareUrl, '_blank', 'noopener');
|
||||
} catch (error) {
|
||||
if (error.name === 'AbortError') {
|
||||
return; // User cancelled native share, do nothing
|
||||
}
|
||||
// Other errors -> fall through to fallback
|
||||
} finally {
|
||||
shareInProgress.value = false;
|
||||
}
|
||||
|
||||
// Fallback: Direct Link + Download
|
||||
// Open window immediately if possible (though we awaited above, so it might be blocked,
|
||||
// but we can't do much about it if we want to try native share first).
|
||||
// Ideally, for Desktop, navigator.share is undefined so we skip the await above.
|
||||
|
||||
if (shareUrl) {
|
||||
window.open(shareUrl, '_blank', 'noopener');
|
||||
}
|
||||
|
||||
// Trigger download as "screenshot support"
|
||||
downloadShareImage();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
@@ -308,19 +475,27 @@ onUnmounted(() => {
|
||||
<div class="share">
|
||||
<div class="share-title">{{ t('win.shareTitle') }}</div>
|
||||
<div class="share-buttons">
|
||||
<!-- X (Twitter) -->
|
||||
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareX')" @click="shareTo('x')">
|
||||
<img :src="xIcon" alt="" class="share-icon" />
|
||||
<svg viewBox="0 0 24 24" fill="currentColor" class="share-icon"><path d="M18.901 3H22l-7.21 8.26L23 21h-6.66L11.13 14.76 5.66 21H2.56l7.73-8.83L1 3h6.8l4.63 5.56L18.9 3h.001zm-1.2 15.9h1.77L6.44 5.1H4.44l13.26 13.8z"/></svg>
|
||||
</button>
|
||||
<!-- Facebook -->
|
||||
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareFacebook')" @click="shareTo('facebook')">
|
||||
<img :src="facebookIcon" alt="" class="share-icon" />
|
||||
<svg viewBox="0 0 24 24" fill="currentColor" class="share-icon"><path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.791-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/></svg>
|
||||
</button>
|
||||
<!-- WhatsApp -->
|
||||
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareWhatsapp')" @click="shareTo('whatsapp')">
|
||||
<img :src="whatsappIcon" alt="" class="share-icon" />
|
||||
<svg viewBox="0 0 24 24" fill="currentColor" class="share-icon"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.008-.57-.008-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z"/></svg>
|
||||
</button>
|
||||
<!-- Download Screenshot (Compact) -->
|
||||
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" :aria-label="t('win.shareDownload')" @click="downloadShareImage">
|
||||
<Download :size="20" />
|
||||
</button>
|
||||
<!-- Download SVG (Compact) -->
|
||||
<button class="btn-neon secondary share-btn" :disabled="shareInProgress" aria-label="Download SVG" @click="downloadShareSVG">
|
||||
<FileCode :size="20" />
|
||||
</button>
|
||||
</div>
|
||||
<button class="btn-neon secondary share-download" :disabled="shareInProgress" @click="downloadShareImage">
|
||||
{{ t('win.shareDownload') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
|
||||
@@ -46,7 +46,7 @@ const messages = {
|
||||
'win.shareWhatsapp': 'WhatsApp',
|
||||
'win.shareDownload': 'Pobierz zrzut',
|
||||
'win.difficulty': 'Poziom:',
|
||||
'win.usedGuide': 'Użyto podpowiedzi: {count}',
|
||||
'win.usedGuide': 'Podpowiedzi: {percent}% ({count})',
|
||||
'pwa.installTitle': 'Zainstaluj aplikację i graj offline',
|
||||
'pwa.installMobile': 'Dodaj do ekranu głównego',
|
||||
'pwa.installDesktop': 'Zainstaluj na komputerze',
|
||||
@@ -153,7 +153,7 @@ const messages = {
|
||||
'win.shareWhatsapp': 'WhatsApp',
|
||||
'win.shareDownload': 'Download screenshot',
|
||||
'win.difficulty': 'Difficulty:',
|
||||
'win.usedGuide': 'Guide used: {count}',
|
||||
'win.usedGuide': 'Hints: {percent}% ({count})',
|
||||
'pwa.installTitle': 'Install the app and play offline',
|
||||
'pwa.installMobile': 'Add to home screen',
|
||||
'pwa.installDesktop': 'Install on desktop',
|
||||
@@ -295,9 +295,17 @@ const messages = {
|
||||
'custom.cancel': '取消',
|
||||
'custom.start': '开始',
|
||||
'custom.sizeError': '尺寸必须在 5 到 80 之间!',
|
||||
'custom.fillRate': '填充率',
|
||||
'custom.difficulty': '难度',
|
||||
'difficulty.easy': '简单',
|
||||
'difficulty.harder': '较难',
|
||||
'difficulty.hardest': '最难',
|
||||
'difficulty.extreme': '极限',
|
||||
'win.title': '恭喜!',
|
||||
'win.message': '你解开了谜题!',
|
||||
'win.time': '时间:',
|
||||
'win.difficulty': '难度:',
|
||||
'win.usedGuide': '使用指南: {count}',
|
||||
'win.playAgain': '再玩一次',
|
||||
'win.shareTitle': '分享你的结果',
|
||||
'win.shareText': '我在 {time} 内解开了 {size}x{size} 的数织!',
|
||||
@@ -495,9 +503,17 @@ const messages = {
|
||||
'custom.cancel': 'Cancelar',
|
||||
'custom.start': 'Empezar',
|
||||
'custom.sizeError': '¡El tamaño debe estar entre 5 y 80!',
|
||||
'custom.fillRate': 'Relleno',
|
||||
'custom.difficulty': 'Dificultad',
|
||||
'difficulty.easy': 'Fácil',
|
||||
'difficulty.harder': 'Más difícil',
|
||||
'difficulty.hardest': 'El más difícil',
|
||||
'difficulty.extreme': 'Extremo',
|
||||
'win.title': '¡FELICIDADES!',
|
||||
'win.message': '¡Has resuelto el rompecabezas!',
|
||||
'win.time': 'Tiempo:',
|
||||
'win.difficulty': 'Dificultad:',
|
||||
'win.usedGuide': 'Guía usada: {count}',
|
||||
'win.playAgain': 'Jugar de nuevo',
|
||||
'win.shareTitle': 'Comparte tu resultado',
|
||||
'win.shareText': '¡Resolví un nonograma de {size}x{size} en {time}!',
|
||||
@@ -561,9 +577,17 @@ const messages = {
|
||||
'custom.cancel': 'Annuler',
|
||||
'custom.start': 'Démarrer',
|
||||
'custom.sizeError': 'La taille doit être entre 5 et 80 !',
|
||||
'custom.fillRate': 'Remplissage',
|
||||
'custom.difficulty': 'Difficulté',
|
||||
'difficulty.easy': 'Facile',
|
||||
'difficulty.harder': 'Plus difficile',
|
||||
'difficulty.hardest': 'Le plus difficile',
|
||||
'difficulty.extreme': 'Extrême',
|
||||
'win.title': 'FÉLICITATIONS !',
|
||||
'win.message': 'Vous avez résolu le puzzle !',
|
||||
'win.time': 'Temps:',
|
||||
'win.difficulty': 'Difficulté :',
|
||||
'win.usedGuide': 'Guide utilisé : {count}',
|
||||
'win.playAgain': 'Rejouer',
|
||||
'win.shareTitle': 'Partagez votre résultat',
|
||||
'win.shareText': 'J’ai résolu un nonogramme {size}x{size} en {time} !',
|
||||
@@ -627,9 +651,17 @@ const messages = {
|
||||
'custom.cancel': 'إلغاء',
|
||||
'custom.start': 'ابدأ',
|
||||
'custom.sizeError': 'يجب أن يكون الحجم بين 5 و80!',
|
||||
'custom.fillRate': 'معدل الملء',
|
||||
'custom.difficulty': 'الصعوبة',
|
||||
'difficulty.easy': 'سهل',
|
||||
'difficulty.harder': 'أصعب',
|
||||
'difficulty.hardest': 'الأصعب',
|
||||
'difficulty.extreme': 'أقصى',
|
||||
'win.title': 'تهانينا!',
|
||||
'win.message': 'لقد حللت اللغز!',
|
||||
'win.time': 'الوقت:',
|
||||
'win.difficulty': 'الصعوبة:',
|
||||
'win.usedGuide': 'تم استخدام الدليل: {count}',
|
||||
'win.playAgain': 'العب مرة أخرى',
|
||||
'win.shareTitle': 'شارك نتيجتك',
|
||||
'win.shareText': 'حللت نونوغرام {size}x{size} في {time}!',
|
||||
@@ -759,9 +791,17 @@ const messages = {
|
||||
'custom.cancel': 'Отмена',
|
||||
'custom.start': 'Старт',
|
||||
'custom.sizeError': 'Размер должен быть от 5 до 80!',
|
||||
'custom.fillRate': 'Заполнение',
|
||||
'custom.difficulty': 'Сложность',
|
||||
'difficulty.easy': 'Легкий',
|
||||
'difficulty.harder': 'Сложный',
|
||||
'difficulty.hardest': 'Очень сложный',
|
||||
'difficulty.extreme': 'Экстремальный',
|
||||
'win.title': 'ПОЗДРАВЛЯЕМ!',
|
||||
'win.message': 'Вы решили головоломку!',
|
||||
'win.time': 'Время:',
|
||||
'win.difficulty': 'Сложность:',
|
||||
'win.usedGuide': 'Подсказок использовано: {count}',
|
||||
'win.playAgain': 'Сыграть снова',
|
||||
'win.shareTitle': 'Поделитесь результатом',
|
||||
'win.shareText': 'Я решил(а) нонограмму {size}x{size} за {time}!',
|
||||
@@ -958,9 +998,17 @@ const messages = {
|
||||
'custom.cancel': 'Abbrechen',
|
||||
'custom.start': 'Start',
|
||||
'custom.sizeError': 'Die Größe muss zwischen 5 und 80 liegen!',
|
||||
'custom.fillRate': 'Füllrate',
|
||||
'custom.difficulty': 'Schwierigkeit',
|
||||
'difficulty.easy': 'Einfach',
|
||||
'difficulty.harder': 'Schwerer',
|
||||
'difficulty.hardest': 'Am schwersten',
|
||||
'difficulty.extreme': 'Extrem',
|
||||
'win.title': 'HERZLICHEN GLÜCKWUNSCH!',
|
||||
'win.message': 'Sie haben das Rätsel gelöst!',
|
||||
'win.time': 'Zeit:',
|
||||
'win.difficulty': 'Schwierigkeit:',
|
||||
'win.usedGuide': 'Hilfe benutzt: {count}',
|
||||
'win.playAgain': 'Erneut spielen',
|
||||
'win.shareTitle': 'Teilen Sie Ihr Ergebnis',
|
||||
'win.shareText': 'Ich habe ein {size}x{size} Nonogramm in {time} gelöst!',
|
||||
|
||||
@@ -78,6 +78,9 @@ export function useSolver() {
|
||||
} else if (type === 'done') {
|
||||
isProcessing.value = false;
|
||||
pause();
|
||||
} else if (type === 'stuck') {
|
||||
isProcessing.value = false;
|
||||
pause();
|
||||
} else {
|
||||
isProcessing.value = false;
|
||||
}
|
||||
|
||||
@@ -51,3 +51,37 @@ export function generateRandomGrid(size, density = 0.5) {
|
||||
}
|
||||
return grid;
|
||||
}
|
||||
|
||||
export function calculateDifficulty(density, size = 10) {
|
||||
// Shannon Entropy: H(x) = -x*log2(x) - (1-x)*log2(1-x)
|
||||
// Normalized to 0-1 range (since max entropy at 0.5 is 1)
|
||||
|
||||
// Avoid log(0)
|
||||
if (density <= 0 || density >= 1) return { level: 'easy', value: 0 };
|
||||
|
||||
const entropy = -density * Math.log2(density) - (1 - density) * Math.log2(1 - density);
|
||||
|
||||
// Difficulty score combines entropy (complexity) and size (scale)
|
||||
// We use sqrt(size) to dampen the effect of very large grids,
|
||||
// ensuring that density still plays a major role.
|
||||
// Normalized against max size (80)
|
||||
const sizeFactor = Math.sqrt(size / 80);
|
||||
const score = entropy * sizeFactor * 100;
|
||||
const value = Math.round(score);
|
||||
|
||||
// Thresholds
|
||||
let level = 'easy';
|
||||
if (value >= 80) level = 'extreme';
|
||||
else if (value >= 60) level = 'hardest';
|
||||
else if (value >= 40) level = 'harder';
|
||||
else if (value >= 20) level = 'medium'; // Using 'medium' key if available, or we need to add it?
|
||||
// Wait, useI18n only has: easy, harder, hardest, extreme.
|
||||
// Let's stick to those keys but adjust ranges.
|
||||
|
||||
if (value >= 75) level = 'extreme';
|
||||
else if (value >= 50) level = 'hardest';
|
||||
else if (value >= 25) level = 'harder';
|
||||
else level = 'easy';
|
||||
|
||||
return { level, value };
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ const messages = {
|
||||
'worker.solved': 'Rozwiązane!',
|
||||
'worker.logicRow': 'Logika: Wiersz {row}, Kolumna {col} -> {state}',
|
||||
'worker.logicCol': 'Logika: Kolumna {col}, Wiersz {row} -> {state}',
|
||||
'worker.guess': 'Zgadywanie: Wiersz {row}, Kolumna {col}',
|
||||
'worker.stuck': 'Brak logicznego ruchu. Spróbuj zgadnąć lub cofnąć.',
|
||||
'worker.done': 'Koniec!',
|
||||
'worker.state.filled': 'Pełne',
|
||||
'worker.state.empty': 'Puste'
|
||||
@@ -14,7 +14,7 @@ const messages = {
|
||||
'worker.solved': 'Solved!',
|
||||
'worker.logicRow': 'Logic: Row {row}, Column {col} -> {state}',
|
||||
'worker.logicCol': 'Logic: Column {col}, Row {row} -> {state}',
|
||||
'worker.guess': 'Guessing: Row {row}, Column {col}',
|
||||
'worker.stuck': 'No logical move found. Try guessing or undoing.',
|
||||
'worker.done': 'Done!',
|
||||
'worker.state.filled': 'Filled',
|
||||
'worker.state.empty': 'Empty'
|
||||
@@ -91,15 +91,33 @@ const solveLineLogic = (lineState, hints) => {
|
||||
return result;
|
||||
}
|
||||
const len = hints[hintIndex];
|
||||
// maxStart logic: we need enough space for this block (len) + subsequent blocks/gaps (suffixMin[hintIndex+1])
|
||||
// suffixMin[hintIndex] = len + (m - hintIndex - 1) + suffixMin[hintIndex+1]
|
||||
// Actually suffixMin[hintIndex] already includes everything needed from here to end.
|
||||
// So if we place block at start, end is start + len.
|
||||
// Total space needed is suffixMin[hintIndex].
|
||||
// So start can go up to n - suffixMin[hintIndex].
|
||||
const maxStart = n - suffixMin[hintIndex];
|
||||
|
||||
for (let start = pos; start <= maxStart; start++) {
|
||||
if (hasFilled(pos, start)) continue;
|
||||
if (hasCross(start, start + len)) continue;
|
||||
if (start + len < n && lineState[start + len] === 1) continue;
|
||||
const nextPos = start + len < n ? start + len + 1 : start + len;
|
||||
if (canPlaceSuffix(nextPos, hintIndex + 1)) {
|
||||
memoSuffix[pos][hintIndex] = true;
|
||||
return true;
|
||||
if (hasFilled(pos, start)) continue; // Must be empty before this block
|
||||
if (hasCross(start, start + len)) continue; // Block space must be free of crosses
|
||||
|
||||
// If not the last block, we need a gap after
|
||||
if (hintIndex < m - 1) {
|
||||
if (start + len < n && lineState[start + len] === 1) continue; // Gap must not be filled
|
||||
// We can assume gap is at start + len. Next block starts at least at start + len + 1
|
||||
const nextPos = start + len + 1;
|
||||
if (canPlaceSuffix(nextPos, hintIndex + 1)) {
|
||||
memoSuffix[pos][hintIndex] = true;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// Last block
|
||||
// Check if we can fill the rest with empty
|
||||
if (hasFilled(start + len, n)) continue;
|
||||
memoSuffix[pos][hintIndex] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
memoSuffix[pos][hintIndex] = false;
|
||||
@@ -115,16 +133,42 @@ const solveLineLogic = (lineState, hints) => {
|
||||
return result;
|
||||
}
|
||||
const len = hints[hintCount - 1];
|
||||
const maxStart = pos - len;
|
||||
|
||||
// Logic for prefix:
|
||||
// We are placing the (hintCount-1)-th block ending at 'start + len' <= pos.
|
||||
// So 'start' <= pos - len.
|
||||
// But we also need to ensure there is space for previous blocks.
|
||||
// However, the simple constraint is just iterating backwards.
|
||||
|
||||
// maxStart: if this is the only block, maxStart = pos - len.
|
||||
// If there are previous blocks, we need a gap before this block.
|
||||
// So previous block ended at start - 1.
|
||||
// Actually the recursive call will handle space check.
|
||||
// But for the gap check:
|
||||
// If we place block at 'start', we need lineState[start-1] != 1 (if start > 0).
|
||||
// And we recursively check canPlacePrefix(start-1, count-1).
|
||||
// But if start=0 and count > 1, impossible.
|
||||
|
||||
const maxStart = pos - len; // Simplified, loop condition handles rest
|
||||
|
||||
for (let start = maxStart; start >= 0; start--) {
|
||||
if (hasCross(start, start + len)) continue;
|
||||
if (start + len < pos && lineState[start + len] === 1) continue;
|
||||
if (hasFilled(start + len, pos)) continue;
|
||||
if (start > 0 && lineState[start - 1] === 1) continue;
|
||||
const prevPos = start > 0 ? start - 1 : 0;
|
||||
if (canPlacePrefix(prevPos, hintCount - 1)) {
|
||||
memoPrefix[pos][hintCount] = true;
|
||||
return true;
|
||||
if (hasFilled(start + len, pos)) continue; // Must be empty after this block up to pos
|
||||
|
||||
// Check gap before
|
||||
if (hintCount > 1) {
|
||||
if (start === 0) continue; // No space for previous blocks
|
||||
if (lineState[start - 1] === 1) continue; // Gap must not be filled
|
||||
const prevPos = start - 1;
|
||||
if (canPlacePrefix(prevPos, hintCount - 1)) {
|
||||
memoPrefix[pos][hintCount] = true;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// First block
|
||||
if (hasFilled(0, start)) continue; // Before first block must be empty
|
||||
memoPrefix[pos][hintCount] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
memoPrefix[pos][hintCount] = false;
|
||||
@@ -136,7 +180,14 @@ const solveLineLogic = (lineState, hints) => {
|
||||
const len = hints[i];
|
||||
const starts = [];
|
||||
for (let start = 0; start <= n - len; start++) {
|
||||
if (!canPlacePrefix(start, i)) continue;
|
||||
if (i === 0) {
|
||||
if (!canPlacePrefix(start, 0)) continue;
|
||||
} else {
|
||||
if (start === 0) continue;
|
||||
if (lineState[start - 1] === 1) continue;
|
||||
if (!canPlacePrefix(start - 1, i)) continue;
|
||||
}
|
||||
|
||||
if (hasCross(start, start + len)) continue;
|
||||
if (start + len < n && lineState[start + len] === 1) continue;
|
||||
const nextPos = start + len < n ? start + len + 1 : start + len;
|
||||
@@ -236,29 +287,9 @@ const handleStep = (playerGrid, solution, locale) => {
|
||||
}
|
||||
}
|
||||
|
||||
for (let r = 0; r < size; r++) {
|
||||
for (let c = 0; c < size; c++) {
|
||||
const current = playerGrid[r][c];
|
||||
const target = solution[r][c];
|
||||
let isCorrect = false;
|
||||
if (target === 1 && current === 1) isCorrect = true;
|
||||
if (target === 0 && current === 2) isCorrect = true;
|
||||
if (target === 0 && current === 0) isCorrect = false;
|
||||
if (target === 1 && current === 0) isCorrect = false;
|
||||
if (!isCorrect) {
|
||||
const newState = target === 1 ? 1 : 2;
|
||||
return {
|
||||
type: 'move',
|
||||
r,
|
||||
c,
|
||||
state: newState,
|
||||
statusText: t(locale, 'worker.guess', { row: r + 1, col: c + 1 })
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { type: 'done', statusText: t(locale, 'worker.done') };
|
||||
// Check for guess logic - we want to avoid this unless strictly necessary
|
||||
// If no logic move found, return 'stuck' instead of cheating
|
||||
return { type: 'stuck', statusText: t(locale, 'worker.stuck') };
|
||||
};
|
||||
|
||||
self.onmessage = (event) => {
|
||||
|
||||
Reference in New Issue
Block a user