[+] Mobile

This commit is contained in:
2024-12-17 02:17:45 -05:00
parent 1c77281756
commit 6d4e8e4438
3 changed files with 20 additions and 7 deletions
+11 -4
View File
@@ -2,11 +2,12 @@
import svelteLogo from './assets/svelte.svg'
import viteLogo from '/vite.svg'
import Number from './lib/Number.svelte'
import { cfg, eStates, Fmt, JsonTy, nStates, randInt, range, zero8, type Checkpoint, type i8s } from "./utils";
import { cfg, eStates, Fmt, JsonTy, Misc, nStates, randInt, range, zero8, type Checkpoint, type i8s } from "./utils";
import Line from "./lib/Line.svelte";
import { solve } from "./solver";
const params = new URLSearchParams(location.search)
const hasTouch = Misc.hasTouch()
// Can pass in puzzle data from props
interface Props { puzzleId?: string, puzzleData?: Checkpoint }
@@ -155,15 +156,21 @@
const idx = (sy + osy) * eCols + (sx + osx)
// Flip the state of the edge
const state = event.type === 'contextmenu' ? 2 : 1
if (color) {
if (vertical) vColors[idx] = ci
else hColors[idx] = ci
}
else {
else if (!hasTouch) {
// Mouse is accurate, so right click to cross, left click to select
const state = event.type === 'contextmenu' ? 2 : 1
if (vertical) vStates[idx] = vStates[idx] % 3 !== state ? state : 0
else hStates[idx] = hStates[idx] % 3 !== state ? state : 0
}
else {
// Touch is not accurate, click once to select, click again to cross, click again to clear
if (vertical) vStates[idx] = (vStates[idx] + 1) % 3
else hStates[idx] = (hStates[idx] + 1) % 3
}
// Check the validity of the clicked cell and its neighbors (check 5x5 but clean only 3x3)
updateArea.forEach(([dx, dy, outer]) => outer ? 0 : clearAutoMark(sx + dx, sy + dy))
@@ -269,7 +276,7 @@
}
</script>
<main class:color-mode={mode === 'color'} class:colorful-cross={colorfulCross}>
<main class:color-mode={mode === 'color'} class:colorful-cross={colorfulCross} class:mobile={hasTouch}>
<div class="heading">Azalea's Colorful Slither Link</div>
<div class="sub-heading">
<img src={viteLogo} alt="Logo"/>
+4 -3
View File
@@ -7,6 +7,7 @@
margin: 1em auto
position: relative
user-select: none
touch-action: manipulation
.grid-number
position: absolute
@@ -52,9 +53,9 @@
position: absolute
top: -7px
&:hover
background: var(--c)
opacity: 0.5
main:not(.mobile) .grid-line:hover
background: var(--c)
opacity: 0.5
.color-mode .grid-line:not(.selected):not(.crossed):not(.auto-crossed)
background: var(--c)
+5
View File
@@ -77,3 +77,8 @@ export const Backend = {
}).then(JsonTy.parse),
post: (data: Checkpoint) => fetch(`${cfg.backend}/`, { method: "post", body: JsonTy.stringify(data) }),
}
export const Misc = {
// @ts-ignore
hasTouch: () => 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0
}