Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5549e24c17 | |||
| ca3193d07e | |||
| 41a36768cd | |||
| 315fb29eac | |||
| 395e9caff4 | |||
| e1c73181d4 | |||
| 874e35bba3 | |||
| 69b04d3336 | |||
| c5b212234a | |||
| 8e0ddf3a72 | |||
| bfb24cfb03 | |||
| 8d3bde8d38 | |||
| d25fa67100 | |||
| c7834bd8bf | |||
| 7d405ef0f6 | |||
| 431b534477 | |||
| ebf9030185 | |||
| 8f52f5daa5 | |||
| 2dc68ab8d0 | |||
| 993ced424e | |||
| 1b0b6a671a | |||
| e39ac9a794 |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "vue-nonograms-solid",
|
||||
"version": "1.0.2",
|
||||
"version": "1.5.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "vue-nonograms-solid",
|
||||
"version": "1.0.2",
|
||||
"version": "1.5.0",
|
||||
"dependencies": {
|
||||
"fireworks-js": "^2.10.8",
|
||||
"flag-icons": "^7.5.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue-nonograms-solid",
|
||||
"version": "1.0.2",
|
||||
"version": "1.5.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -9,6 +9,7 @@ import GuidePanel from './components/GuidePanel.vue';
|
||||
import WinModal from './components/WinModal.vue';
|
||||
import CustomGameModal from './components/CustomGameModal.vue';
|
||||
import FixedBar from './components/FixedBar.vue';
|
||||
import ReloadPrompt from './components/ReloadPrompt.vue';
|
||||
|
||||
// Main App Entry
|
||||
const store = usePuzzleStore();
|
||||
@@ -173,6 +174,7 @@ onUnmounted(() => {
|
||||
<Teleport to="body">
|
||||
<WinModal v-if="store.isGameWon" />
|
||||
<CustomGameModal v-if="showCustomModal" @close="showCustomModal = false" />
|
||||
<ReloadPrompt />
|
||||
</Teleport>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { ref, computed } from 'vue';
|
||||
import { usePuzzleStore } from '@/stores/puzzle';
|
||||
import { useI18n } from '@/composables/useI18n';
|
||||
import { calculateDifficulty } from '@/utils/puzzleUtils';
|
||||
|
||||
const emit = defineEmits(['close']);
|
||||
const store = usePuzzleStore();
|
||||
const { t } = useI18n();
|
||||
|
||||
const customSize = ref(10);
|
||||
const fillRate = ref(50);
|
||||
const errorMsg = ref('');
|
||||
|
||||
const snapToStep = (value, step) => {
|
||||
@@ -19,6 +21,20 @@ const handleSnap = () => {
|
||||
customSize.value = snapToStep(Number(customSize.value), 5);
|
||||
};
|
||||
|
||||
const difficultyLevel = computed(() => {
|
||||
return calculateDifficulty(fillRate.value / 100);
|
||||
});
|
||||
|
||||
const difficultyColor = computed(() => {
|
||||
switch(difficultyLevel.value) {
|
||||
case 'extreme': return '#ff3333';
|
||||
case 'hardest': return '#ff9933';
|
||||
case 'harder': return '#ffff33';
|
||||
case 'easy': return '#33ff33';
|
||||
default: return '#33ff33';
|
||||
}
|
||||
});
|
||||
|
||||
const confirm = () => {
|
||||
const size = parseInt(customSize.value);
|
||||
if (isNaN(size) || size < 5 || size > 80) {
|
||||
@@ -26,7 +42,7 @@ const confirm = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
store.initCustomGame(size);
|
||||
store.initCustomGame(size, fillRate.value / 100);
|
||||
emit('close');
|
||||
};
|
||||
</script>
|
||||
@@ -52,6 +68,29 @@ const confirm = () => {
|
||||
<span>80</span>
|
||||
</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>
|
||||
</div>
|
||||
|
||||
<div class="difficulty-indicator">
|
||||
<span class="label">{{ t('custom.difficulty') }}:</span>
|
||||
<span class="value" :style="{ color: difficultyColor }">
|
||||
{{ t(`difficulty.${difficultyLevel}`) }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<p v-if="errorMsg" class="error">{{ errorMsg }}</p>
|
||||
|
||||
@@ -87,6 +126,7 @@ const confirm = () => {
|
||||
border: 1px solid var(--accent-cyan);
|
||||
box-shadow: 0 0 50px rgba(0, 242, 255, 0.2);
|
||||
animation: slideUp 0.3s ease;
|
||||
transition: all 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
h2 {
|
||||
@@ -161,6 +201,31 @@ input[type="range"]::-moz-range-thumb {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.difficulty-indicator {
|
||||
margin: 20px 0;
|
||||
font-size: 1.2rem;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
height: 1.5em; /* Reserve space for one line of text */
|
||||
}
|
||||
|
||||
.difficulty-indicator .label {
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.difficulty-indicator .value {
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
text-shadow: 0 0 10px currentColor;
|
||||
transition: color 0.3s ease;
|
||||
display: inline-block;
|
||||
min-width: 120px; /* Reserve space for longest text */
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #ff4d4d;
|
||||
font-size: 0.9rem;
|
||||
|
||||
110
src/components/ReloadPrompt.vue
Normal file
110
src/components/ReloadPrompt.vue
Normal file
@@ -0,0 +1,110 @@
|
||||
<script setup>
|
||||
import { useRegisterSW } from 'virtual:pwa-register/vue'
|
||||
import { useI18n } from '@/composables/useI18n'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const {
|
||||
offlineReady,
|
||||
needRefresh,
|
||||
updateServiceWorker,
|
||||
} = useRegisterSW()
|
||||
|
||||
const close = async () => {
|
||||
offlineReady.value = false
|
||||
needRefresh.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="offlineReady || needRefresh"
|
||||
class="pwa-toast"
|
||||
role="alert"
|
||||
>
|
||||
<div class="message">
|
||||
<span v-if="offlineReady">
|
||||
{{ t('pwa.offlineReady') }}
|
||||
</span>
|
||||
<span v-else>
|
||||
{{ t('pwa.newContent') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<button v-if="needRefresh" class="btn-neon small" @click="updateServiceWorker()">
|
||||
{{ t('pwa.reload') }}
|
||||
</button>
|
||||
<button class="close-btn" @click="close">
|
||||
{{ t('pwa.close') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.pwa-toast {
|
||||
position: fixed;
|
||||
right: 0;
|
||||
bottom: 60px; /* Above the footer */
|
||||
margin: 16px;
|
||||
padding: 15px;
|
||||
border: 1px solid var(--banner-border);
|
||||
background: var(--banner-bg);
|
||||
border-radius: 12px;
|
||||
z-index: 2000;
|
||||
text-align: left;
|
||||
box-shadow: var(--banner-shadow);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
backdrop-filter: blur(10px);
|
||||
color: var(--text-color);
|
||||
max-width: 320px;
|
||||
animation: slideIn 0.3s ease-out;
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
transform: translateY(20px);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translateY(0);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.message {
|
||||
font-size: 0.95rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
background: transparent;
|
||||
border: 1px solid var(--text-muted);
|
||||
color: var(--text-muted);
|
||||
padding: 6px 12px;
|
||||
border-radius: 20px;
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.close-btn:hover {
|
||||
border-color: var(--text-color);
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.btn-neon.small {
|
||||
padding: 6px 16px;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
</style>
|
||||
@@ -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 } from 'lucide-vue-next';
|
||||
import { calculateDifficulty } from '@/utils/puzzleUtils';
|
||||
|
||||
const store = usePuzzleStore();
|
||||
const { t } = useI18n();
|
||||
@@ -88,8 +87,9 @@ const buildShareCanvas = () => {
|
||||
const padding = 28;
|
||||
const headerHeight = 64;
|
||||
const footerHeight = 28;
|
||||
const infoHeight = 40; // New space for difficulty/guide info
|
||||
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 canvas = document.createElement('canvas');
|
||||
canvas.width = width * scale;
|
||||
@@ -109,6 +109,24 @@ const buildShareCanvas = () => {
|
||||
ctx.fillText(t('app.title'), padding, padding + 10);
|
||||
ctx.font = '600 16px "Segoe UI", sans-serif';
|
||||
ctx.fillText(`${t('win.time')} ${formattedTime.value}`, padding, padding + 34);
|
||||
|
||||
// Difficulty & Density Info
|
||||
const densityPercent = Math.round(store.currentDensity * 100);
|
||||
const difficultyKey = calculateDifficulty(store.currentDensity);
|
||||
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}`);
|
||||
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 gridY = padding + headerHeight;
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.06)';
|
||||
@@ -152,6 +170,19 @@ const buildShareCanvas = () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Guide Usage Info (Dirty Flag)
|
||||
if (store.guideUsageCount > 0) {
|
||||
ctx.fillStyle = '#ff4d4d';
|
||||
ctx.font = '600 14px "Segoe UI", sans-serif';
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.75)';
|
||||
ctx.font = '500 14px "Segoe UI", sans-serif';
|
||||
ctx.fillText(appUrl, padding, height - padding + 6);
|
||||
@@ -183,7 +214,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}`;
|
||||
@@ -197,29 +228,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(() => {
|
||||
@@ -279,19 +329,23 @@ 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>
|
||||
</div>
|
||||
<button class="btn-neon secondary share-download" :disabled="shareInProgress" @click="downloadShareImage">
|
||||
{{ t('win.shareDownload') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
}
|
||||
|
||||
20
src/main.js
20
src/main.js
@@ -31,23 +31,3 @@ app.directive('cell-hover', vCellHover)
|
||||
|
||||
app.mount('#app')
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
let refreshing = false
|
||||
const triggerReload = () => {
|
||||
if (refreshing) return
|
||||
refreshing = true
|
||||
window.location.reload()
|
||||
}
|
||||
navigator.serviceWorker.addEventListener('controllerchange', triggerReload)
|
||||
const checkForUpdate = () => {
|
||||
navigator.serviceWorker.getRegistration().then((registration) => {
|
||||
if (registration) {
|
||||
registration.update()
|
||||
}
|
||||
})
|
||||
}
|
||||
window.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState === 'visible') checkForUpdate()
|
||||
})
|
||||
window.addEventListener('focus', checkForUpdate)
|
||||
}
|
||||
|
||||
@@ -64,6 +64,9 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
||||
const playerGrid = ref([]); // 0: empty, 1: filled, 2: cross
|
||||
const isGameWon = 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 startTime = ref(null);
|
||||
const elapsedTime = ref(0);
|
||||
@@ -118,23 +121,29 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
||||
resetGrid();
|
||||
isGameWon.value = false;
|
||||
hasUsedGuide.value = false;
|
||||
guideUsageCount.value = 0;
|
||||
currentDensity.value = totalCellsToFill.value / (size.value * size.value);
|
||||
elapsedTime.value = 0;
|
||||
startTimer();
|
||||
saveState();
|
||||
}
|
||||
|
||||
function initCustomGame(customSize) {
|
||||
function initCustomGame(customSize, density = 0.5) {
|
||||
stopTimer();
|
||||
currentLevelId.value = 'custom';
|
||||
size.value = customSize;
|
||||
|
||||
// Generate random grid
|
||||
solution.value = generateRandomGrid(customSize);
|
||||
solution.value = generateRandomGrid(customSize, density);
|
||||
|
||||
resetGrid();
|
||||
isGameWon.value = false;
|
||||
hasUsedGuide.value = false;
|
||||
guideUsageCount.value = 0;
|
||||
currentDensity.value = density;
|
||||
elapsedTime.value = 0;
|
||||
startTimer();
|
||||
saveState();
|
||||
}
|
||||
|
||||
function resetGrid() {
|
||||
@@ -242,6 +251,8 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
||||
playerGrid: playerGrid.value,
|
||||
isGameWon: isGameWon.value,
|
||||
hasUsedGuide: hasUsedGuide.value,
|
||||
guideUsageCount: guideUsageCount.value,
|
||||
currentDensity: currentDensity.value,
|
||||
elapsedTime: elapsedTime.value,
|
||||
moves: moves.value,
|
||||
history: history.value
|
||||
@@ -259,6 +270,9 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
||||
solution.value = parsed.solution;
|
||||
playerGrid.value = parsed.playerGrid;
|
||||
isGameWon.value = parsed.isGameWon;
|
||||
hasUsedGuide.value = parsed.hasUsedGuide || false;
|
||||
guideUsageCount.value = parsed.guideUsageCount || 0;
|
||||
currentDensity.value = parsed.currentDensity || 0;
|
||||
elapsedTime.value = parsed.elapsedTime || 0;
|
||||
moves.value = parsed.moves || 0;
|
||||
history.value = parsed.history || [];
|
||||
@@ -275,44 +289,9 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
||||
return false;
|
||||
}
|
||||
|
||||
function initGame(levelId = 'easy') {
|
||||
// If init called without args and we have save, load it?
|
||||
// User might want to start fresh if clicking buttons.
|
||||
// Let's add explicit 'continue' logic or just auto-load on first run.
|
||||
// For now, let's just stick to explicit init, but maybe load on mount if exists?
|
||||
// The user didn't explicitly ask for "Continue", but "features from HTML".
|
||||
// HTML usually auto-saves and loads.
|
||||
|
||||
stopTimer();
|
||||
currentLevelId.value = levelId;
|
||||
|
||||
let puzzle = PUZZLES[levelId];
|
||||
if (!puzzle) {
|
||||
puzzle = PUZZLES['easy'];
|
||||
}
|
||||
|
||||
size.value = puzzle.size;
|
||||
solution.value = puzzle.grid;
|
||||
|
||||
resetGrid();
|
||||
isGameWon.value = false;
|
||||
elapsedTime.value = 0;
|
||||
startTimer();
|
||||
saveState();
|
||||
}
|
||||
// Duplicate initGame removed
|
||||
|
||||
// Modify initCustomGame similarly
|
||||
function initCustomGame(customSize) {
|
||||
stopTimer();
|
||||
currentLevelId.value = 'custom';
|
||||
size.value = customSize;
|
||||
solution.value = generateRandomGrid(customSize);
|
||||
resetGrid();
|
||||
isGameWon.value = false;
|
||||
elapsedTime.value = 0;
|
||||
startTimer();
|
||||
saveState();
|
||||
}
|
||||
// Duplicate initCustomGame removed
|
||||
|
||||
// Duplicate toggleCell/setCell removed
|
||||
|
||||
@@ -321,6 +300,7 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
||||
resetGrid();
|
||||
isGameWon.value = false;
|
||||
hasUsedGuide.value = false;
|
||||
guideUsageCount.value = 0;
|
||||
elapsedTime.value = 0;
|
||||
startTimer();
|
||||
saveState();
|
||||
@@ -332,6 +312,7 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
||||
function markGuideUsed() {
|
||||
if (isGameWon.value) return;
|
||||
hasUsedGuide.value = true;
|
||||
guideUsageCount.value++;
|
||||
saveState();
|
||||
}
|
||||
|
||||
@@ -360,6 +341,8 @@ export const usePuzzleStore = defineStore('puzzle', () => {
|
||||
undo,
|
||||
closeWinModal,
|
||||
hasUsedGuide,
|
||||
guideUsageCount,
|
||||
currentDensity,
|
||||
markGuideUsed
|
||||
};
|
||||
|
||||
|
||||
@@ -40,15 +40,36 @@ export function calculateHints(grid) {
|
||||
return { rowHints, colHints };
|
||||
}
|
||||
|
||||
export function generateRandomGrid(size) {
|
||||
export function generateRandomGrid(size, density = 0.5) {
|
||||
const grid = [];
|
||||
for (let i = 0; i < size; i++) {
|
||||
const row = [];
|
||||
for (let j = 0; j < size; j++) {
|
||||
// ~25% empty cells
|
||||
row.push(Math.random() > 0.25 ? 1 : 0);
|
||||
row.push(Math.random() < density ? 1 : 0);
|
||||
}
|
||||
grid.push(row);
|
||||
}
|
||||
return grid;
|
||||
}
|
||||
|
||||
export function calculateDifficulty(density) {
|
||||
// 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 'easy';
|
||||
|
||||
const entropy = -density * Math.log2(density) - (1 - density) * Math.log2(1 - density);
|
||||
|
||||
// Thresholds based on entropy
|
||||
// 0.5 density -> entropy 1.0 (Extreme)
|
||||
// 0.4/0.6 density -> entropy ~0.97 (Extreme)
|
||||
// 0.3/0.7 density -> entropy ~0.88 (Hardest)
|
||||
// 0.2/0.8 density -> entropy ~0.72 (Harder)
|
||||
// <0.2/>0.8 density -> entropy <0.72 (Easy)
|
||||
|
||||
if (entropy >= 0.96) return 'extreme'; // approx 38% - 62%
|
||||
if (entropy >= 0.85) return 'hardest'; // approx 28% - 38% & 62% - 72%
|
||||
if (entropy >= 0.65) return 'harder'; // approx 17% - 28% & 72% - 83%
|
||||
return 'easy';
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
@@ -236,29 +236,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) => {
|
||||
|
||||
@@ -10,12 +10,11 @@ export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
VitePWA({
|
||||
registerType: 'autoUpdate',
|
||||
registerType: 'prompt',
|
||||
injectRegister: 'auto',
|
||||
workbox: {
|
||||
cleanupOutdatedCaches: true,
|
||||
skipWaiting: true,
|
||||
clientsClaim: true,
|
||||
globPatterns: ['**/*.{js,css,html,ico,png,svg,json,vue,txt,woff2}']
|
||||
},
|
||||
devOptions: {
|
||||
enabled: true
|
||||
|
||||
Reference in New Issue
Block a user