Skip to content

Commit ea81b54

Browse files
snow-jallenclaude
andcommitted
Pick-up: card rows scroll with a mouse (wheel, or drag); the Pick-up Game link shows only in the phone-size menu
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V8fdNFMnkyDNTFoKqQyD6L
1 parent 1fbf021 commit ea81b54

5 files changed

Lines changed: 56 additions & 3 deletions

File tree

‎src/NetRts.Server/wwwroot/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<a href="#/recaps" data-section="recaps">Recaps</a>
5353
<a href="#/achievements" data-section="achievements">Achievements</a>
5454
<a href="#/blocks" data-section="blocks">Block Bot</a>
55-
<a href="#/pickup" data-section="pickup">Pick-up Game</a>
55+
<a href="#/pickup" data-section="pickup" class="nav-phone-only">Pick-up Game</a>
5656
<a href="#/stats" data-section="stats">Stats</a>
5757
<a href="#/api" data-section="api">API</a>
5858
<a class="gh-link" href="https://github.com/SnowSE/NetRTS" target="_blank" rel="noopener" title="Source on GitHub"><svg viewBox="0 0 16 16" width="20" height="20" aria-hidden="true" focusable="false"><path fill="currentColor" d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"/></svg><span class="gh-text">GitHub</span></a>

‎src/NetRts.Server/wwwroot/pickup/deck.js‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,48 @@ export function dragToReorder(root, scope, onMove) {
282282
scope.on(document, 'pointercancel', end);
283283
return () => { const was = eatClick; eatClick = false; return was; };
284284
}
285+
286+
/**
287+
* The hands of cards scroll sideways with a mouse too: the wheel scrolls the row under the pointer (until
288+
* it reaches an end, then the page scrolls on), and a mouse can drag the row. Touch already swipes it.
289+
* Returns eat(): true once just after a drag, so the click that ends it doesn't also play a card.
290+
*/
291+
export function mouseScroll(root, scope) {
292+
let D = null, eatClick = false;
293+
scope.on(root, 'wheel', (e) => {
294+
const row = e.target.closest('.hand');
295+
if (!row || e.ctrlKey || Math.abs(e.deltaY) <= Math.abs(e.deltaX)) return;
296+
const room = row.scrollWidth - row.clientWidth;
297+
if (room <= 0 || (e.deltaY < 0 && row.scrollLeft <= 0) || (e.deltaY > 0 && row.scrollLeft >= room - 1)) return;
298+
e.preventDefault();
299+
row.scrollLeft += e.deltaY;
300+
}, { passive: false });
301+
scope.on(root, 'pointerdown', (e) => {
302+
const row = e.target.closest('.hand');
303+
if (!row || e.pointerType !== 'mouse' || e.button !== 0 || row.scrollWidth <= row.clientWidth) return;
304+
D = { row, x: e.clientX, left: row.scrollLeft, moved: false, id: e.pointerId };
305+
});
306+
scope.on(document, 'pointermove', (e) => {
307+
if (!D || e.pointerId !== D.id) return;
308+
const dx = e.clientX - D.x;
309+
if (!D.moved) {
310+
if (Math.abs(dx) < 6) return;
311+
D.moved = true;
312+
D.row.classList.add('grabbing'); // snapping off while it's held, so it follows the mouse
313+
}
314+
e.preventDefault();
315+
D.row.scrollLeft = D.left - dx;
316+
});
317+
const end = (e) => {
318+
if (!D || e.pointerId !== D.id) return;
319+
const d = D;
320+
D = null;
321+
if (!d.moved) return;
322+
d.row.classList.remove('grabbing');
323+
eatClick = true;
324+
scope.later(() => { eatClick = false; }, 80);
325+
};
326+
scope.on(document, 'pointerup', end);
327+
scope.on(document, 'pointercancel', end);
328+
return () => { const was = eatClick; eatClick = false; return was; };
329+
}

‎src/NetRts.Server/wwwroot/pickup/index.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { api, esc, mountScope, setTitle } from '../util.js';
1212
import { load, save } from '../storage.js';
1313
import { takePage } from './page.js';
1414
import { createSheets } from './sheets.js';
15-
import { createDeck, dragToReorder } from './deck.js';
15+
import { createDeck, dragToReorder, mouseScroll } from './deck.js';
1616
import { mountPlaying } from './playing.js';
1717
import { overHTML } from './over.js';
1818
import { setCatalog, normalize, left, clock, ordinal, samePlan } from './items.js';
@@ -65,7 +65,9 @@ export function mountPickup(main) {
6565
live: () => (liveEdit && me?.phase === 'playing' ? { step: me.step ?? 0 } : null),
6666
sheets,
6767
});
68-
const eatClick = dragToReorder(root, scope, (kind, from, to) => deck.move(kind, from, to));
68+
const eatDrag = dragToReorder(root, scope, (kind, from, to) => deck.move(kind, from, to));
69+
const eatScroll = mouseScroll(root, scope);
70+
const eatClick = () => eatDrag() | eatScroll(); // both, so neither keeps a stale true
6971
scope.cleanup(() => playing?.dispose());
7072

7173
// ---- talking to the server

‎src/NetRts.Server/wwwroot/pickup/pickup.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ main.pk-main { max-width: none; padding: 0; }
9292
.p-cards .hand-h { font: 700 11px var(--pk-font); text-transform: uppercase; letter-spacing: .1em; color: var(--sub); margin: 16px 16px 8px; }
9393
.p-cards .hand { display: flex; gap: 10px; overflow-x: auto; padding: 4px 16px 12px; scroll-snap-type: x proximity; scrollbar-width: none;
9494
-webkit-mask-image: linear-gradient(90deg, #000 82%, transparent); mask-image: linear-gradient(90deg, #000 82%, transparent); }
95+
/* With a mouse the row drags sideways; snapping waits until it's let go. */
96+
@media (hover: hover) and (pointer: fine) { .p-cards .hand { cursor: grab; } }
97+
.p-cards .hand.grabbing { cursor: grabbing; scroll-snap-type: none; user-select: none; }
98+
.p-cards .hand.grabbing .card { cursor: grabbing; }
9599
.p-cards .card { flex: none; width: 128px; height: 218px; border-radius: 6px; border: 2px solid var(--pk-ink); background: #fff; color: var(--pk-ink);
96100
position: relative; display: flex; flex-direction: column; align-items: stretch; padding: 5px; gap: 4px; cursor: pointer;
97101
scroll-snap-align: start; font: inherit; text-align: center; }

‎src/NetRts.Server/wwwroot/styles.css‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,8 @@ html.map-full { overflow: hidden; }
13121312
.avatar { border-radius: 50%; vertical-align: middle; margin-right: 6px; }
13131313
.avatar.big { margin: 0; }
13141314
.topbar nav a.account-link { display: inline-flex; align-items: center; }
1315+
/* The Pick-up Game is played on phones: its link shows only in the folded (☰) menu. */
1316+
@media (min-width: 1061px) { .topbar nav a.nav-phone-only { display: none; } }
13151317
/* GitHub: the logo in the bar (its name for screen readers); logo and name in the folded menu. */
13161318
.topbar nav a.gh-link { display: inline-flex; align-items: center; gap: 8px; }
13171319
.topbar nav a.gh-link svg { display: block; }

0 commit comments

Comments
 (0)