Phone UI and touch precision overhaul, proxy fixes, Orbital Uplink, four new maps
Phone panels (reviewed + QA'd, matrix of 22 layouts with real taps/bounding boxes): - selected-tower action bar over the board (Upgrade/Sell/Target/close), info panel updated in place so taps are never lost, scrollable palette for 7+ towers, overlays with pinned footers (Help "Got it", Play solo, Join always visible), tappable room chip to invite, reduced-motion/contrast/forced-colors fixes, paused state, partner cursor labels, bigger level pips and owner flags - touch input rewritten around "pointerdown commits nothing": pinch never builds, 10px tap slop, palm-proof pinch, long-press pings with any tool armed, nudge arrows for precise placement, hotkey repeat guard, proportional wheel zoom - new e2e: select/sell, info-panel stability, UI states, touch precision; camera unit tests Proxy/server (reproduced against real nginx 1.26 with NPM v2.16 config): - Origin check works when the proxy drops a non-default port, TRUSTED_PROXIES for proxies on global IPv6/CGNAT addresses, service worker no longer serves nginx's 502 page, DEPLOY.md corrected (NPM default read timeout is 90 s, Advanced-tab limits, path-prefix, cookie size, per-IP cap behaviour) Content: - Orbital Uplink: 4-level endgame tower (450 + 500/800/1200 credits): piercing armour-ignoring beam, blast and lingering slow, ground+air, range 11-14; glyph, beam effect, sound, help text, unit tests - Maps: The Canyon, Archipelago, Fortress, Pinwheel (7 maps total) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
This commit is contained in:
parent
dad0382e10
commit
a5bd09d505
22 changed files with 2423 additions and 405 deletions
|
|
@ -1,11 +1,20 @@
|
|||
/* Netwall - styles. Dark "network operations" theme. Mobile-first: portrait phones, landscape phones, desktop. */
|
||||
/* Netwall - styles. Dark "network operations" theme. Mobile-first: portrait phones, landscape phones, desktop.
|
||||
*
|
||||
* Layout modes (see main.js layoutApp for the JS half):
|
||||
* wide stage | side panel (320px). Desktop and tablets in landscape. Tower actions live in the side panel.
|
||||
* stacked top bar / stage / side panel. Portrait phones and narrow windows: (orientation: portrait), (max-width: 760px) and (min-height: 521px)
|
||||
* short stage | narrow side panel, one-row top bar. Landscape phones: (orientation: landscape) and (max-height: 520px)
|
||||
* compact #app[data-ui="compact"]: stacked OR short OR a coarse pointer. Here the selected tower's actions float over the
|
||||
* stage as a bar (placed on the half of the stage away from the tower), and every target is at least 44px.
|
||||
* Everything that has to be reachable (primary buttons, tower actions, room code) is positioned, never scrolled to.
|
||||
*/
|
||||
:root {
|
||||
--bg: #070b16;
|
||||
--panel: #0c1322;
|
||||
--panel2: #111b30;
|
||||
--line: #1d2c4c;
|
||||
--text: #d3e6ff;
|
||||
--dim: #7f97bd;
|
||||
--dim: #8ea6cc;
|
||||
--cyan: #4de3ff;
|
||||
--amber: #ffd24d;
|
||||
--red: #ff5c7a;
|
||||
|
|
@ -16,11 +25,13 @@
|
|||
--safe-b: env(safe-area-inset-bottom, 0px);
|
||||
--safe-l: env(safe-area-inset-left, 0px);
|
||||
--btn: 40px;
|
||||
--tile-h: 66px;
|
||||
--bar-h: 54px;
|
||||
--nudge-h: 52px; /* the build bar is this much taller than the tower bar: it has a row of nudge buttons */
|
||||
--aspect: 26 / 16;
|
||||
--font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
|
||||
}
|
||||
@media (pointer: coarse) { :root { --btn: 46px; } }
|
||||
|
||||
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
|
||||
html, body {
|
||||
|
|
@ -40,7 +51,7 @@ svg.ic { width: 1.25em; height: 1.25em; flex: none; }
|
|||
grid-template-columns: minmax(0, 1fr) var(--side-w);
|
||||
grid-template-rows: auto minmax(0, 1fr);
|
||||
grid-template-areas: "top top" "stage side";
|
||||
padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
|
||||
padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); /* the one place the safe-area insets are applied */
|
||||
background:
|
||||
radial-gradient(1200px 600px at 20% -10%, #0f1f3d 0%, transparent 60%),
|
||||
radial-gradient(900px 500px at 100% 110%, #1b1035 0%, transparent 55%), var(--bg);
|
||||
|
|
@ -48,18 +59,19 @@ svg.ic { width: 1.25em; height: 1.25em; flex: none; }
|
|||
#topbar { grid-area: top; display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; padding: 6px 10px; background: rgba(8, 13, 26, .85); border-bottom: 1px solid var(--line); }
|
||||
#stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; overflow: hidden; touch-action: none; }
|
||||
#side > * { flex: none; }
|
||||
#side { grid-area: side; display: flex; flex-direction: column; gap: 10px; padding: 10px; overflow-y: auto; border-left: 1px solid var(--line); background: rgba(8, 13, 26, .7); -webkit-overflow-scrolling: touch; }
|
||||
/* (no transform / filter / mask / contain on #side or #info: the tower action bar is position:fixed inside them) */
|
||||
#side { grid-area: side; display: flex; flex-direction: column; gap: 10px; padding: 10px; overflow-y: auto; border-left: 1px solid var(--line); background: rgba(8, 13, 26, .7); }
|
||||
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
|
||||
|
||||
/* portrait phones / narrow windows: board on top, panels underneath */
|
||||
/* stacked: portrait phones and narrow windows. main.js sets --stage-h so the stage hugs the board (no dead bands) and the side panel gets the rest */
|
||||
@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) {
|
||||
#app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); grid-template-areas: "top" "stage" "side"; }
|
||||
#stage { aspect-ratio: var(--aspect-p, 16 / 26); max-height: 58dvh; width: 100%; }
|
||||
#side { border-left: 0; border-top: 1px solid var(--line); padding: 8px 10px calc(8px + var(--safe-b)); gap: 8px; }
|
||||
#app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto var(--stage-h, 56dvh) minmax(0, 1fr); grid-template-areas: "top" "stage" "side"; }
|
||||
#stage { width: 100%; }
|
||||
#side { border-left: 0; border-top: 1px solid var(--line); padding: 0 10px 8px; gap: 8px; }
|
||||
}
|
||||
/* landscape phones: short viewport, narrow side panel */
|
||||
@media (orientation: landscape) and (max-height: 520px) {
|
||||
:root { --side-w: 236px; --btn: 40px; }
|
||||
:root { --side-w: 236px; --btn: 40px; --tile-h: 58px; }
|
||||
#topbar { padding: 3px 8px; gap: 4px 6px; flex-wrap: nowrap; }
|
||||
#side { gap: 6px; padding: 6px; }
|
||||
}
|
||||
|
|
@ -72,82 +84,139 @@ svg.ic { width: 1.25em; height: 1.25em; flex: none; }
|
|||
.stat .lbl { color: var(--dim); font-size: 11px; letter-spacing: .12em; }
|
||||
#statLives { color: var(--red); }
|
||||
#statGold { color: var(--amber); }
|
||||
#statLives.low { animation: pulse 0.8s infinite; }
|
||||
@keyframes pulse { 50% { background: #3a1020; } }
|
||||
#statLives.low { border-color: var(--red); box-shadow: 0 0 0 2px rgba(255, 92, 122, .35); background: #2a0e18; animation: pulse 0.8s infinite; } /* static cue first, the pulse is extra */
|
||||
@keyframes pulse { 50% { background: #4a1426; } }
|
||||
.spacer { flex: 1 1 8px; }
|
||||
.chip { display: flex; align-items: center; gap: 6px; padding: 0 10px; height: var(--btn); border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-family: var(--mono); font-size: 13px; color: var(--cyan); }
|
||||
button.chip { gap: 6px; padding: 0 10px; border-radius: 10px; background: var(--panel); font-family: var(--mono); font-size: 13px; color: var(--cyan); }
|
||||
button.chip .share { width: 1.1em; height: 1.1em; opacity: .85; }
|
||||
button.chip:hover { background: #15233f; }
|
||||
.chip #netPing { color: var(--dim); }
|
||||
.chip.bad #netPing { color: var(--red); }
|
||||
.chip.waiting { border-color: var(--amber); color: var(--amber); animation: glow 1.4s infinite; } /* alone in the room: tap to invite */
|
||||
|
||||
button { min-height: var(--btn); border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; touch-action: manipulation; transition: background .12s, border-color .12s, transform .05s; }
|
||||
button:hover { border-color: #35538a; background: #15233f; }
|
||||
button:active { transform: translateY(1px); }
|
||||
button:disabled { opacity: .4; cursor: default; }
|
||||
button:disabled { opacity: 1; cursor: default; color: #8da3c8; background: #0c1426; border-color: #172540; }
|
||||
button:focus-visible, input:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
|
||||
button.icon { min-width: var(--btn); padding: 0 8px; font-family: var(--mono); font-size: 13px; }
|
||||
button.icon.toggle[aria-pressed="true"] { background: #0f3550; border-color: var(--cyan); color: var(--cyan); }
|
||||
button#btnPause[aria-pressed="true"] { background: #3a2c08; border-color: var(--amber); color: var(--amber); }
|
||||
button.primary { background: linear-gradient(#1b7a96, #135872); border-color: #2fb4d6; color: #eaffff; font-weight: 600; }
|
||||
button.primary:hover { background: linear-gradient(#2290b0, #176b8a); }
|
||||
button.primary:hover { background: linear-gradient(#1b7a96, #135872); border-color: #8fe6ff; }
|
||||
button.danger { color: var(--red); }
|
||||
button.big { min-height: calc(var(--btn) + 6px); font-size: 16px; padding: 0 20px; }
|
||||
button.link { background: none; border: 0; color: var(--dim); text-decoration: underline; min-height: 36px; padding: 0 8px; }
|
||||
button.link:hover { color: var(--text); background: none; }
|
||||
button.floating { position: absolute; right: 8px; bottom: 8px; background: rgba(12, 19, 34, .85); }
|
||||
#btnWave { white-space: nowrap; min-width: 0; } /* long label ("Wave 12 · 28s") shrinks with an ellipsis instead of wrapping or pushing Sound off screen */
|
||||
#btnWaveText { overflow: hidden; text-overflow: ellipsis; }
|
||||
#btnWave.attn { animation: glow 1.4s infinite; }
|
||||
@keyframes glow { 50% { box-shadow: 0 0 0 4px rgba(77, 227, 255, .25); } }
|
||||
|
||||
@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) {
|
||||
#topbar { padding: 6px 8px; }
|
||||
.stat { padding: 0 8px; font-size: 15px; }
|
||||
#btnWave { flex: 1 1 auto; }
|
||||
.spacer { flex: 0 0 0; }
|
||||
#btnWave { flex: 1 1 130px; }
|
||||
.spacer { display: none; }
|
||||
button.chip { margin-left: auto; font-size: 12.5px; padding: 0 8px; }
|
||||
.chip #netPing { display: none; }
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- stage overlays */
|
||||
.hint { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 20px); padding: 6px 12px; border-radius: 999px; background: rgba(8, 13, 26, .92); border: 1px solid var(--line); font-family: var(--mono); font-size: 13px; pointer-events: none; white-space: nowrap; }
|
||||
.hint { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 20px); padding: 6px 12px; border-radius: 999px; background: rgba(8, 13, 26, .92); border: 1px solid var(--line); font-family: var(--mono); font-size: 13px; pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.hint.ok { color: var(--green); border-color: #1c6a55; }
|
||||
.hint.bad { color: var(--red); border-color: #6a2336; }
|
||||
.hint.info { color: var(--cyan); }
|
||||
.paused-tag { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 10px 26px; border-radius: 999px; background: rgba(8, 13, 26, .88); border: 1px solid var(--amber); color: var(--amber); font-weight: 800; letter-spacing: .3em; font-size: 18px; pointer-events: none; z-index: 2; }
|
||||
/* paused: the board is dimmed and the pill is a button that resumes */
|
||||
#stage.paused::after { content: ""; position: absolute; inset: 0; background: rgba(4, 7, 14, .5); pointer-events: none; z-index: 1; }
|
||||
.paused-tag { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 8px 22px 8px 16px; min-height: 52px; border-radius: 999px; background: rgba(8, 13, 26, .94); border: 2px solid var(--amber); color: var(--amber); font-weight: 800; letter-spacing: .24em; font-size: 17px; z-index: 2; }
|
||||
.paused-tag:hover { background: rgba(30, 24, 8, .96); border-color: var(--amber); }
|
||||
.paused-tag span { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
|
||||
.paused-tag small { font-size: 11px; letter-spacing: .08em; font-weight: 600; color: #e8d9a0; }
|
||||
.paused-tag .ic { width: 1.5em; height: 1.5em; }
|
||||
.banner { position: absolute; left: 0; right: 0; top: 34%; text-align: center; pointer-events: none; font-weight: 800; font-size: clamp(22px, 5vw, 44px); letter-spacing: .14em; color: var(--cyan); text-shadow: 0 0 24px rgba(77, 227, 255, .6); opacity: 0; transform: scale(.96); transition: opacity .3s, transform .3s; }
|
||||
.banner.show { opacity: 1; transform: none; }
|
||||
.banner.boss { color: var(--red); text-shadow: 0 0 24px rgba(255, 92, 122, .7); }
|
||||
#toasts { position: absolute; left: 0; right: 0; bottom: 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
|
||||
.toast { padding: 7px 14px; background: rgba(8, 13, 26, .94); border: 1px solid var(--line); border-radius: 10px; font-size: 14px; animation: toast 2.6s forwards; max-width: calc(100% - 24px); text-align: center; }
|
||||
/* toasts sit under the route hint at the top, and drop below the action bar when that one is at the top (never behind it, never on the server) */
|
||||
#toasts { position: absolute; left: 0; right: 0; top: 46px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 5; }
|
||||
#app[data-ui="compact"][data-bar="top"] #toasts { top: calc(var(--bar-h) + 18px); }
|
||||
#app[data-ui="compact"][data-bar="top"][data-conf] #toasts { top: calc(var(--bar-h) + var(--nudge-h) + 18px); }
|
||||
.toast { padding: 7px 14px; background: rgba(8, 13, 26, .96); border: 1px solid var(--line); border-radius: 10px; font-size: 14px; animation: toast 2.6s forwards; max-width: calc(100% - 24px); text-align: center; }
|
||||
.toast.bad { border-color: #6a2336; color: #ffb3c1; }
|
||||
.toast.good { border-color: #1c6a55; color: #aef5d6; }
|
||||
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
|
||||
.confirm { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; gap: 8px; padding: 6px; border-radius: 14px; background: rgba(8, 13, 26, .94); border: 1px solid var(--line); z-index: 3; white-space: nowrap; }
|
||||
.confirm.top { bottom: auto; top: 52px; }
|
||||
.confirm .primary.big { min-width: 120px; }
|
||||
.reconnect { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 12px; background: rgba(5, 8, 16, .72); z-index: 4; font-size: 16px; }
|
||||
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--cyan); border-radius: 50%; animation: spin .8s linear infinite; }
|
||||
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
|
||||
/* touch build bar: cancel, the route text (what the hint pill shows on desktop), and Build. Same slot and size as the tower action bar. */
|
||||
.confirm { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); width: min(calc(100% - 16px), 480px); height: calc(var(--bar-h) + var(--nudge-h)); display: flex; flex-wrap: wrap; align-content: center; align-items: center; gap: 6px 8px; padding: 5px; border-radius: 14px; background: rgba(8, 13, 26, .96); border: 1px solid #2c4372; box-shadow: 0 6px 22px rgba(0, 0, 0, .5); z-index: 3; }
|
||||
.confirm.top { bottom: auto; top: 8px; }
|
||||
.confirm button { min-height: 44px; flex: none; }
|
||||
.confirm .primary.big { min-width: 112px; padding: 0 12px; font-size: 15px; }
|
||||
.chint { flex: 1 1 0; min-width: 0; text-align: center; font-family: var(--mono); font-size: 12.5px; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
|
||||
/* nudge row: one cell left / up / down / right, for fine aim when a cell is only 12 to 20 px (the arrow is the up icon turned) */
|
||||
.nudge { flex: 1 1 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
|
||||
.nudge button { width: 100%; padding: 0; }
|
||||
/* a stage wide enough for it (tablets, landscape phones) keeps the build bar one row: cancel, route text, arrows, Build */
|
||||
#app[data-barrows="1"] { --nudge-h: 0px; }
|
||||
#app[data-barrows="1"] .confirm { flex-wrap: nowrap; }
|
||||
#app[data-barrows="1"] #confirmHint { order: 1; }
|
||||
#app[data-barrows="1"] .nudge { order: 2; flex: 0 0 auto; grid-template-columns: repeat(4, 44px); gap: 4px; }
|
||||
#app[data-barrows="1"] #btnConfirmBuild { order: 3; }
|
||||
/* a stage too short for two rows (320x568): one row, no route text in the bar (it goes to the pill at the top) and a check-only Build, so the bar leaves the board free */
|
||||
#app[data-barrows="0"] { --nudge-h: 0px; }
|
||||
#app[data-barrows="0"] .confirm { flex-wrap: nowrap; gap: 4px; justify-content: space-between; }
|
||||
#app[data-barrows="0"] #confirmHint, #app[data-barrows="0"] #confirmText { display: none; }
|
||||
#app[data-barrows="0"] .nudge { order: 2; flex: 0 0 auto; grid-template-columns: repeat(4, 44px); gap: 4px; }
|
||||
#app[data-barrows="0"] #btnConfirmBuild { order: 3; min-width: 44px; padding: 0; }
|
||||
#app[data-barrows="0"][data-bar="top"] .hint { top: calc(var(--bar-h) + 16px); }
|
||||
.nudge [data-dx="-1"] .ic { transform: rotate(-90deg); } .nudge [data-dx="1"] .ic { transform: rotate(90deg); } .nudge [data-dy="1"] .ic { transform: rotate(180deg); }
|
||||
.chint.ok { color: var(--green); } .chint.bad { color: var(--red); } .chint.info { color: var(--cyan); }
|
||||
#app[data-ui="compact"][data-bar="bottom"] #btnFit { bottom: auto; top: 8px; } /* keep the reset-zoom button out from under the bar */
|
||||
.reconnect { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 12px; background: rgba(5, 8, 16, .78); z-index: 4; font-size: 16px; padding: 0 16px; text-align: center; }
|
||||
.spinner { width: 22px; height: 22px; flex: none; border: 3px solid var(--line); border-top-color: var(--cyan); border-radius: 50%; animation: spin .8s linear infinite; }
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
/* offline: the rest of the HUD looks dead too (only the menu and the room chip stay usable) */
|
||||
#app.offline #side, #app.offline #topbar > :not(#btnMenu):not(#netChip) { opacity: .45; pointer-events: none; }
|
||||
|
||||
/* ---------------------------------------------------------------- side panel */
|
||||
/* ---------------------------------------------------------------- side panel: palette */
|
||||
#side h4 { margin: 0 0 6px; font-size: 11px; letter-spacing: .14em; color: var(--dim); text-transform: uppercase; font-weight: 600; }
|
||||
#palette { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
|
||||
.tbtn { position: relative; flex-direction: column; gap: 2px; padding: 6px 4px 5px; min-height: 66px; text-align: center; line-height: 1.15; }
|
||||
#palette.many { grid-template-columns: repeat(4, minmax(0, 1fr)); } /* more than 6 towers */
|
||||
.tbtn { position: relative; flex-direction: column; gap: 2px; padding: 6px 4px 5px; min-height: var(--tile-h); text-align: center; line-height: 1.15; }
|
||||
.tbtn canvas { width: 34px; height: 34px; pointer-events: none; }
|
||||
.tbtn .nm { font-size: 11.5px; color: var(--text); }
|
||||
.tbtn .cost { font-family: var(--mono); font-size: 12px; color: var(--amber); }
|
||||
.tbtn .key { position: absolute; top: 3px; left: 5px; font-family: var(--mono); font-size: 10px; color: var(--dim); }
|
||||
.tbtn .key { position: absolute; top: 3px; left: 5px; font-family: var(--mono); font-size: 11px; color: #9db4d8; }
|
||||
.tbtn.sel { border-color: var(--cyan); background: #0f3550; box-shadow: inset 0 0 0 1px var(--cyan); }
|
||||
.tbtn.poor .cost { color: var(--red); }
|
||||
.tbtn.poor { opacity: .72; }
|
||||
.tbtn.poor .nm { color: #9fb2d4; }
|
||||
.tbtn.poor .cost { color: #ff8fa3; }
|
||||
.tbtn.poor canvas { opacity: .6; }
|
||||
@media (pointer: coarse) { .tbtn .key { display: none; } }
|
||||
/* scroll affordance: main.js sets data-more="start|end|both" on a palette that has hidden tiles; the edge fades out */
|
||||
#palette[data-more="end"] { -webkit-mask-image: linear-gradient(var(--fade-dir, to right), #000 calc(100% - 30px), transparent); mask-image: linear-gradient(var(--fade-dir, to right), #000 calc(100% - 30px), transparent); }
|
||||
#palette[data-more="start"] { -webkit-mask-image: linear-gradient(var(--fade-dir, to right), transparent, #000 30px); mask-image: linear-gradient(var(--fade-dir, to right), transparent, #000 30px); }
|
||||
#palette[data-more="both"] { -webkit-mask-image: linear-gradient(var(--fade-dir, to right), transparent, #000 30px, #000 calc(100% - 30px), transparent); mask-image: linear-gradient(var(--fade-dir, to right), transparent, #000 30px, #000 calc(100% - 30px), transparent); }
|
||||
/* stacked: one scrolling row of tiles pinned to the top of the side panel (thumb reach), wrapping grid when there is room */
|
||||
@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) {
|
||||
#palette { position: sticky; top: -8px; z-index: 2; margin: -8px -10px 0; padding: 8px 10px 6px; background: rgba(8, 13, 26, .97); }
|
||||
#palette { display: flex; overflow-x: auto; gap: 6px; padding-bottom: 2px; scrollbar-width: none; scroll-snap-type: x proximity; scroll-padding: 0 10px; }
|
||||
#palette { position: sticky; top: 0; z-index: 2; margin: 0 -10px; padding: 8px 10px 6px; background: #0a101f; display: flex; overflow-x: auto; gap: 6px; scrollbar-width: none; scroll-snap-type: x proximity; scroll-padding: 0 10px; overscroll-behavior-x: contain; }
|
||||
#palette::-webkit-scrollbar { display: none; }
|
||||
.tbtn { flex: 0 0 76px; min-height: 72px; scroll-snap-align: start; }
|
||||
#palette.many { grid-template-columns: none; }
|
||||
}
|
||||
@media (min-width: 640px) and (orientation: portrait), (min-width: 640px) and (max-width: 760px) and (min-height: 521px) {
|
||||
#palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); overflow: visible; mask-image: none; -webkit-mask-image: none; }
|
||||
#palette.many { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
|
||||
.tbtn { flex: none; }
|
||||
}
|
||||
/* short landscape: a few rows of tiles in the narrow column; a long palette scrolls vertically with a fade */
|
||||
@media (orientation: landscape) and (max-height: 520px) {
|
||||
#palette { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
|
||||
.tbtn { min-height: 58px; padding: 3px 2px; }
|
||||
#palette { gap: 4px; max-height: calc(var(--tile-h) * 3.5 + 12px); overflow-y: auto; scrollbar-width: none; overscroll-behavior: contain; --fade-dir: to bottom; }
|
||||
#palette::-webkit-scrollbar { display: none; }
|
||||
#palette.many { gap: 3px; }
|
||||
.tbtn { padding: 3px 2px; }
|
||||
.tbtn canvas { width: 26px; height: 26px; }
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- side panel: info, actions, wave, players */
|
||||
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
|
||||
#info:empty { display: none; }
|
||||
.info-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
|
||||
|
|
@ -160,27 +229,62 @@ button.floating { position: absolute; right: 8px; bottom: 8px; background: rgba(
|
|||
.kvp span:first-child { color: var(--dim); }
|
||||
.kv .up { color: var(--green); }
|
||||
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.actions button { flex: 1 1 auto; font-size: 14px; }
|
||||
.actions button { flex: 1 1 auto; font-size: 14px; min-width: 0; white-space: nowrap; }
|
||||
.actions .cost { font-family: var(--mono); color: var(--amber); }
|
||||
.actions .mv { overflow: hidden; text-overflow: ellipsis; }
|
||||
.actions [data-act="close"] { display: none; }
|
||||
/* wide layout: the actions stay at the bottom edge of the side panel even when a tall palette pushes them down */
|
||||
#app:not([data-ui="compact"]) .actions { position: sticky; bottom: 0; background: var(--panel); padding-top: 6px; margin-top: -2px; }
|
||||
.byline { font-size: 11.5px; color: var(--dim); margin-top: 6px; display: flex; align-items: center; gap: 6px; }
|
||||
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
|
||||
|
||||
/* compact UI: the tower actions are a bar over the stage, on the half away from the tower (data-bar, set by main.js layoutBars) */
|
||||
#app[data-ui="compact"] #info .actions {
|
||||
position: fixed; z-index: 6; flex-wrap: nowrap; gap: 6px; padding: 5px; height: var(--bar-h);
|
||||
left: calc(var(--st-l, 0px) + var(--st-w, 100vw) / 2); transform: translateX(-50%); width: min(calc(var(--st-w, 100vw) - 16px), 480px);
|
||||
top: calc(var(--st-t, 0px) + var(--st-h, 120px) - var(--bar-h) - 8px);
|
||||
border-radius: 14px; background: rgba(8, 13, 26, .96); border: 1px solid #2c4372; box-shadow: 0 6px 22px rgba(0, 0, 0, .5);
|
||||
}
|
||||
#app[data-ui="compact"][data-bar="top"] #info .actions { top: calc(var(--st-t, 0px) + 8px); }
|
||||
#app[data-ui="compact"] #info .actions button { min-height: 44px; padding: 0 8px; gap: 5px; flex: 1 1 0; font-size: 14px; }
|
||||
#app[data-ui="compact"] #info .actions [data-act="up"] { flex-grow: 1.1; }
|
||||
#app[data-ui="compact"] #info .actions [data-act="mode"] { flex-grow: 1.4; }
|
||||
#app[data-ui="compact"] #info .actions [data-act="close"] { display: inline-flex; flex: 0 0 44px; min-width: 44px; padding: 0; }
|
||||
#app[data-ui="compact"][data-barw="s"] #info .actions [data-act="up"] .w, #app[data-ui="compact"][data-barw="s"] #info .actions [data-act="mode"] .w { display: none; }
|
||||
#app[data-ui="compact"] #info .panel { padding: 8px 10px; }
|
||||
#app[data-ui="compact"] .kv { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-bottom: 4px; }
|
||||
#app[data-ui="compact"] .kvp { display: inline-flex; gap: 6px; }
|
||||
#app[data-ui="compact"] .info .desc { font-size: 12.5px; margin: 0 0 4px; }
|
||||
#app[data-ui="compact"] .info-head { margin-bottom: 4px; }
|
||||
#app[data-ui="compact"] .info-head canvas { width: 32px; height: 32px; }
|
||||
|
||||
#nextwave .panel { padding: 8px 10px; }
|
||||
.wv { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-family: var(--mono); font-size: 12.5px; }
|
||||
.wv .e { display: inline-flex; align-items: center; gap: 4px; }
|
||||
.wv .e i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
|
||||
.wv .e i { width: 12px; height: 12px; display: inline-block; background: var(--c); flex: none; } /* shape per enemy kind, not just a colour (see .sh-*) */
|
||||
.wv .e i.sh-ping, .wv .e i.sh-worm { border-radius: 50%; }
|
||||
.wv .e i.sh-trojan { clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0 50%); }
|
||||
.wv .e i.sh-spam { clip-path: polygon(0 20%, 60% 20%, 60% 0, 100% 50%, 60% 100%, 60% 80%, 0 80%); }
|
||||
.wv .e i.sh-spoof { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
|
||||
.wv .e i.sh-rootkit { clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%); width: 14px; height: 14px; }
|
||||
.wv .tag { padding: 1px 6px; border-radius: 6px; font-size: 11px; border: 1px solid; }
|
||||
.wv .tag.air { color: #e29bff; border-color: #5b3a73; }
|
||||
.wv .tag.boss { color: var(--red); border-color: #6a2336; }
|
||||
/* stacked / short: while a tower or build type is selected the wave panel makes room for its stats */
|
||||
#app[data-ui="compact"] #info:not(:empty) ~ #nextwave { display: none; }
|
||||
#players .pl { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13.5px; }
|
||||
#players .pl .off { color: var(--dim); font-size: 12px; }
|
||||
#players .pl .you { color: var(--dim); font-size: 12px; }
|
||||
#players .actions { margin-top: 6px; }
|
||||
|
||||
/* ---------------------------------------------------------------- overlays (menus) */
|
||||
.overlay { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 14px; background: rgba(4, 7, 14, .78); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); overflow-y: auto; }
|
||||
.card { width: min(560px, 100%); max-height: 100%; overflow-y: auto; margin: auto; padding: 20px 20px 16px; border-radius: 18px; background: linear-gradient(#0f1830, #0a1124); border: 1px solid #25396a; box-shadow: 0 20px 60px rgba(0, 0, 0, .6), 0 0 0 1px rgba(77, 227, 255, .06); }
|
||||
/* ---------------------------------------------------------------- overlays (menu, lobby, help, end)
|
||||
* .card is a flex column: .card-body scrolls, .card-foot (the primary buttons) is always visible. */
|
||||
.overlay { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: max(14px, var(--safe-t)) max(14px, var(--safe-r)) max(14px, var(--safe-b)) max(14px, var(--safe-l)); background: rgba(4, 7, 14, .78); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); overflow: hidden; }
|
||||
.card { width: min(560px, 100%); max-height: 100%; min-height: 0; display: flex; flex-direction: column; overflow: hidden; border-radius: 18px; background: linear-gradient(#0f1830, #0a1124); border: 1px solid #25396a; box-shadow: 0 20px 60px rgba(0, 0, 0, .6), 0 0 0 1px rgba(77, 227, 255, .06); }
|
||||
.card.wide { width: min(680px, 100%); }
|
||||
.card-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px 20px 10px; }
|
||||
.card-foot { flex: none; padding: 10px 20px 14px; border-top: 1px solid #1a2a50; background: #0a1124; }
|
||||
.card-foot > .row:first-child, .card-foot > .opts + .row { margin-top: 0; }
|
||||
.card h1 { margin: 0; font-size: clamp(30px, 8vw, 46px); letter-spacing: .26em; font-weight: 800; color: #eaffff; text-shadow: 0 0 22px rgba(77, 227, 255, .55); }
|
||||
.card h2 { margin: 0 0 8px; font-size: 24px; }
|
||||
.card h3 { margin: 0 0 6px; font-size: 14px; letter-spacing: .08em; text-transform: uppercase; color: var(--dim); }
|
||||
|
|
@ -190,30 +294,41 @@ button.floating { position: absolute; right: 8px; bottom: 8px; background: rgba(
|
|||
.muted { color: var(--dim); }
|
||||
.small { font-size: 13px; }
|
||||
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
|
||||
.row.small { margin-top: 6px; }
|
||||
.row > .big { flex: 1 1 200px; }
|
||||
.msg { min-height: 1.4em; text-align: center; color: var(--amber); margin: 8px 0 0; }
|
||||
.row.small { margin-top: 4px; }
|
||||
.row > .big { flex: 1 1 180px; }
|
||||
.opts { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; } /* difficulty selector goes here */
|
||||
.opts:empty { display: none; }
|
||||
.msg { min-height: 1.4em; text-align: center; color: var(--amber); margin: 0 0 4px; }
|
||||
.msg.bad { color: var(--red); }
|
||||
.msg:empty { min-height: 0; margin: 0; }
|
||||
.resume { width: 100%; margin-top: 10px; border-color: var(--cyan); color: var(--cyan); }
|
||||
|
||||
.maps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 4px; }
|
||||
/* map picker: wrapping grid that copes with any number of maps (scrolls inside the card body) */
|
||||
.maps { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 4px; }
|
||||
.mapcard { flex-direction: column; align-items: stretch; gap: 4px; padding: 8px; text-align: left; min-height: 0; border-radius: 12px; }
|
||||
.mapcard canvas { width: 100%; aspect-ratio: 26 / 16; border-radius: 6px; background: #060a14; }
|
||||
.mapcard .nm { font-weight: 700; font-size: 13.5px; min-height: 2.6em; }
|
||||
.mapcard .df { font-size: 11px; color: var(--dim); letter-spacing: .06em; }
|
||||
.mapcard .df { font-size: 11px; color: #9db4d8; letter-spacing: .06em; }
|
||||
.mapcard .df b { color: var(--amber); letter-spacing: 1px; }
|
||||
.mapcard[aria-checked="true"] { border-color: var(--cyan); background: #0f3550; box-shadow: inset 0 0 0 1px var(--cyan); }
|
||||
.mapcard[aria-checked="true"] .nm::before { content: "\2713\00a0"; color: var(--cyan); }
|
||||
.mapdesc { text-align: center; color: var(--dim); font-size: 13px; min-height: 2.6em; margin: 6px 0 4px; }
|
||||
@media (max-width: 480px) { .mapcard .df { display: none; } .mapcard .nm { font-size: 12.5px; } .card { padding: 16px 14px 12px; } }
|
||||
@media (max-width: 480px) { .mapcard .df { display: none; } .mapcard .nm { font-size: 12.5px; min-height: 2.4em; } .card-body { padding: 14px 14px 8px; } .card-foot { padding: 8px 14px 12px; } }
|
||||
|
||||
.field { display: block; margin: 12px 0; }
|
||||
.field span { display: block; font-size: 12px; color: var(--dim); margin-bottom: 4px; letter-spacing: .06em; }
|
||||
input { width: 100%; min-height: var(--btn); border-radius: 10px; border: 1px solid var(--line); background: #070d1b; color: var(--text); padding: 0 12px; font: inherit; font-size: 16px; /* >=16px stops iOS zooming on focus */ }
|
||||
input.code { text-align: center; letter-spacing: .5em; font-family: var(--mono); font-size: 22px; text-transform: uppercase; padding-left: .5em; margin-bottom: 8px; }
|
||||
input::placeholder { color: #8397bb; }
|
||||
input.code { text-align: center; letter-spacing: .5em; font-family: var(--mono); font-size: 22px; text-transform: uppercase; padding-left: .5em; }
|
||||
.joinrow { display: flex; gap: 8px; margin-top: auto; }
|
||||
.joinrow input { flex: 1 1 auto; min-width: 0; }
|
||||
.joinrow button { flex: 0 0 auto; }
|
||||
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
|
||||
.split .col { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 12px; background: rgba(255, 255, 255, .02); border: 1px solid var(--line); }
|
||||
.split .col button { margin-top: auto; }
|
||||
@media (max-width: 480px) { .split { grid-template-columns: 1fr; } }
|
||||
.split .col > button { margin-top: auto; }
|
||||
.roomlist { margin-top: 12px; }
|
||||
@media (max-width: 480px) { .split { grid-template-columns: 1fr; gap: 10px; } }
|
||||
@media (max-height: 640px) { .lead { display: none; } .field { margin: 8px 0; } .split .col { padding: 10px; } } /* small phones: the intro text makes way for the buttons */
|
||||
|
||||
.howto { padding-left: 18px; margin: 10px 0 0; display: grid; gap: 8px; }
|
||||
.howto li { color: #bcd3f5; }
|
||||
|
|
@ -225,56 +340,87 @@ input.code { text-align: center; letter-spacing: .5em; font-family: var(--mono);
|
|||
.stats div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); }
|
||||
.stats span { color: var(--dim); }
|
||||
|
||||
/* short landscape: compact menus so the title, a row of maps and the buttons all fit in 320px */
|
||||
@media (orientation: landscape) and (max-height: 520px) {
|
||||
.overlay { padding: max(6px, var(--safe-t)) max(8px, var(--safe-r)) max(6px, var(--safe-b)) max(8px, var(--safe-l)); }
|
||||
.card-body { padding: 8px 16px 6px; }
|
||||
.card-foot { padding: 6px 16px 8px; }
|
||||
.card h1 { font-size: 24px; letter-spacing: .2em; }
|
||||
.card h2 { font-size: 19px; margin-bottom: 4px; }
|
||||
.logo { gap: 10px; } .logo-mark { width: 28px; height: 28px; }
|
||||
.tag { margin: 2px 0 6px; font-size: 13px; }
|
||||
.maps { display: flex; overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; padding-bottom: 2px; }
|
||||
.maps::-webkit-scrollbar { display: none; }
|
||||
.mapcard { flex: 0 0 118px; scroll-snap-align: start; padding: 5px; gap: 2px; }
|
||||
.mapcard .nm { min-height: 0; font-size: 12px; }
|
||||
.mapcard .df { display: none; }
|
||||
.mapdesc { min-height: 0; margin: 4px 0 0; font-size: 12px; }
|
||||
.row { margin-top: 6px; gap: 8px; } .row.small { margin-top: 0; }
|
||||
.row > .big { flex: 1 1 140px; }
|
||||
.lead { display: none; }
|
||||
.field { margin: 6px 0; display: flex; align-items: center; gap: 10px; } .field span { margin: 0; flex: none; }
|
||||
.split { gap: 8px; } .split .col { padding: 6px 8px; gap: 4px; } .split .col h3 { margin-bottom: 0; font-size: 12px; }
|
||||
.split .col .small { display: none; }
|
||||
.resume { margin-top: 6px; }
|
||||
.stats { margin: 6px 0 2px; font-size: 13px; }
|
||||
.stats div { padding: 2px 0; }
|
||||
.howto { gap: 5px; font-size: 13.5px; }
|
||||
button.link { min-height: 32px; }
|
||||
}
|
||||
|
||||
/* the board gets the whole stage while a menu is shown behind blurred overlays; hide HUD chrome pre-game */
|
||||
#app[data-screen="menu"] #side,
|
||||
#app[data-screen="menu"] #topbar > :not(#btnMenu) { visibility: hidden; }
|
||||
|
||||
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
|
||||
|
||||
/* compact info panel on stacked (portrait / narrow) layouts: must come after the base rules above */
|
||||
@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) {
|
||||
.kv { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-bottom: 6px; }
|
||||
.kvp { display: inline-flex; gap: 6px; }
|
||||
.info .desc { font-size: 12.5px; margin: 0 0 4px; }
|
||||
.info-head { margin-bottom: 4px; }
|
||||
.info-head canvas { width: 32px; height: 32px; }
|
||||
.panel { padding: 8px 10px; }
|
||||
.actions button { min-height: 42px; }
|
||||
/* reduced motion: less movement, never less information (toasts and the low-integrity cue stay visible) */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.toast { animation: none; }
|
||||
#btnWave.attn, #statLives.low, .chip.waiting { animation: none; }
|
||||
.banner { transition: none; }
|
||||
button { transition: none; }
|
||||
.spinner { animation-duration: 2.4s; }
|
||||
}
|
||||
|
||||
/* stacked layouts: keep the top bar to two rows even with the co-op chip */
|
||||
@media (orientation: portrait), (max-width: 760px) and (min-height: 521px) {
|
||||
.chip { padding: 0 8px; font-size: 12.5px; }
|
||||
.chip #netPing { display: none; }
|
||||
#netChip { margin-left: auto; }
|
||||
.spacer { display: none; }
|
||||
#btnWave { flex: 1 1 130px; }
|
||||
}
|
||||
|
||||
/* narrow portrait phones: the room chip moves into the players panel, stats shrink so the bar stays two rows */
|
||||
/* narrow portrait phones: the room chip shrinks to its code + share icon, stats shrink so the bar stays two rows */
|
||||
@media (max-width: 420px) {
|
||||
#netChip { display: none; }
|
||||
button.chip > svg:first-child { display: none; }
|
||||
.stat { padding: 0 7px; gap: 4px; font-size: 14px; }
|
||||
.stat .lbl { font-size: 10px; letter-spacing: .06em; }
|
||||
#topbar { gap: 5px 6px; padding: 5px 6px; }
|
||||
}
|
||||
/* small landscape phones: one slim top bar, narrower side panel */
|
||||
@media (orientation: landscape) and (max-height: 520px) and (max-width: 700px) {
|
||||
:root { --side-w: 200px; --btn: 38px; }
|
||||
#netChip { display: none; }
|
||||
:root { --side-w: 200px; }
|
||||
.stat .lbl { display: none; }
|
||||
.stat { padding: 0 6px; font-size: 14px; }
|
||||
.stat { padding: 0 5px; font-size: 14px; }
|
||||
button.icon { min-width: 36px; padding: 0 6px; }
|
||||
#topbar { gap: 4px; padding: 3px 6px; }
|
||||
#topbar { gap: 3px; padding: 3px 6px; }
|
||||
#btnWave { padding: 0 8px; gap: 5px; }
|
||||
.tbtn .nm { font-size: 10.5px; }
|
||||
button.chip { padding: 0 6px; font-size: 12px; gap: 4px; } .chip #netPing { display: none; } button.chip > svg { display: none; }
|
||||
}
|
||||
|
||||
@media (orientation: landscape) and (max-height: 520px) and (min-width: 701px) { .chip #netPing { display: none; } }
|
||||
/* very small phones (320px) */
|
||||
@media (max-width: 340px) {
|
||||
:root { --btn: 38px; }
|
||||
.stat .lbl { display: none; }
|
||||
.stat { padding: 0 6px; }
|
||||
#btnWave { flex: 1 1 80px; padding: 0 8px; }
|
||||
button.icon { min-width: 38px; padding: 0 4px; }
|
||||
#topbar { gap: 4px; padding: 4px; }
|
||||
}
|
||||
|
||||
/* touch: every target is at least 44px (declared last so no layout rule above can shrink it) */
|
||||
@media (pointer: coarse) {
|
||||
:root { --btn: 44px; }
|
||||
button.icon { min-width: 44px; }
|
||||
button.link { min-height: 44px; }
|
||||
button.chip { min-width: 44px; }
|
||||
}
|
||||
|
||||
/* Windows high contrast: selection must not depend on colours the UA replaces */
|
||||
@media (forced-colors: active) {
|
||||
.tbtn.sel, .mapcard[aria-checked="true"], button.toggle[aria-pressed="true"], button#btnPause[aria-pressed="true"] { outline: 3px solid Highlight; outline-offset: -3px; forced-color-adjust: none; background: Highlight; color: HighlightText; }
|
||||
.tbtn.sel .nm, .tbtn.sel .cost, .mapcard[aria-checked="true"] .df, .mapcard[aria-checked="true"] .df b { color: HighlightText; }
|
||||
.overlay { background: Canvas; }
|
||||
#side { border-color: CanvasText; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
<symbol id="i-up" viewBox="0 0 24 24"><path d="M12 19V6M6 11.5L12 5.5l6 6" fill="none" stroke="currentColor" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round"/></symbol>
|
||||
<symbol id="i-trash" viewBox="0 0 24 24"><path d="M5 7h14M10 7V4.5h4V7M7 7l1 12.5h8L17 7M10.5 11v5M13.5 11v5" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/></symbol>
|
||||
<symbol id="i-users" viewBox="0 0 24 24"><circle cx="9" cy="8.5" r="3.3" fill="currentColor"/><path d="M2.5 19.5c0-3.6 2.9-5.6 6.5-5.6s6.5 2 6.5 5.6z" fill="currentColor"/><circle cx="17" cy="9.5" r="2.5" fill="currentColor" opacity=".7"/><path d="M16.5 14.2c3 0 5 1.6 5 4.6h-4.2" fill="currentColor" opacity=".7"/></symbol>
|
||||
<symbol id="i-target" viewBox="0 0 24 24"><circle cx="12" cy="12" r="7.5" fill="none" stroke="currentColor" stroke-width="2"/><circle cx="12" cy="12" r="2.2" fill="currentColor"/><path d="M12 2.5v4M12 17.5v4M2.5 12h4M17.5 12h4" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></symbol>
|
||||
<symbol id="i-fs" viewBox="0 0 24 24"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></symbol>
|
||||
</defs>
|
||||
</svg>
|
||||
|
|
@ -46,12 +47,12 @@
|
|||
<div class="stat" id="statWave" title="Wave"><span class="lbl">WAVE</span><b id="vWave">0</b><small id="vWaveMax"></small></div>
|
||||
<div class="stat" id="statLives" title="Server integrity"><svg class="ic"><use href="#i-heart"/></svg><b id="vLives">20</b></div>
|
||||
<div class="stat" id="statGold" title="Credits"><svg class="ic"><use href="#i-coin"/></svg><b id="vGold">0</b></div>
|
||||
<div id="netChip" class="chip" hidden title="Co-op room"><svg class="ic"><use href="#i-users"/></svg><span id="netRoom"></span><span id="netPing"></span></div>
|
||||
<button id="netChip" class="chip" type="button" hidden title="Co-op room: tap to invite your partner" aria-label="Co-op room. Tap to invite your partner"><svg class="ic"><use href="#i-users"/></svg><span id="netRoom"></span><span id="netPing"></span><svg class="ic share"><use href="#i-share"/></svg></button>
|
||||
<div class="spacer"></div>
|
||||
<button id="btnWave" class="primary" aria-label="Start next wave"><svg class="ic"><use href="#i-play"/></svg><span id="btnWaveText">Wave 1</span></button>
|
||||
<button id="btnAuto" class="icon toggle" aria-pressed="false" aria-label="Automatic waves" title="Automatic waves (A)"><span>AUTO</span></button>
|
||||
<button id="btnSpeed" class="icon" aria-label="Game speed" title="Speed (F)"><span id="speedText">1×</span></button>
|
||||
<button id="btnPause" class="icon" aria-label="Pause" title="Pause (P)"><svg class="ic"><use href="#i-pause"/></svg></button>
|
||||
<button id="btnPause" class="icon" aria-label="Pause" aria-pressed="false" title="Pause (P)"><svg class="ic"><use href="#i-pause"/></svg></button>
|
||||
<button id="btnSound" class="icon" aria-label="Sound" title="Sound (M)"><svg class="ic"><use href="#i-sound"/></svg></button>
|
||||
</header>
|
||||
|
||||
|
|
@ -59,14 +60,21 @@
|
|||
<canvas id="board" aria-label="Game board" role="img"></canvas>
|
||||
<div id="hint" class="hint" hidden></div>
|
||||
<div id="banner" class="banner" aria-live="polite"></div>
|
||||
<div id="pausedTag" class="paused-tag" hidden>PAUSED</div>
|
||||
<button id="pausedTag" class="paused-tag" type="button" hidden><svg class="ic"><use href="#i-play"/></svg><span>PAUSED<small>tap to resume</small></span></button>
|
||||
<div id="toasts" aria-live="polite"></div>
|
||||
<button id="btnFit" class="icon floating" aria-label="Reset zoom" hidden><svg class="ic"><use href="#i-fit"/></svg></button>
|
||||
<div id="confirm" class="confirm" hidden>
|
||||
<button id="btnCancelBuild" class="icon danger" aria-label="Cancel"><svg class="ic"><use href="#i-x"/></svg></button>
|
||||
<span id="confirmHint" class="chint" aria-live="polite"></span>
|
||||
<button id="btnConfirmBuild" class="primary big"><svg class="ic"><use href="#i-check"/></svg><span id="confirmText">Build</span></button>
|
||||
<div id="nudge" class="nudge" role="group" aria-label="Move the build cell by one cell">
|
||||
<button type="button" data-dx="-1" data-dy="0" aria-label="Move left"><svg class="ic"><use href="#i-up"/></svg></button>
|
||||
<button type="button" data-dx="0" data-dy="-1" aria-label="Move up"><svg class="ic"><use href="#i-up"/></svg></button>
|
||||
<button type="button" data-dx="0" data-dy="1" aria-label="Move down"><svg class="ic"><use href="#i-up"/></svg></button>
|
||||
<button type="button" data-dx="1" data-dy="0" aria-label="Move right"><svg class="ic"><use href="#i-up"/></svg></button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="reconnect" class="reconnect" hidden><div class="spinner"></div><span>Connection lost. Reconnecting…</span></div>
|
||||
<div id="reconnect" class="reconnect" hidden role="alert"><div class="spinner"></div><span>Connection lost. Reconnecting…</span></div>
|
||||
</main>
|
||||
|
||||
<aside id="side">
|
||||
|
|
@ -76,24 +84,27 @@
|
|||
<section id="players" hidden></section>
|
||||
</aside>
|
||||
|
||||
<!-- ===== main menu ===== -->
|
||||
<!-- ===== main menu: .card-body scrolls, .card-foot (the primary buttons) is always visible ===== -->
|
||||
<div id="menu" class="overlay">
|
||||
<div class="card">
|
||||
<div class="logo"><span class="logo-mark" aria-hidden="true"></span><h1>NETWALL</h1></div>
|
||||
<p class="tag">Build the firewall. Stretch the route. Protect the server.</p>
|
||||
|
||||
<div id="mapPick" class="maps" role="radiogroup" aria-label="Map"></div>
|
||||
<p id="mapDesc" class="mapdesc"></p>
|
||||
|
||||
<div class="row">
|
||||
<button id="btnSolo" class="primary big"><svg class="ic"><use href="#i-play"/></svg>Play solo</button>
|
||||
<button id="btnCoop" class="big"><svg class="ic"><use href="#i-users"/></svg>Co-op online</button>
|
||||
<div class="card-body">
|
||||
<div class="logo"><span class="logo-mark" aria-hidden="true"></span><h1>NETWALL</h1></div>
|
||||
<p class="tag">Build the firewall. Stretch the route. Protect the server.</p>
|
||||
<div id="mapPick" class="maps" role="radiogroup" aria-label="Map"></div>
|
||||
<p id="mapDesc" class="mapdesc"></p>
|
||||
</div>
|
||||
<button id="btnResume" class="big resume" hidden></button>
|
||||
<div class="row small">
|
||||
<button id="btnHelp" class="link">How to play</button>
|
||||
<button id="btnFullscreen" class="link" hidden>Fullscreen</button>
|
||||
<button id="btnCloseMenu" class="link" hidden>Back to game</button>
|
||||
<div class="card-foot">
|
||||
<div id="menuOpts" class="opts"></div><!-- room for the difficulty selector (Easy / Normal / Hard) -->
|
||||
<div class="row">
|
||||
<button id="btnSolo" class="primary big"><svg class="ic"><use href="#i-play"/></svg>Play solo</button>
|
||||
<button id="btnCoop" class="big"><svg class="ic"><use href="#i-users"/></svg>Co-op online</button>
|
||||
</div>
|
||||
<button id="btnResume" class="big resume" hidden></button>
|
||||
<div class="row small">
|
||||
<button id="btnHelp" class="link">How to play</button>
|
||||
<button id="btnFullscreen" class="link" hidden>Fullscreen</button>
|
||||
<button id="btnCloseMenu" class="link" hidden>Back to game</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -101,55 +112,68 @@
|
|||
<!-- ===== co-op lobby ===== -->
|
||||
<div id="lobby" class="overlay" hidden>
|
||||
<div class="card">
|
||||
<h2>Co-op online</h2>
|
||||
<p class="muted">Two players, one base, one pool of credits. Create a room and send the link, or enter a friend's code.</p>
|
||||
<label class="field"><span>Your name</span><input id="inName" maxlength="16" autocomplete="nickname" autocapitalize="words" spellcheck="false" placeholder="Player"></label>
|
||||
<div class="split">
|
||||
<div class="col">
|
||||
<h3>Host a game</h3>
|
||||
<p class="muted small" id="lobbyMapName"></p>
|
||||
<button id="btnCreate" class="primary big">Create room</button>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h3>Join a game</h3>
|
||||
<input id="inCode" class="code" maxlength="4" autocomplete="off" autocapitalize="characters" spellcheck="false" inputmode="text" placeholder="ABCD" aria-label="Room code">
|
||||
<button id="btnJoin" class="big">Join</button>
|
||||
<div class="card-body">
|
||||
<h2>Co-op online</h2>
|
||||
<p class="muted lead">Two players, one base, one pool of credits. Create a room and send the link, or enter a friend's code.</p>
|
||||
<label class="field"><span>Your name</span><input id="inName" maxlength="16" autocomplete="nickname" autocapitalize="words" spellcheck="false" placeholder="Player"></label>
|
||||
<div class="split">
|
||||
<div class="col">
|
||||
<h3>Host a game</h3>
|
||||
<p class="muted small" id="lobbyMapName"></p>
|
||||
<button id="btnCreate" class="primary big">Create room</button>
|
||||
</div>
|
||||
<div class="col">
|
||||
<h3>Join a game</h3>
|
||||
<div class="joinrow">
|
||||
<input id="inCode" class="code" maxlength="4" autocomplete="off" autocapitalize="characters" spellcheck="false" inputmode="text" placeholder="ABCD" aria-label="Room code">
|
||||
<button id="btnJoin" class="big">Join</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="roomList" class="roomlist" hidden></div><!-- room for the list of open rooms -->
|
||||
</div>
|
||||
<div class="card-foot">
|
||||
<p id="lobbyMsg" class="msg" role="status"></p>
|
||||
<div class="row small"><button id="btnLobbyBack" class="link">← Back</button></div>
|
||||
</div>
|
||||
<p id="lobbyMsg" class="msg" role="status"></p>
|
||||
<div class="row small"><button id="btnLobbyBack" class="link">← Back</button></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ===== help ===== -->
|
||||
<div id="help" class="overlay" hidden>
|
||||
<div class="card wide">
|
||||
<div class="card-body">
|
||||
<h2>How to play</h2>
|
||||
<ul class="howto">
|
||||
<li><b>Goal.</b> Packets pour in from the gateways (red). Don't let them reach the <b>server</b>. Each leak costs integrity (♥).</li>
|
||||
<li><b>Maze.</b> The map is open: <b>Firewalls</b> are cheap walls. Packets always take the shortest open route, so walls make them walk further, past your turrets. You can lengthen the route but never seal it off completely. Hover to preview the new route.</li>
|
||||
<li><b>Turrets.</b> Filter (fast), IDS Sniper (long range, armour-piercing), Mortar (splash), Rate Limiter (slows), Router Arc (chain lightning). <b>Spoofed packets fly</b> over your maze, so keep some anti-air. Mortars can't hit flyers.</li>
|
||||
<li><b>Maze.</b> The map is open: <b>Firewalls</b> are cheap walls. Packets always take the shortest open route, so walls make them walk further, past your turrets. You can lengthen the route but never seal it off completely. <span class="kbd-only">Hover</span><span class="touch-only">Tap</span> to preview the new route.</li>
|
||||
<li><b>Turrets.</b> Filter (fast), IDS Sniper (long range, armour-piercing), Mortar (splash), Rate Limiter (slows), Router Arc (chain lightning), and the very expensive late-game <b>Orbital Uplink</b> (a piercing beam that ignores armour, hits flyers and slows what it touches). <b>Spoofed packets fly</b> over your maze, so keep some anti-air. Mortars can't hit flyers.</li>
|
||||
<li><b>Credits.</b> Earned from kills and every cleared wave. Upgrade turrets up to level 3. Sell for 70% back (walls refund in full).</li>
|
||||
<li><b>Controls.</b> <span class="kbd-only">Click to build, drag to paint walls, right-click to cancel. Keys 1–6 pick a tower, Space starts a wave, U upgrades, X sells, T changes targeting, P pauses, F changes speed, wheel zooms.</span>
|
||||
<span class="touch-only">Tap a tower type, then tap the map to preview and tap ✓ to build. Walls paint as you drag. Pinch to zoom, two fingers to pan, long-press to ping your partner.</span></li>
|
||||
<li><b>Controls.</b> <span class="kbd-only">Click to build, drag to paint walls, right-click to cancel. Keys <span id="helpKeys">1–6</span> pick a tower, Space starts a wave, U upgrades, X sells, T changes targeting, P pauses, F changes speed, wheel zooms.</span>
|
||||
<span class="touch-only">Tap a tower type, then tap the map to preview; nudge the cell with the arrows and tap ✓ to build. Walls paint as you drag. Pinch to zoom, two fingers to pan, long-press to ping your partner.</span></li>
|
||||
<li><b>Co-op.</b> Both players share everything and can build, sell and upgrade at the same time. You see each other's cursors; long-press / Alt-click pings the map.</li>
|
||||
</ul>
|
||||
<div class="row"><button id="btnHelpClose" class="primary big">Got it</button></div>
|
||||
</div>
|
||||
<div class="card-foot"><div class="row"><button id="btnHelpClose" class="primary big">Got it</button></div></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ===== game over / victory ===== -->
|
||||
<div id="end" class="overlay" hidden>
|
||||
<div class="card">
|
||||
<h2 id="endTitle">Breach!</h2>
|
||||
<p id="endText" class="muted"></p>
|
||||
<div id="endStats" class="stats"></div>
|
||||
<div class="row">
|
||||
<button id="btnAgain" class="primary big">Play again</button>
|
||||
<button id="btnContinue" class="big" hidden>Keep going</button>
|
||||
<button id="btnEndMenu" class="big">Menu</button>
|
||||
<div class="card-body">
|
||||
<h2 id="endTitle">Breach!</h2>
|
||||
<p id="endText" class="muted"></p>
|
||||
<div id="endStats" class="stats"></div>
|
||||
</div>
|
||||
<div class="card-foot">
|
||||
<div class="row">
|
||||
<button id="btnAgain" class="primary big">Play again</button>
|
||||
<button id="btnContinue" class="big" hidden>Keep going</button>
|
||||
<button id="btnEndMenu" class="big">Menu</button>
|
||||
</div>
|
||||
<p id="endWait" class="msg" hidden>Waiting for the host to start a new game…</p>
|
||||
</div>
|
||||
<p id="endWait" class="msg" hidden>Waiting for the host to start a new game…</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -86,6 +86,8 @@
|
|||
shot_filter: () => noise(0.03, 0.07, 'highpass', 5000),
|
||||
shot_ids: () => { tone(1100, 0.14, 'sawtooth', 0.2, 180); noise(0.08, 0.12, 'highpass', 2500); },
|
||||
shot_mortar: () => tone(150, 0.18, 'sine', 0.45, 60),
|
||||
// Orbital Uplink: a falling laser sweep over a sub-bass thump and a hiss of ionised air
|
||||
shot_uplink: () => { tone(2600, 0.45, 'sawtooth', 0.16, 140); tone(1300, 0.45, 'square', 0.07, 70, 0.02); tone(70, 0.55, 'sine', 0.5, 32); noise(0.4, 0.22, 'bandpass', 4200, 600); },
|
||||
arc: () => { noise(0.1, 0.16, 'bandpass', 3500, 900); tone(900, 0.08, 'sawtooth', 0.1, 300); },
|
||||
boom: () => noise(0.32, 0.5, 'lowpass', 1800, 90),
|
||||
kill: () => tone(820, 0.05, 'triangle', 0.1, 1200),
|
||||
|
|
@ -96,7 +98,7 @@
|
|||
ping: () => { tone(1320, 0.18, 'sine', 0.25, 1760); tone(1760, 0.3, 'sine', 0.12, 0, 0.12); },
|
||||
join: () => { tone(660, 0.1, 'triangle', 0.2); tone(990, 0.16, 'triangle', 0.2, 0, 0.1); },
|
||||
};
|
||||
const MIN_GAP = { shot_filter: 0.06, kill: 0.05, arc: 0.07, boom: 0.08, shot_mortar: 0.1, shot_ids: 0.08, wall: 0.03 };
|
||||
const MIN_GAP = { shot_uplink: 0.12, shot_filter: 0.06, kill: 0.05, arc: 0.07, boom: 0.08, shot_mortar: 0.1, shot_ids: 0.08, wall: 0.03 };
|
||||
|
||||
function sfx(name) {
|
||||
if (muted || !unlocked || !ctx || !SFX[name]) return;
|
||||
|
|
|
|||
|
|
@ -330,9 +330,11 @@
|
|||
return this.board.trial(x, y, reserved, null, routes);
|
||||
}
|
||||
newGame(map) { this._send({ t: 'newgame', map }); }
|
||||
sendCursor(x, y) {
|
||||
// Moves are throttled to one per 70 ms. A clear (x === null) or `force` always goes out, so the final position / the
|
||||
// "cursor gone" message of a touch is never swallowed by the throttle (touch-9).
|
||||
sendCursor(x, y, force) {
|
||||
const now = performance.now();
|
||||
if (now - this.lastCursor < 70) return;
|
||||
if (x !== null && !force && now - this.lastCursor < 70) return;
|
||||
this.lastCursor = now;
|
||||
this._send({ t: 'cursor', x: x === null ? null : Math.round(x * 100) / 100, y: y === null ? null : Math.round(y * 100) / 100 });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,15 +72,23 @@
|
|||
clearTimeout(bannerT);
|
||||
bannerT = setTimeout(() => { b.className = 'banner' + (boss ? ' boss' : ''); }, 1500);
|
||||
}
|
||||
let hintText = '', hintKind = '';
|
||||
function hint(text, kind) {
|
||||
const h = $('hint');
|
||||
const h = $('hint'), ch = $('confirmHint');
|
||||
hintText = text || ''; hintKind = kind || 'info';
|
||||
if (!$('confirm').hidden && $('app').dataset.barrows !== '0') { // the touch build bar carries the route text itself: one overlay on the board instead of two (not when it is too small for it)
|
||||
h.hidden = true; h.textContent = hintText; ch.textContent = hintText; ch.className = 'chint ' + hintKind; return; // (#hint keeps the text, hidden, for readers and tests)
|
||||
}
|
||||
if (!text) { h.hidden = true; return; }
|
||||
h.hidden = false; h.textContent = text; h.className = 'hint ' + (kind || 'info');
|
||||
h.hidden = false; h.textContent = text; h.className = 'hint ' + hintKind;
|
||||
}
|
||||
const fmtLen = (v) => String(Math.round(v / Math.max(1, ui.spawns || 1)));
|
||||
|
||||
function showOverlay(id) {
|
||||
for (const o of document.querySelectorAll('.overlay')) o.hidden = o.id !== id;
|
||||
for (const o of document.querySelectorAll('.overlay')) {
|
||||
const wasHidden = o.hidden; o.hidden = o.id !== id;
|
||||
if (wasHidden && !o.hidden) { const body = o.querySelector('.card-body'); if (body) body.scrollTop = 0; }
|
||||
}
|
||||
}
|
||||
function setScreen(name) {
|
||||
app.screen = name;
|
||||
|
|
@ -163,15 +171,20 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
let errSfxAt = -1e9;
|
||||
function onReject(r) {
|
||||
toast(REASONS[r.reason] || ('Not possible: ' + r.reason), 'bad');
|
||||
Audio.sfx('error');
|
||||
// One buzzer per wall stroke (a stroke can reject dozens of cells), and never a burst: co-op rejects arrive after the finger has lifted (touch-16)
|
||||
const now = performance.now();
|
||||
if (now - errSfxAt > 450 && !(painting && strokeErr)) { errSfxAt = now; Audio.sfx('error'); }
|
||||
if (painting) strokeErr = true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ palette + info panel
|
||||
function buildPalette() {
|
||||
const pal = $('palette');
|
||||
pal.textContent = '';
|
||||
pal.classList.toggle('many', TD.TOWER_ORDER.length > 6);
|
||||
for (const type of TD.TOWER_ORDER) {
|
||||
const def = TD.TOWERS[type];
|
||||
const b = document.createElement('button');
|
||||
|
|
@ -183,8 +196,28 @@
|
|||
b.addEventListener('click', () => { Audio.sfx('click'); selectType(app.selType === type ? null : type); });
|
||||
pal.appendChild(b);
|
||||
}
|
||||
drawPaletteIcons();
|
||||
drawPaletteIcons(); updatePaletteHint();
|
||||
}
|
||||
// A palette that does not fit scrolls (sideways when stacked, down in the narrow landscape column). data-more says on which
|
||||
// side more tiles are hidden; the CSS fades that edge so the player can see there is more.
|
||||
function updatePaletteHint() {
|
||||
const p = $('palette'); let more = '';
|
||||
const edge = (pos, size, view) => { const a = pos > 2, b = pos < size - view - 2; return a && b ? 'both' : a ? 'start' : b ? 'end' : ''; };
|
||||
if (p.scrollWidth > p.clientWidth + 2) more = edge(p.scrollLeft, p.scrollWidth, p.clientWidth);
|
||||
else if (p.scrollHeight > p.clientHeight + 2) more = edge(p.scrollTop, p.scrollHeight, p.clientHeight);
|
||||
if (more) { if (p.dataset.more !== more) p.dataset.more = more; } else if (p.dataset.more) delete p.dataset.more;
|
||||
}
|
||||
function revealTile(b) { // scroll the palette (only the palette, never the page) so this tile is fully in view
|
||||
const p = $('palette'); if (!b) return;
|
||||
const pr = p.getBoundingClientRect(), br = b.getBoundingClientRect(), m = 34; // keep clear of the edge fade
|
||||
if (p.scrollWidth > p.clientWidth + 2) {
|
||||
if (br.left < pr.left + m) p.scrollLeft -= pr.left + m - br.left; else if (br.right > pr.right - m) p.scrollLeft += br.right - (pr.right - m);
|
||||
} else if (p.scrollHeight > p.clientHeight + 2) {
|
||||
if (br.top < pr.top + m) p.scrollTop -= pr.top + m - br.top; else if (br.bottom > pr.bottom - m) p.scrollTop += br.bottom - (pr.bottom - m);
|
||||
}
|
||||
updatePaletteHint();
|
||||
}
|
||||
$('palette').addEventListener('scroll', updatePaletteHint, { passive: true });
|
||||
function drawPaletteIcons() {
|
||||
for (const b of $('palette').children) NW.drawIcon(b.querySelector('canvas'), b.dataset.type, 1);
|
||||
}
|
||||
|
|
@ -193,6 +226,7 @@
|
|||
const sel = b.dataset.type === app.selType;
|
||||
b.classList.toggle('sel', sel);
|
||||
b.setAttribute('aria-pressed', sel ? 'true' : 'false');
|
||||
if (sel) revealTile(b);
|
||||
}
|
||||
}
|
||||
function selectType(type) {
|
||||
|
|
@ -218,46 +252,40 @@
|
|||
}
|
||||
function targetsText(def) { return def.ground && def.air ? 'ground + air' : def.ground ? 'ground only' : 'none'; }
|
||||
|
||||
let infoSig = '';
|
||||
// The info panel is built ONCE per selection (tower id + owner, or armed build type) and then updated in place, so a
|
||||
// button is never replaced under a finger: partner actions bump view.rev constantly in co-op (code-2). A rebuild that
|
||||
// would replace nodes is deferred while a pointer is down inside the panel.
|
||||
const info = { shape: '', sig: '', lv: 0, pressed: false, dirty: false };
|
||||
|
||||
function renderInfo(force) {
|
||||
const box = $('info'), ctrl = app.ctrl, view = ctrl.view;
|
||||
let sig, tower = null;
|
||||
let tower = null, ownerP = null, shape = '';
|
||||
if (app.selTower) {
|
||||
tower = view.towers.find((t) => t.id === app.selTower);
|
||||
if (!tower) { app.selTower = 0; }
|
||||
tower = view.towers.find((t) => t.id === app.selTower) || null;
|
||||
if (!tower) app.selTower = 0;
|
||||
}
|
||||
if (tower) sig = 't' + tower.id + ':' + tower.level + ':' + tower.mode;
|
||||
else if (app.selType) sig = 'b' + app.selType;
|
||||
else sig = '';
|
||||
if (!force && sig === infoSig) return;
|
||||
infoSig = sig;
|
||||
if (!sig) { box.textContent = ''; return; }
|
||||
if (tower) {
|
||||
const def = TD.TOWERS[tower.type], i = tower.level - 1;
|
||||
const cur = statsFor(tower.type, i), nxt = tower.level < def.levels.length ? statsFor(tower.type, i + 1) : null;
|
||||
let kv = '';
|
||||
cur.forEach((row, k) => {
|
||||
const n = nxt && nxt[k] && nxt[k][1] !== row[1] ? ' <span class="up">→ ' + nxt[k][1] + '</span>' : '';
|
||||
kv += '<div class="kvp"><span>' + row[0] + '</span><span>' + row[1] + n + '</span></div>';
|
||||
});
|
||||
if (tower.type !== 'wall') kv += '<div class="kvp"><span>Targets</span><span>' + targetsText(def) + '</span></div>';
|
||||
const sellVal = def.refund ? tower.spent : Math.floor(tower.spent * TD.SELL_RATIO);
|
||||
const upCost = tower.level < def.levels.length ? def.levels[tower.level].cost : null;
|
||||
const owner = ctrl.kind === 'remote' && ctrl.players.length > 1;
|
||||
const ownerP = owner ? ctrl.players.find((p) => p.slot === tower.owner) : null;
|
||||
if (ctrl.kind === 'remote' && ctrl.players.length > 1) ownerP = ctrl.players.find((p) => p.slot === tower.owner) || null;
|
||||
shape = 't' + tower.id + tower.type + ':' + (ownerP ? ownerP.slot + ownerP.name : '');
|
||||
} else if (app.selType) shape = 'b' + app.selType;
|
||||
if (!force && shape === info.shape) { if (tower) syncInfo(); return; }
|
||||
if (info.pressed) { info.dirty = true; return; } // never replace a node while a pointer is down on it
|
||||
info.shape = shape; info.sig = ''; info.lv = 0; info.dirty = false;
|
||||
if (!shape) { box.textContent = ''; return; }
|
||||
if (tower) {
|
||||
const def = TD.TOWERS[tower.type], wall = tower.type === 'wall';
|
||||
box.innerHTML =
|
||||
'<div class="panel info"><div class="info-head"><canvas></canvas><div><div class="nm"></div><div class="lv"></div></div></div>' +
|
||||
'<div class="desc"></div><div class="kv">' + kv + '</div><div class="actions">' +
|
||||
(tower.type === 'wall' ? '' :
|
||||
'<button type="button" data-act="up"' + (upCost === null ? ' disabled' : '') + '><svg class="ic"><use href="#i-up"/></svg>' + (upCost === null ? 'Max level' : 'Upgrade <span class="cost" id="upCost">' + upCost + '</span>') + '</button>' +
|
||||
'<button type="button" data-act="mode" title="Which packet to shoot"><span>Target: ' + MODE_NAMES[tower.mode] + '</span></button>') +
|
||||
'<button type="button" data-act="sell" class="danger"><svg class="ic"><use href="#i-trash"/></svg>Sell <span class="cost">' + sellVal + '</span></button></div>' +
|
||||
'<div class="byline">' + (tower.type === 'wall' ? '' : '<span id="infoKills"></span>') + (ownerP ? '<span class="dot" style="background:' + NW.SLOT_COLORS[ownerP.slot] + '"></span><span id="infoOwner"></span>' : '') + '</div></div>';
|
||||
'<div class="desc"></div><div class="kv"></div><div class="actions">' +
|
||||
(wall ? '' : '<button type="button" data-act="up"><svg class="ic"><use href="#i-up"/></svg><span class="w"></span><span class="cost" id="upCost"></span></button>') +
|
||||
'<button type="button" data-act="sell" class="danger"><svg class="ic"><use href="#i-trash"/></svg><span class="w">Sell</span><span class="cost"></span></button>' +
|
||||
(wall ? '' : '<button type="button" data-act="mode" title="Which packet to shoot"><svg class="ic"><use href="#i-target"/></svg><span class="w">Target:</span><span class="mv"></span></button>') +
|
||||
'<button type="button" data-act="close" class="icon" aria-label="Close" title="Close"><svg class="ic"><use href="#i-x"/></svg></button></div>' +
|
||||
'<div class="byline">' + (wall ? '' : '<span id="infoKills"></span>') + (ownerP ? '<span class="dot" style="background:' + NW.SLOT_COLORS[ownerP.slot] + '"></span><span id="infoOwner"></span>' : '') + '</div></div>';
|
||||
box.querySelector('.nm').textContent = def.name;
|
||||
box.querySelector('.lv').textContent = tower.type === 'wall' ? '' : 'Level ' + tower.level + ' / ' + def.levels.length;
|
||||
box.querySelector('.desc').textContent = def.desc;
|
||||
if (ownerP) box.querySelector('#infoOwner').textContent = 'Built by ' + ownerP.name;
|
||||
NW.drawIcon(box.querySelector('canvas'), tower.type, tower.level);
|
||||
syncInfo();
|
||||
} else {
|
||||
const def = TD.TOWERS[app.selType];
|
||||
let kv = '';
|
||||
|
|
@ -270,23 +298,65 @@
|
|||
NW.drawIcon(box.querySelector('canvas'), app.selType, 1);
|
||||
}
|
||||
}
|
||||
function updateInfoDynamic() {
|
||||
// numbers of the selected tower: only text/disabled changes, never a replaced element
|
||||
function syncInfo() {
|
||||
if (!app.selTower) return;
|
||||
const t = app.ctrl.view.towers.find((x) => x.id === app.selTower);
|
||||
if (!t) return;
|
||||
const k = $('infoKills'); if (k) k.textContent = t.kills + (t.kills === 1 ? ' kill' : ' kills');
|
||||
const def = TD.TOWERS[t.type];
|
||||
const up = $('info').querySelector('[data-act="up"]');
|
||||
if (up && t.level < def.levels.length) up.disabled = app.ctrl.view.gold < def.levels[t.level].cost;
|
||||
const box = $('info'), view = app.ctrl.view, t = view.towers.find((x) => x.id === app.selTower);
|
||||
if (!t || !box.firstChild) return;
|
||||
const def = TD.TOWERS[t.type], wall = t.type === 'wall', i = t.level - 1;
|
||||
const canUp = t.level < def.levels.length, upCost = canUp ? def.levels[t.level].cost : 0;
|
||||
const affordable = canUp && view.gold >= upCost;
|
||||
const sellVal = def.refund ? t.spent : Math.floor(t.spent * TD.SELL_RATIO);
|
||||
const sig = t.level + ':' + t.mode + ':' + sellVal + ':' + t.kills + ':' + (affordable ? 1 : 0);
|
||||
if (sig === info.sig) return;
|
||||
info.sig = sig;
|
||||
const setText = (el, v) => { if (el && el.textContent !== v) el.textContent = v; };
|
||||
if (info.lv !== t.level) { // level changed: stats table and icon
|
||||
info.lv = t.level;
|
||||
const cur = statsFor(t.type, i), nxt = canUp ? statsFor(t.type, i + 1) : null;
|
||||
let kv = '';
|
||||
cur.forEach((row, k) => {
|
||||
const n = nxt && nxt[k] && nxt[k][1] !== row[1] ? ' <span class="up">→ ' + nxt[k][1] + '</span>' : '';
|
||||
kv += '<div class="kvp"><span>' + row[0] + '</span><span>' + row[1] + n + '</span></div>';
|
||||
});
|
||||
if (!wall) kv += '<div class="kvp"><span>Targets</span><span>' + targetsText(def) + '</span></div>';
|
||||
box.querySelector('.kv').innerHTML = kv;
|
||||
setText(box.querySelector('.lv'), wall ? '' : 'Level ' + t.level + ' / ' + def.levels.length);
|
||||
NW.drawIcon(box.querySelector('canvas'), t.type, t.level);
|
||||
}
|
||||
const up = box.querySelector('[data-act="up"]');
|
||||
if (up) {
|
||||
setText(up.querySelector('.w'), canUp ? 'Upgrade' : 'Max level');
|
||||
setText(up.querySelector('.cost'), canUp ? String(upCost) : '');
|
||||
up.disabled = !affordable;
|
||||
up.setAttribute('aria-label', canUp ? 'Upgrade for ' + upCost + ' credits' : 'Max level');
|
||||
}
|
||||
const sell = box.querySelector('[data-act="sell"]');
|
||||
setText(sell.querySelector('.cost'), String(sellVal));
|
||||
sell.setAttribute('aria-label', 'Sell for ' + sellVal + ' credits');
|
||||
const mode = box.querySelector('[data-act="mode"]');
|
||||
if (mode) { setText(mode.querySelector('.mv'), MODE_NAMES[t.mode]); mode.setAttribute('aria-label', 'Target: ' + MODE_NAMES[t.mode] + '. Tap to change'); }
|
||||
setText(box.querySelector('#infoKills'), t.kills + (t.kills === 1 ? ' kill' : ' kills'));
|
||||
}
|
||||
let infoTimer = 0;
|
||||
$('info').addEventListener('pointerdown', () => { clearTimeout(infoTimer); info.pressed = true; }); // (a new press cancels the previous release timer)
|
||||
const infoRelease = () => {
|
||||
if (!info.pressed) return;
|
||||
clearTimeout(infoTimer);
|
||||
infoTimer = setTimeout(() => { info.pressed = false; if (info.dirty) renderInfo(false); }, 90); // after the click has been delivered
|
||||
};
|
||||
document.addEventListener('pointerup', infoRelease, true);
|
||||
document.addEventListener('pointercancel', infoRelease, true);
|
||||
$('info').addEventListener('click', (e) => {
|
||||
const btn = e.target.closest('button[data-act]'); if (!btn || !app.selTower) return;
|
||||
info.pressed = false;
|
||||
const ctrl = app.ctrl, tower = ctrl.view.towers.find((t) => t.id === app.selTower);
|
||||
if (!tower) return;
|
||||
Audio.sfx('click');
|
||||
switch (btn.dataset.act) {
|
||||
case 'up': ctrl.send({ c: 'upgrade', id: tower.id }); break;
|
||||
case 'sell': ctrl.send({ c: 'sell', id: tower.id }); app.selTower = 0; renderInfo(true); app.previewDirty = true; break;
|
||||
case 'close': selectTower(0); break;
|
||||
case 'mode': {
|
||||
const modes = TD.TARGET_MODES; ctrl.send({ c: 'target', id: tower.id, mode: modes[(modes.indexOf(tower.mode) + 1) % modes.length] });
|
||||
break;
|
||||
|
|
@ -308,7 +378,7 @@
|
|||
for (const g of sum) {
|
||||
const d = TD.ENEMIES[g.k];
|
||||
if (d.air) air = true;
|
||||
html += '<span class="e"><i style="background:' + d.color + '"></i>' + g.c + '× ' + d.name + '</span>';
|
||||
html += '<span class="e" title="' + d.name + (d.air ? ' (flies)' : '') + '"><i class="sh-' + g.k + '" style="--c:' + d.color + '"></i>' + g.c + '× ' + d.name + '</span>';
|
||||
}
|
||||
if (air) html += '<span class="tag air">AIR</span>';
|
||||
if (n % 10 === 0) html += '<span class="tag boss">BOSS</span>';
|
||||
|
|
@ -328,7 +398,7 @@
|
|||
}
|
||||
app.prevPlayers = list.map((p) => Object.assign({}, p));
|
||||
renderPlayers();
|
||||
if (ctrl.kind === 'remote') renderInfo(true);
|
||||
if (ctrl.kind === 'remote') renderInfo(false); // the shape includes the owner, so only a changed roster rebuilds
|
||||
}
|
||||
function renderPlayers() {
|
||||
const ctrl = app.ctrl, box = $('players');
|
||||
|
|
@ -379,7 +449,12 @@
|
|||
if (L.attn !== attn) { L.attn = attn; $('btnWave').classList.toggle('attn', attn); }
|
||||
if (L.auto !== view.auto) { L.auto = view.auto; $('btnAuto').setAttribute('aria-pressed', view.auto ? 'true' : 'false'); }
|
||||
if (L.speed !== view.speed) { L.speed = view.speed; $('speedText').textContent = view.speed + '×'; }
|
||||
if (L.paused !== view.paused) { L.paused = view.paused; $('pausedTag').hidden = !view.paused; $('btnPause').innerHTML = '<svg class="ic"><use href="#i-' + (view.paused ? 'play' : 'pause') + '"/></svg>'; $('btnPause').setAttribute('aria-label', view.paused ? 'Resume' : 'Pause'); }
|
||||
if (L.paused !== view.paused) { // paused: dimmed board, a resume pill, and an amber pressed pause button (not a second play triangle)
|
||||
L.paused = view.paused; $('pausedTag').hidden = !view.paused; $('stage').classList.toggle('paused', !!view.paused);
|
||||
$('btnPause').setAttribute('aria-pressed', view.paused ? 'true' : 'false'); $('btnPause').setAttribute('aria-label', view.paused ? 'Resume' : 'Pause');
|
||||
}
|
||||
const offline = !$('reconnect').hidden;
|
||||
if (L.offline !== offline) { L.offline = offline; $('app').classList.toggle('offline', offline); }
|
||||
if (L.muted !== Audio.muted) { L.muted = Audio.muted; $('btnSound').innerHTML = '<svg class="ic"><use href="#i-' + (Audio.muted ? 'mute' : 'sound') + '"/></svg>'; }
|
||||
// palette affordability
|
||||
const gold = view.gold;
|
||||
|
|
@ -391,11 +466,16 @@
|
|||
const chip = $('netChip');
|
||||
chip.hidden = false;
|
||||
$('netRoom').textContent = ctrl.room || '';
|
||||
const alone = ctrl.players.length < 2;
|
||||
if (L.alone !== alone || L.room !== ctrl.room) {
|
||||
L.alone = alone; L.room = ctrl.room; chip.classList.toggle('waiting', alone);
|
||||
chip.setAttribute('aria-label', 'Co-op room ' + (ctrl.room || '') + (alone ? '. Waiting for a partner: tap to invite them' : '. Tap to invite your partner'));
|
||||
}
|
||||
const p = ctrl.rtt ? ctrl.rtt + ' ms' : '';
|
||||
if (L.ping !== p) { L.ping = p; $('netPing').textContent = p; chip.classList.toggle('bad', ctrl.rtt > 220); const pp = $('plPing'); if (pp) pp.textContent = p ? '\u00b7 ' + p : ''; }
|
||||
}
|
||||
renderWavePanel(view);
|
||||
updateInfoDynamic();
|
||||
syncInfo();
|
||||
}
|
||||
|
||||
function endScreen(view) {
|
||||
|
|
@ -457,19 +537,62 @@
|
|||
function updateConfirm() {
|
||||
const show = !!(app.pending && app.selType && app.selType !== 'wall');
|
||||
$('confirm').hidden = !show;
|
||||
if (show) {
|
||||
$('confirmText').textContent = 'Build · ' + TD.TOWERS[app.selType].levels[0].cost;
|
||||
// keep the bar clear of the cell being placed: show it on the opposite half of the stage
|
||||
const p = renderer.cellToScreen(app.pending.x, app.pending.y);
|
||||
$('confirm').classList.toggle('top', p.y > $('stage').clientHeight * 0.5);
|
||||
}
|
||||
if (show) { const cost = TD.TOWERS[app.selType].levels[0].cost; $('confirmText').textContent = 'Build · ' + cost; $('btnConfirmBuild').setAttribute('aria-label', 'Build for ' + cost + ' credits'); hint(hintText, hintKind); }
|
||||
else if (!ptrs.size) clearCursor(); // (no pending cell, no finger down: the partner's view of our touch cursor goes)
|
||||
layoutBars(true);
|
||||
}
|
||||
$('btnConfirmBuild').addEventListener('click', () => { if (app.pending && placeAt(app.pending)) { app.pending = null; updateConfirm(); } });
|
||||
// Where the floating bars go (the touch confirm bar and the selected-tower action bar): on the half of the stage away from the
|
||||
// cell they act on, so they never cover it. Runs every frame (cheap, writes only on change) so rotation, resize, pan and zoom
|
||||
// keep it right (touch-14). The stage rectangle goes into CSS variables because the tower bar is position:fixed.
|
||||
// The bar does not hop to the other half while the same cell is being worked on (nudging across the middle must not move the buttons
|
||||
// out from under the thumb): it flips only when the cell would end up under it.
|
||||
let barKey = '', barSide = '', barSubject = '';
|
||||
function layoutBars(force) {
|
||||
const r = $('stage').getBoundingClientRect(), a = $('app'), conf = !$('confirm').hidden && !!app.pending;
|
||||
let cell = null;
|
||||
if (conf) cell = app.pending;
|
||||
else if (app.selTower && app.ctrl) cell = app.ctrl.view.towers.find((t) => t.id === app.selTower) || null;
|
||||
let side = '';
|
||||
if (cell) {
|
||||
const sp = renderer.cellToScreen(cell.x, cell.y), bar = conf ? $('confirm') : $('info').querySelector('.actions');
|
||||
const guard = (bar ? bar.offsetHeight : 54) + 8 + renderer.cellSizePx() / 2 + 8; // the strip a bar there would cover, plus the cell itself
|
||||
const hit = (s) => (s === 'top' ? sp.y < guard : sp.y > r.height - guard);
|
||||
const subject = conf ? 'pending' : 'tower' + app.selTower;
|
||||
const mid = sp.y > r.height * 0.5 ? 'top' : 'bottom', other = mid === 'top' ? 'bottom' : 'top';
|
||||
side = subject === barSubject && barSide && !hit(barSide) ? barSide : hit(mid) && !hit(other) ? other : mid;
|
||||
barSubject = subject; barSide = side;
|
||||
} else { barSubject = ''; barSide = ''; }
|
||||
const key = side + '|' + (conf ? 1 : 0) + '|' + Math.round(r.left) + ',' + Math.round(r.top) + ',' + Math.round(r.width) + ',' + Math.round(r.height);
|
||||
if (!force && key === barKey) return;
|
||||
barKey = key;
|
||||
const st = a.style;
|
||||
st.setProperty('--st-l', r.left.toFixed(1) + 'px'); st.setProperty('--st-t', r.top.toFixed(1) + 'px');
|
||||
st.setProperty('--st-w', r.width.toFixed(1) + 'px'); st.setProperty('--st-h', r.height.toFixed(1) + 'px');
|
||||
if (side) a.dataset.bar = side; else delete a.dataset.bar;
|
||||
if (conf) a.dataset.conf = '1'; else delete a.dataset.conf; // the build bar is taller than the tower bar (it has the nudge row)
|
||||
a.dataset.barrows = r.width >= 484 ? '1' : r.height >= 262 ? '2' : '0'; // build bar: nudge buttons in the bar's row on a wide stage, a second row on a phone, no text at all on a tiny one
|
||||
a.dataset.barw = r.width < 440 ? 's' : 'm'; // narrow stage: the bar drops the words, keeps icons + numbers
|
||||
$('confirm').classList.toggle('top', side === 'top');
|
||||
}
|
||||
$('btnConfirmBuild').addEventListener('click', () => { if (app.pending && placeAt(app.pending)) setPending(null); });
|
||||
$('btnCancelBuild').addEventListener('click', () => { selectType(null); });
|
||||
|
||||
// ------------------------------------------------------------------ pointer input
|
||||
// Touch rules. pointerdown never builds and never selects: every pinch starts with one finger down. A TAP (the finger stays within
|
||||
// TAP_SLOP of where it landed and lifts before the long press) acts on the cell it LANDED on, when it lifts. A DRAG acts as soon as it
|
||||
// passes the slop: it paints a Firewall line, aims the pending turret, or pans a zoomed board. A second finger turns the whole gesture
|
||||
// into pinch/pan and undoes whatever the first finger had begun; extra fingers (a palm) are ignored. A long press pings the map,
|
||||
// whatever is armed, and never builds. Cells are only 12 to 20 px on a phone, which is why the build bar also has nudge buttons.
|
||||
const TAP_SLOP = 10, MOUSE_SLOP = 8, LONG_MS = 520;
|
||||
const ptrs = new Map();
|
||||
let painting = false, paintCell = null, panning = false, longT = 0, longFired = false, rightDown = null, prevPending = null, pinch = null;
|
||||
let painting = false, paintCell = null, panning = false, longT = 0, longFired = false, rightDown = null, pinch = null;
|
||||
let multi = false; // a second finger landed: pinch/pan owns the gesture until every finger is up
|
||||
let tg = null; // the one-finger touch gesture in progress: { id, cell (where it landed), pend (pending cell then), hover0, dragged }
|
||||
let tapSelectOnUp = false;
|
||||
let tapTowerId = 0; // a wall stroke that began on a turret: a stationary click or tap selects that turret instead (touch-17)
|
||||
let pendFree = true; // the pending cell held no tower when it was chosen (a tower appearing there later is the partner's, coop-7)
|
||||
let curSent = false; // a touch cursor is showing on the partner's board
|
||||
let strokeErr = false; // this wall stroke already played its error sound (touch-16)
|
||||
|
||||
function cancelLong() { clearTimeout(longT); longT = 0; }
|
||||
function setHover(cell) {
|
||||
|
|
@ -478,6 +601,50 @@
|
|||
if (c && app.hover && c.x === app.hover.x && c.y === app.hover.y) return;
|
||||
app.hover = c; app.previewDirty = true;
|
||||
}
|
||||
// The partner's view of where this touch is aiming. `force` skips the 70 ms throttle (the last position must get through).
|
||||
function touchCursor(cell, force) {
|
||||
if (!cell || !app.ctrl.board.inBounds(cell.x, cell.y)) return;
|
||||
app.ctrl.sendCursor(cell.x + 0.5, cell.y + 0.5, force); curSent = true;
|
||||
}
|
||||
function clearCursor() { if (curSent) { curSent = false; app.ctrl.sendCursor(null, null); } }
|
||||
// The only way the touch-pending build cell changes. An off-board cell is no cell (code-23).
|
||||
function setPending(cell, commit) {
|
||||
const c = cell && app.ctrl.board.inBounds(cell.x, cell.y) ? { x: cell.x, y: cell.y } : null;
|
||||
app.pending = c; pendFree = !c || !towerAtCell(c); app.previewDirty = true;
|
||||
if (c) { setHover(c); touchCursor(c, commit); }
|
||||
updateConfirm();
|
||||
}
|
||||
// the finger-down preview ends without a commit (long press, second finger, cancel): hover goes back, the touch cursor goes away
|
||||
function unaim() {
|
||||
if (tg) { app.hover = tg.hover0; app.previewDirty = true; }
|
||||
if (!app.pending) clearCursor();
|
||||
}
|
||||
function abortTouch() { // forget what the first finger began: a second finger landed, or the touch was cancelled
|
||||
cancelLong(); painting = false; paintCell = null; tapSelectOnUp = false; tapTowerId = 0; longFired = false;
|
||||
if (tg) { if (tg.dragged) setPending(tg.pend); unaim(); tg = null; }
|
||||
}
|
||||
function startStroke(cell) { painting = true; paintCell = cell; strokeErr = false; }
|
||||
function seedPinch() { // pinch/pan between the first two fingers only; the pair is re-seeded when one of them lifts
|
||||
const ids = [...ptrs.keys()].slice(0, 2), a = ptrs.get(ids[0]), b = ptrs.get(ids[1]);
|
||||
pinch = { ids, d: Math.hypot(a.x - b.x, a.y - b.y) || 1, mx: (a.x + b.x) / 2, my: (a.y + b.y) / 2 };
|
||||
}
|
||||
// nudge buttons: move the pending cell one cell in a screen direction (rotation-safe), and keep it in view when zoomed in
|
||||
function nudge(dx, dy) {
|
||||
const p = app.pending; if (!p) return;
|
||||
const c = renderer.stepCell(p.x, p.y, dx, dy);
|
||||
if (!app.ctrl.board.inBounds(c.x, c.y)) return; // the edge of the board: stay put
|
||||
setPending(c, true);
|
||||
if (renderer.zoom > 1.01) {
|
||||
const s = renderer.cellToScreen(c.x, c.y), m = renderer.cellSizePx() * 1.5;
|
||||
const mx = s.x < m ? m - s.x : s.x > renderer.W - m ? renderer.W - m - s.x : 0, my = s.y < m ? m - s.y : s.y > renderer.H - m ? renderer.H - m - s.y : 0;
|
||||
if (mx || my) { renderer.panBy(mx, my); updateFit(); }
|
||||
}
|
||||
}
|
||||
$('nudge').addEventListener('click', (e) => {
|
||||
const b = e.target.closest('button[data-dx]'); if (!b) return;
|
||||
Audio.sfx('click'); nudge(+b.dataset.dx, +b.dataset.dy);
|
||||
});
|
||||
|
||||
function paintLine(from, to) { // place on every cell crossed by a fast drag (Bresenham)
|
||||
let x0 = from.x, y0 = from.y; const x1 = to.x, y1 = to.y;
|
||||
const dx = Math.abs(x1 - x0), dy = -Math.abs(y1 - y0), sx = x0 < x1 ? 1 : -1, sy = y0 < y1 ? 1 : -1;
|
||||
|
|
@ -511,47 +678,42 @@
|
|||
e.preventDefault();
|
||||
try { canvas.setPointerCapture(e.pointerId); } catch (err) { /* ignore */ }
|
||||
Audio.unlock();
|
||||
const touch = e.pointerType !== 'mouse';
|
||||
if (touch && e.isPrimary) { ptrs.clear(); abortTouch(); multi = false; pinch = null; } // (a lost pointerup must never leave half a gesture behind)
|
||||
const r = canvas.getBoundingClientRect(), sx = e.clientX - r.left, sy = e.clientY - r.top;
|
||||
ptrs.set(e.pointerId, { x: sx, y: sy, sx, sy, type: e.pointerType, moved: false, btn: e.button });
|
||||
if (ptrs.size === 2) { // second finger: pinch/pan, abandon whatever the first finger started
|
||||
cancelLong(); painting = false; tapSelectOnUp = false;
|
||||
const [a, b] = [...ptrs.values()];
|
||||
pinch = { d: Math.hypot(a.x - b.x, a.y - b.y) || 1, mx: (a.x + b.x) / 2, my: (a.y + b.y) / 2 };
|
||||
if (ptrs.size >= 2) { // second finger: pinch/pan; whatever the first finger had begun is undone, a third finger is ignored
|
||||
if (!multi) { multi = true; abortTouch(); }
|
||||
if (!pinch) seedPinch();
|
||||
return;
|
||||
}
|
||||
if (ptrs.size > 2) return;
|
||||
const cell = renderer.screenToCell(sx, sy);
|
||||
longFired = false;
|
||||
if (e.pointerType === 'mouse') {
|
||||
if (!touch) {
|
||||
if (e.button === 2) { rightDown = { x: sx, y: sy, moved: false }; return; }
|
||||
if (e.button === 1) { panning = true; return; }
|
||||
if (e.altKey) { markAt(cell); return; }
|
||||
const ex = towerAtCell(cell);
|
||||
if (app.selType && ex && !(app.selType === 'wall' && ex.type === 'wall')) { selectTower(ex.id); Audio.sfx('click'); }
|
||||
if (app.selType === 'wall' && ex && ex.type !== 'wall') { setHover(cell); startStroke(cell); tapTowerId = ex.id; } // a Firewall stroke may start on a turret; a plain click selects it
|
||||
else if (app.selType && ex && !(app.selType === 'wall' && ex.type === 'wall')) { selectTower(ex.id); Audio.sfx('click'); }
|
||||
else if (app.selType) {
|
||||
setHover(cell);
|
||||
if (!ex) placeAt(cell);
|
||||
if (app.selType === 'wall') { painting = true; paintCell = cell; }
|
||||
if (app.selType === 'wall') startStroke(cell);
|
||||
} else {
|
||||
tapSelectOnUp = true; panning = renderer.zoom > 1.01;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// touch / pen
|
||||
prevPending = app.pending ? { x: app.pending.x, y: app.pending.y } : null;
|
||||
const ex = towerAtCell(cell);
|
||||
if (app.selType && ex && !(app.selType === 'wall' && ex.type === 'wall')) {
|
||||
selectTower(ex.id); Audio.sfx('click');
|
||||
} else if (app.selType === 'wall') {
|
||||
setHover(cell); if (!ex) placeAt(cell); painting = true; paintCell = cell;
|
||||
} else if (app.selType) {
|
||||
app.pending = { x: cell.x, y: cell.y }; setHover(cell); updateConfirm();
|
||||
} else {
|
||||
tapSelectOnUp = true;
|
||||
longT = setTimeout(() => { longFired = true; tapSelectOnUp = false; markAt(cell); }, 520);
|
||||
}
|
||||
// touch / pen: remember what is under the finger and preview it; commit nothing until the finger lifts or drags
|
||||
tg = { id: e.pointerId, cell, pend: app.pending ? { x: app.pending.x, y: app.pending.y } : null, hover0: app.hover, dragged: false };
|
||||
if (app.selType) { setHover(cell); touchCursor(cell); }
|
||||
tapSelectOnUp = !app.selType;
|
||||
longT = setTimeout(() => { // a long press pings the map, whatever is armed
|
||||
longT = 0; if (!tg || multi || tg.id !== e.pointerId) return;
|
||||
longFired = true; tapSelectOnUp = false; unaim(); markAt(tg.cell);
|
||||
}, LONG_MS);
|
||||
});
|
||||
let tapSelectOnUp = false;
|
||||
|
||||
canvas.addEventListener('pointermove', (e) => {
|
||||
const r = canvas.getBoundingClientRect(), sx = e.clientX - r.left, sy = e.clientY - r.top;
|
||||
|
|
@ -567,9 +729,10 @@
|
|||
}
|
||||
const dx = sx - p.x, dy = sy - p.y;
|
||||
p.x = sx; p.y = sy;
|
||||
if (Math.hypot(sx - p.sx, sy - p.sy) > 8) p.moved = true;
|
||||
if (ptrs.size === 2 && pinch) {
|
||||
const [a, b] = [...ptrs.values()];
|
||||
if (Math.hypot(sx - p.sx, sy - p.sy) > (e.pointerType === 'mouse' ? MOUSE_SLOP : TAP_SLOP)) p.moved = true;
|
||||
if (pinch) {
|
||||
if (!pinch.ids.includes(e.pointerId)) return; // a third finger (palm) neither pans nor zooms
|
||||
const a = ptrs.get(pinch.ids[0]), b = ptrs.get(pinch.ids[1]); if (!a || !b) return;
|
||||
const d = Math.hypot(a.x - b.x, a.y - b.y) || 1, mx = (a.x + b.x) / 2, my = (a.y + b.y) / 2;
|
||||
renderer.panBy(mx - pinch.mx, my - pinch.my);
|
||||
renderer.setZoom(renderer.zoom * d / pinch.d, mx, my);
|
||||
|
|
@ -577,50 +740,76 @@
|
|||
updateFit();
|
||||
return;
|
||||
}
|
||||
if (multi) return; // one finger of a pinch is still down: it must not paint, aim or pan
|
||||
const cell = renderer.screenToCell(sx, sy);
|
||||
if (e.pointerType === 'mouse') {
|
||||
if (rightDown) { if (Math.hypot(sx - rightDown.x, sy - rightDown.y) > 5) rightDown.moved = true; if (rightDown.moved) { renderer.panBy(dx, dy); updateFit(); } rightDown.x = rightDown.moved ? sx : rightDown.x; return; }
|
||||
if (panning && p.moved) { renderer.panBy(dx, dy); updateFit(); tapSelectOnUp = false; return; }
|
||||
setHover(cell);
|
||||
app.ctrl.sendCursor(cell.fx, cell.fy);
|
||||
if (painting && app.selType === 'wall' && paintCell && (cell.x !== paintCell.x || cell.y !== paintCell.y)) { paintLine(paintCell, cell); paintCell = cell; }
|
||||
if (painting && app.selType === 'wall' && paintCell && (cell.x !== paintCell.x || cell.y !== paintCell.y)) { tapTowerId = 0; paintLine(paintCell, cell); paintCell = cell; }
|
||||
return;
|
||||
}
|
||||
// touch / pen
|
||||
if (p.moved) { cancelLong(); tapSelectOnUp = tapSelectOnUp && !p.moved; }
|
||||
if (painting && app.selType === 'wall') {
|
||||
if (!tg || tg.id !== e.pointerId || !p.moved) return; // inside the tap slop it is still a tap: nothing moves
|
||||
cancelLong(); tapSelectOnUp = false;
|
||||
if (app.selType === 'wall') {
|
||||
if (!painting) { // the stroke starts here; paintLine skips its first cell, so the origin goes in now (unless a tower is on it)
|
||||
startStroke(tg.cell);
|
||||
if (!towerAtCell(tg.cell)) placeAt(tg.cell);
|
||||
}
|
||||
setHover(cell);
|
||||
if (paintCell && (cell.x !== paintCell.x || cell.y !== paintCell.y)) { paintLine(paintCell, cell); paintCell = cell; }
|
||||
} else if (app.selType) {
|
||||
app.pending = { x: cell.x, y: cell.y }; setHover(cell); updateConfirm();
|
||||
app.ctrl.sendCursor(cell.fx, cell.fy);
|
||||
} else if (p.moved && renderer.zoom > 1.01) {
|
||||
if (cell.x !== paintCell.x || cell.y !== paintCell.y) { paintLine(paintCell, cell); paintCell = cell; }
|
||||
} else if (app.selType) { // aim: the pending cell follows the finger (off the board it stays on the last cell)
|
||||
if (app.ctrl.board.inBounds(cell.x, cell.y)) { tg.dragged = true; setPending(cell); }
|
||||
} else if (renderer.zoom > 1.01) {
|
||||
renderer.panBy(dx, dy); updateFit();
|
||||
}
|
||||
});
|
||||
|
||||
function endPointer(e) {
|
||||
const p = ptrs.get(e.pointerId);
|
||||
const p = ptrs.get(e.pointerId), cancelled = e.type === 'pointercancel';
|
||||
ptrs.delete(e.pointerId);
|
||||
try { canvas.releasePointerCapture(e.pointerId); } catch (err) { /* ignore */ }
|
||||
if (!p || !app.inGame) return;
|
||||
if (!p || !app.inGame) { if (!ptrs.size) { multi = false; pinch = null; } return; }
|
||||
cancelLong();
|
||||
if (ptrs.size < 2) pinch = null;
|
||||
const r = canvas.getBoundingClientRect(), cell = renderer.screenToCell(e.clientX - r.left, e.clientY - r.top);
|
||||
if (e.pointerType === 'mouse') {
|
||||
const r = canvas.getBoundingClientRect(), cell = renderer.screenToCell(e.clientX - r.left, e.clientY - r.top);
|
||||
if (e.button === 2 && rightDown) { if (!rightDown.moved) { selectType(null); selectTower(0); } rightDown = null; return; }
|
||||
if (e.button === 1) { panning = false; return; }
|
||||
if (tapSelectOnUp && !p.moved && e.type === 'pointerup') tapSelect(cell);
|
||||
tapSelectOnUp = false; painting = false; panning = false;
|
||||
if (tapTowerId && !p.moved && e.type === 'pointerup') { selectTower(tapTowerId); Audio.sfx('click'); }
|
||||
tapSelectOnUp = false; tapTowerId = 0; painting = false; panning = false;
|
||||
return;
|
||||
}
|
||||
if (e.type === 'pointercancel') { painting = false; tapSelectOnUp = false; return; }
|
||||
if (painting) { painting = false; return; }
|
||||
if (ptrs.size > 0) return; // lifted one finger of a pinch
|
||||
if (app.selType && app.pending && !p.moved && prevPending && prevPending.x === app.pending.x && prevPending.y === app.pending.y) {
|
||||
if (placeAt(app.pending)) { app.pending = null; updateConfirm(); } // tapping the previewed cell again builds
|
||||
} else if (!app.selType && tapSelectOnUp && !p.moved && !longFired) tapSelect(cell);
|
||||
// touch / pen
|
||||
if (pinch && pinch.ids.includes(e.pointerId)) { if (ptrs.size >= 2) seedPinch(); else pinch = null; }
|
||||
const wasMulti = multi;
|
||||
if (!ptrs.size) multi = false;
|
||||
if (wasMulti) return; // the end of a pinch/pan is never a tap
|
||||
const g = tg;
|
||||
if (!g || g.id !== e.pointerId) return;
|
||||
if (cancelled) { abortTouch(); return; } // pointercancel: no action, nothing half done
|
||||
tg = null;
|
||||
const wasPainting = painting; painting = false; paintCell = null;
|
||||
if (wasPainting || p.moved || longFired) { // a stroke, an aim drag, a pan or a long press: lifting the finger adds nothing
|
||||
tapSelectOnUp = false;
|
||||
if (longFired) unaim(); else if (!app.pending) clearCursor();
|
||||
return;
|
||||
}
|
||||
// a tap, on the cell the finger landed on (not wherever it drifted to)
|
||||
const cell = g.cell, ex = towerAtCell(cell);
|
||||
if (app.selType === 'wall') {
|
||||
if (ex && ex.type !== 'wall') { selectTower(ex.id); Audio.sfx('click'); } // (a drag that starts on a turret is a stroke: it keeps the tool)
|
||||
else if (!ex) placeAt(cell);
|
||||
} else if (app.selType) {
|
||||
if (ex) { selectTower(ex.id); Audio.sfx('click'); }
|
||||
else if (!app.ctrl.board.inBounds(cell.x, cell.y)) setPending(null);
|
||||
else if (g.pend && g.pend.x === cell.x && g.pend.y === cell.y) { if (placeAt(cell)) setPending(null); } // tapping the previewed cell again builds
|
||||
else setPending(cell, true);
|
||||
} else if (tapSelectOnUp) tapSelect(cell);
|
||||
tapSelectOnUp = false;
|
||||
if (!app.pending) clearCursor();
|
||||
}
|
||||
canvas.addEventListener('pointerup', endPointer);
|
||||
canvas.addEventListener('pointercancel', endPointer);
|
||||
|
|
@ -629,9 +818,13 @@
|
|||
if (!app.inGame) return;
|
||||
e.preventDefault();
|
||||
const r = canvas.getBoundingClientRect();
|
||||
renderer.setZoom(renderer.zoom * (e.deltaY < 0 ? 1.15 : 1 / 1.15), e.clientX - r.left, e.clientY - r.top);
|
||||
// proportional to the scroll distance (a mouse notch is about the old 1.15x; a trackpad glides). ctrl+wheel is a trackpad pinch: much smaller deltas.
|
||||
const dy = clamp(e.deltaY * (e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? 400 : 1), -300, 300);
|
||||
renderer.setZoom(renderer.zoom * Math.exp(-dy * (e.ctrlKey ? 0.01 : 0.0015)), e.clientX - r.left, e.clientY - r.top);
|
||||
updateFit();
|
||||
}, { passive: false });
|
||||
// (the window lost focus mid-gesture: the pointerup may never arrive)
|
||||
root.addEventListener('blur', () => { ptrs.clear(); abortTouch(); multi = false; pinch = null; rightDown = null; panning = false; });
|
||||
|
||||
function updateFit() {
|
||||
const z = renderer.zoom > 1.02;
|
||||
|
|
@ -643,12 +836,15 @@
|
|||
root.addEventListener('keydown', (e) => {
|
||||
if (e.target && (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA')) return;
|
||||
if (e.ctrlKey || e.metaKey) return;
|
||||
if (e.repeat) return; // holding a key is one press: Space must not start 20 waves (code-6)
|
||||
if (!app.inGame) return;
|
||||
if (document.querySelector('.overlay:not([hidden])')) { if (e.key === 'Escape') { closeOverlayToGame(); } return; }
|
||||
const ctrl = app.ctrl, view = ctrl.view;
|
||||
const k = e.key.toLowerCase();
|
||||
const idx = '123456'.indexOf(k);
|
||||
if (idx >= 0 && k.length === 1) { selectType(app.selType === TD.TOWER_ORDER[idx] ? null : TD.TOWER_ORDER[idx]); Audio.sfx('click'); e.preventDefault(); return; }
|
||||
// Space / Enter on a focused button or link press THAT control (keyboard users), not the next-wave hotkey (code-8)
|
||||
if ((k === ' ' || k === 'enter') && e.target && e.target.closest && e.target.closest('button, a, select, [role="button"]')) return;
|
||||
const keyType = k.length === 1 ? TD.TOWER_ORDER.find((t) => TD.TOWERS[t].key === k) : null; // 1-9, 0: one key per tower in the palette
|
||||
if (keyType) { selectType(app.selType === keyType ? null : keyType); Audio.sfx('click'); e.preventDefault(); return; }
|
||||
switch (k) {
|
||||
case 'escape': case 'q': selectType(null); selectTower(0); app.pending = null; updateConfirm(); break;
|
||||
case ' ': case 'enter': ctrl.send({ c: 'wave' }); e.preventDefault(); break;
|
||||
|
|
@ -673,6 +869,8 @@
|
|||
$('btnPause').addEventListener('click', () => { Audio.sfx('click'); app.ctrl.ctl('pause', !app.ctrl.view.paused); });
|
||||
$('btnSound').addEventListener('click', () => { Audio.unlock(); Audio.toggleMuted(); Audio.sfx('click'); });
|
||||
$('btnMenu').addEventListener('click', () => { Audio.sfx('click'); openMenu(); });
|
||||
$('pausedTag').addEventListener('click', () => { Audio.sfx('click'); app.ctrl.ctl('pause', false); });
|
||||
$('netChip').addEventListener('click', () => { if (app.ctrl && app.ctrl.kind === 'remote') { Audio.sfx('click'); invite(); } }); // room code chip: tap to invite
|
||||
|
||||
// ------------------------------------------------------------------ menu / lobby
|
||||
function buildMapPicker() {
|
||||
|
|
@ -818,13 +1016,45 @@
|
|||
}
|
||||
document.addEventListener('visibilitychange', () => { if (!document.hidden && app.inGame) requestWakeLock(); });
|
||||
|
||||
// ------------------------------------------------------------------ app layout (the JS half of the layout modes in style.css)
|
||||
const mq = (q) => (root.matchMedia ? root.matchMedia(q) : { matches: false, addEventListener() {} });
|
||||
const mqStacked = mq('(orientation: portrait), (max-width: 760px) and (min-height: 521px)');
|
||||
const mqCompact = mq('(pointer: coarse), (orientation: portrait), (max-width: 760px) and (min-height: 521px), (orientation: landscape) and (max-height: 520px)');
|
||||
// Stacked (portrait / narrow) layout: the stage hugs the board, so there is no dead band above and below it and the side panel gets
|
||||
// everything else. The board is drawn turned 90 degrees when that makes the cells clearly bigger (tall phones), otherwise upright
|
||||
// and short (small phones: the freed height goes to the palette and info panel). Inputs are the viewport and top bar only (never
|
||||
// the stage's own size), so this cannot feed back into the ResizeObserver.
|
||||
function layoutApp() {
|
||||
const a = $('app'), b = app.ctrl && app.ctrl.board;
|
||||
a.dataset.ui = mqCompact.matches ? 'compact' : 'wide';
|
||||
if (!mqStacked.matches || !b) { a.style.removeProperty('--stage-h'); app.rotate = null; return; }
|
||||
const cs = root.getComputedStyle(a);
|
||||
const W = a.clientWidth - (parseFloat(cs.paddingLeft) || 0) - (parseFloat(cs.paddingRight) || 0);
|
||||
const H = a.clientHeight - (parseFloat(cs.paddingTop) || 0) - (parseFloat(cs.paddingBottom) || 0) - $('topbar').offsetHeight;
|
||||
const mg = (NW.BOARD_MARGIN || 0) * 2, dw = b.cols * NW.CELL + mg, dh = b.rows * NW.CELL + mg, pad = 8;
|
||||
const minSide = clamp(Math.round(H * 0.25), 140, 210); // room for the palette row and a window onto the info panel
|
||||
const maxStage = Math.max(120, H - minSide);
|
||||
const sU = Math.min((W - pad) / dw, (maxStage - pad) / dh), sR = Math.min((W - pad) / dh, (maxStage - pad) / dw);
|
||||
const rot = sR > sU * 1.08;
|
||||
const bh = rot ? dw : dh, bw = rot ? dh : dw;
|
||||
const stageH = Math.round(Math.min(maxStage, Math.ceil(bh * ((W - pad) / bw) + pad)));
|
||||
app.rotate = rot;
|
||||
if (a.style.getPropertyValue('--stage-h') !== stageH + 'px') a.style.setProperty('--stage-h', stageH + 'px');
|
||||
}
|
||||
function resizeCanvas() {
|
||||
layoutApp();
|
||||
const st = $('stage'), r = st.getBoundingClientRect();
|
||||
renderer.setRotation(r.height > r.width * 1.05); // portrait: draw the board turned 90 degrees (bigger cells)
|
||||
renderer.setRotation(app.rotate !== null && app.rotate !== undefined ? app.rotate : r.height > r.width * 1.05); // portrait: board turned 90 degrees (bigger cells)
|
||||
const dpr = Math.min(root.devicePixelRatio || 1, root.matchMedia && root.matchMedia('(pointer: coarse)').matches ? 2 : 2.5);
|
||||
renderer.resize(r.width, r.height, dpr);
|
||||
updatePaletteHint(); layoutBars(true); updateFit(); // (a rotation or board swap resets the camera: hide a stale Reset-zoom button)
|
||||
}
|
||||
if (root.ResizeObserver) new ResizeObserver(resizeCanvas).observe($('stage')); else root.addEventListener('resize', resizeCanvas);
|
||||
let resizeRaf = 0;
|
||||
function scheduleResize() { if (!resizeRaf) resizeRaf = root.requestAnimationFrame(() => { resizeRaf = 0; resizeCanvas(); }); } // (a frame later: never resize inside the observer callback)
|
||||
if (root.ResizeObserver) { const ro = new ResizeObserver(scheduleResize); ro.observe($('stage')); ro.observe($('topbar')); ro.observe($('palette')); }
|
||||
root.addEventListener('resize', scheduleResize);
|
||||
mqStacked.addEventListener && mqStacked.addEventListener('change', scheduleResize);
|
||||
mqCompact.addEventListener && mqCompact.addEventListener('change', scheduleResize);
|
||||
root.addEventListener('orientationchange', () => setTimeout(() => { resizeCanvas(); drawPaletteIcons(); }, 250));
|
||||
// keep the page from scrolling/bouncing or zooming on iOS
|
||||
document.addEventListener('gesturestart', (e) => e.preventDefault());
|
||||
|
|
@ -843,8 +1073,13 @@
|
|||
else if (app.endShown) { app.endShown = false; $('end').hidden = true; }
|
||||
}
|
||||
if (app.selTower && !view.towers.some((t) => t.id === app.selTower)) { app.selTower = 0; renderInfo(true); }
|
||||
if (app.last.rev !== view.rev) { app.last.rev = view.rev; app.previewDirty = true; if (app.selTower) renderInfo(true); }
|
||||
if (app.pending && pendFree) { // the partner built on the cell being previewed: drop it and say so (coop-7)
|
||||
const t = towerAtCell(app.pending);
|
||||
if (t) { setPending(null); toast(((ui.names && ui.names[t.owner]) || 'Someone') + ' just built there', 'bad'); }
|
||||
}
|
||||
if (app.last.rev !== view.rev) { app.last.rev = view.rev; app.previewDirty = true; if (app.selTower) renderInfo(false); }
|
||||
updateHud(view);
|
||||
layoutBars(false);
|
||||
if (now - app.lastBossCheck > 600 && view.state === 'playing') {
|
||||
app.lastBossCheck = now;
|
||||
const boss = view.monsters.some((m) => m.kind === 'rootkit');
|
||||
|
|
@ -861,6 +1096,7 @@
|
|||
// ------------------------------------------------------------------ boot
|
||||
function boot() {
|
||||
buildPalette(); buildMapPicker();
|
||||
{ const keys = TD.TOWER_ORDER.map((t) => TD.TOWERS[t].key); $('helpKeys').textContent = keys[0] + '\u2013' + keys[keys.length - 1]; }
|
||||
previewMap(app.mapId);
|
||||
setScreen('menu'); showOverlay('menu');
|
||||
$('btnCloseMenu').hidden = true;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
const TAU = Math.PI * 2;
|
||||
const SLOT_COLORS = ['#4de3ff', '#ffd24d'];
|
||||
const BG = '#050810', BOARD = '#09101f';
|
||||
const MARGIN = 10; // world px kept free on every side of the board so the gateway / server rings are never cut off
|
||||
const clamp = (v, a, b) => Math.min(b, Math.max(a, v));
|
||||
const lerpAngle = (a, b, k) => { let d = ((b - a + Math.PI * 3) % TAU) - Math.PI; return a + d * k; };
|
||||
|
||||
|
|
@ -55,6 +56,7 @@
|
|||
ctx.restore(); return;
|
||||
}
|
||||
ctx.fillStyle = '#0c1426'; rr(ctx, -h, -h, h * 2, h * 2, S * 0.12); ctx.fill();
|
||||
if (level >= 2) { ctx.fillStyle = rgba(col, level >= 3 ? 0.3 : 0.16); ctx.fill(); } // upgraded towers are tinted (level 3 clearly)
|
||||
ctx.lineWidth = S * (level >= 3 ? 0.075 : 0.05); ctx.strokeStyle = col; ctx.stroke();
|
||||
ctx.lineCap = 'round'; ctx.lineJoin = 'round';
|
||||
switch (type) {
|
||||
|
|
@ -100,11 +102,29 @@
|
|||
ctx.lineTo(-S * 0.07, S * 0.27); ctx.lineTo(S * 0.15, -S * 0.07); ctx.lineTo(S * 0.02, -S * 0.07); ctx.lineTo(S * 0.11, -S * 0.26);
|
||||
ctx.closePath(); ctx.fill();
|
||||
break;
|
||||
case 'uplink': {
|
||||
// satellite dish with a feed horn and two pulsing signal arcs
|
||||
const pulse = (t * 0.8) % 1;
|
||||
ctx.lineWidth = S * 0.07; ctx.strokeStyle = col;
|
||||
ctx.beginPath(); ctx.arc(0, S * 0.07, S * 0.23, Math.PI * 0.12, Math.PI * 0.88); ctx.stroke();
|
||||
ctx.lineWidth = S * 0.045;
|
||||
ctx.beginPath(); ctx.moveTo(0, S * 0.07); ctx.lineTo(0, -S * 0.15); ctx.stroke();
|
||||
ctx.fillStyle = col; ctx.beginPath(); ctx.arc(0, -S * 0.17, S * 0.05, 0, TAU); ctx.fill();
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const k = (pulse + i * 0.5) % 1;
|
||||
ctx.strokeStyle = rgba(col, 1 - k); ctx.lineWidth = S * 0.035;
|
||||
ctx.beginPath(); ctx.arc(0, -S * 0.17, S * (0.1 + 0.2 * k), -Math.PI * 0.85, -Math.PI * 0.15); ctx.stroke();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
// level pips
|
||||
ctx.fillStyle = '#ffffff';
|
||||
for (let i = 0; i < level; i++) { ctx.beginPath(); ctx.arc((i - (level - 1) / 2) * S * 0.13, h - S * 0.08, S * 0.035, 0, TAU); ctx.fill(); }
|
||||
// level pips: big enough to read at 14 px cells, with a dark halo so they show on any tile colour
|
||||
for (let i = 0; i < level; i++) {
|
||||
const px = (i - (level - 1) / 2) * S * 0.25, py = h - S * 0.11;
|
||||
ctx.fillStyle = '#04101a'; ctx.beginPath(); ctx.arc(px, py, S * 0.125, 0, TAU); ctx.fill();
|
||||
ctx.fillStyle = '#ffffff'; ctx.beginPath(); ctx.arc(px, py, S * 0.085, 0, TAU); ctx.fill();
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
|
|
@ -229,7 +249,7 @@
|
|||
_layout() {
|
||||
const b = this.board; if (!b) return;
|
||||
const d = this._dims(), pad = 4;
|
||||
this.fit = Math.min((this.W - pad * 2) / d.w, (this.H - pad * 2) / d.h);
|
||||
this.fit = Math.min((this.W - pad * 2) / (d.w + MARGIN * 2), (this.H - pad * 2) / (d.h + MARGIN * 2));
|
||||
this.scale = this.fit * this.cam.zoom;
|
||||
const sw = d.w * this.scale, sh = d.h * this.scale;
|
||||
const mx = sw > this.W ? (sw - this.W) / 2 + 24 : 0, my = sh > this.H ? (sh - this.H) / 2 + 24 : 0;
|
||||
|
|
@ -261,6 +281,9 @@
|
|||
return { x: Math.floor(fx), y: Math.floor(fy), fx, fy };
|
||||
}
|
||||
cellToScreen(cx, cy) { return this._w2s((cx + 0.5) * C, (cy + 0.5) * C); }
|
||||
// The cell one step away in a SCREEN direction (dx, dy each -1, 0 or 1). The board is drawn turned 90 degrees on tall screens,
|
||||
// so screen right is not world +x there: this is what the touch nudge buttons use.
|
||||
stepCell(cx, cy, dx, dy) { return this.rot ? { x: cx + dy, y: cy - dx } : { x: cx + dx, y: cy + dy }; }
|
||||
cellSizePx() { return C * this.scale; }
|
||||
|
||||
// ---------------------------------------------------------------- effects
|
||||
|
|
@ -296,6 +319,17 @@
|
|||
else if (e.k === 'filter') this._burst(e.x * C + Math.cos(e.a) * 14, e.y * C + Math.sin(e.a) * 14, '#35e0a1', 1, 30, 0.12);
|
||||
else if (e.k === 'mortar') this._burst(e.x * C + Math.cos(e.a) * 16, e.y * C + Math.sin(e.a) * 16, '#d4f04a', 3, 40, 0.25);
|
||||
break;
|
||||
case 'beam': {
|
||||
const x1 = e.x * C, y1 = e.y * C, x2 = e.tx * C, y2 = e.ty * C, wpx = (e.w || 0.5) * C;
|
||||
this.lines.push({ pts: [[x1, y1], [x2, y2]], col: 'rgba(255,226,122,.35)', w: wpx * 2.6, life: 0.42, max: 0.42, jit: 0 });
|
||||
this.lines.push({ pts: [[x1, y1], [x2, y2]], col: '#ffe27a', w: wpx * 1.1, life: 0.34, max: 0.34, jit: 0 });
|
||||
this.lines.push({ pts: [[x1, y1], [x2, y2]], col: '#ffffff', w: wpx * 0.45, life: 0.26, max: 0.26, jit: 0 });
|
||||
this._ring(e.bx * C, e.by * C, 6, (e.br || 1.3) * C, '#ffe27a', 0.45, 4);
|
||||
this._burst(e.bx * C, e.by * C, '#ffe27a', 10, 130, 0.45);
|
||||
this._ring(x1, y1, 4, 30, '#ffffff', 0.25, 3);
|
||||
this.shake = Math.min(2, this.shake + 0.35);
|
||||
break;
|
||||
}
|
||||
case 'arc': this.lines.push({ pts: e.pts.map((p) => [p[0] * C, p[1] * C]), col: '#ff7ad9', w: 2.4, life: 0.18, max: 0.18, jit: 5 }); break;
|
||||
case 'place': { const d = TD.TOWERS[e.type]; this._ring((e.x + 0.5) * C, (e.y + 0.5) * C, 6, 34, d ? d.color : '#fff', 0.35, 2.5); this._burst((e.x + 0.5) * C, (e.y + 0.5) * C, d ? d.color : '#fff', 5, 60, 0.35); break; }
|
||||
case 'sell': this._burst((e.x + 0.5) * C, (e.y + 0.5) * C, '#9db4d8', 6, 70, 0.35); break;
|
||||
|
|
@ -388,9 +422,11 @@
|
|||
if (tg) { ang = lerpAngle(ang, Math.atan2(tg.y - (tw.y + 0.5), tg.x - (tw.x + 0.5)), 0.35); this.aim.set(tw.id, ang); }
|
||||
const cx = (tw.x + 0.5) * C, cy = (tw.y + 0.5) * C;
|
||||
drawGlyph(ctx, tw.type, tw.level, cx, cy, C, ang, t, 1, rot);
|
||||
if (coop && tw.type !== 'wall') {
|
||||
ctx.fillStyle = SLOT_COLORS[tw.owner] || '#fff';
|
||||
ctx.beginPath(); ctx.moveTo(cx - C * 0.43, cy - C * 0.43); ctx.lineTo(cx - C * 0.43 + 8, cy - C * 0.43); ctx.lineTo(cx - C * 0.43, cy - C * 0.43 + 8); ctx.closePath(); ctx.fill();
|
||||
if (coop && tw.type !== 'wall') { // owner corner flag: at least ~5 CSS px, dark outline so it shows on a tile of the same colour
|
||||
const k = Math.max(12, 5.5 / sc), x0 = cx - C * 0.46, y0 = cy - C * 0.46;
|
||||
ctx.beginPath(); ctx.moveTo(x0, y0); ctx.lineTo(x0 + k, y0); ctx.lineTo(x0, y0 + k); ctx.closePath();
|
||||
ctx.fillStyle = SLOT_COLORS[tw.owner] || '#fff'; ctx.fill();
|
||||
ctx.lineWidth = 1.5 / sc; ctx.strokeStyle = '#04101a'; ctx.stroke();
|
||||
}
|
||||
}
|
||||
if (this.aim.size > towers.length + 40) { const live = new Set(towers.map((x) => x.id)); for (const k of this.aim.keys()) if (!live.has(k)) this.aim.delete(k); }
|
||||
|
|
@ -445,18 +481,12 @@
|
|||
}
|
||||
|
||||
// partner cursors and pings
|
||||
ctx.font = '600 ' + (11 / sc) + 'px system-ui, sans-serif'; ctx.textBaseline = 'middle';
|
||||
const labels = []; // the cell frame is drawn on the board, the name label later in screen space (clamped to the stage)
|
||||
for (const cu of view.cursors || []) {
|
||||
const col = SLOT_COLORS[cu.slot] || '#fff', gx = Math.floor(cu.x), gy = Math.floor(cu.y);
|
||||
ctx.strokeStyle = col; ctx.lineWidth = 2; ctx.strokeRect(gx * C + 1, gy * C + 1, C - 2, C - 2);
|
||||
const nm = (ui.names && ui.names[cu.slot]) || 'Partner';
|
||||
const tw = ctx.measureText(nm).width + 10 / sc;
|
||||
ctx.save(); ctx.translate((gx + 0.5) * C, (gy + 0.5) * C); if (rot) ctx.rotate(-rot);
|
||||
ctx.fillStyle = col; ctx.fillRect(-tw / 2, -C / 2 - 17 / sc, tw, 15 / sc);
|
||||
ctx.fillStyle = '#04101a'; ctx.textAlign = 'center'; ctx.fillText(nm, 0, -C / 2 - 9.5 / sc);
|
||||
ctx.restore();
|
||||
labels.push({ nm: (ui.names && ui.names[cu.slot]) || 'Partner', col, gx, gy });
|
||||
}
|
||||
ctx.textAlign = 'start';
|
||||
for (let i = this.marks.length - 1; i >= 0; i--) {
|
||||
const m = this.marks[i]; m.life -= dt;
|
||||
if (m.life <= 0) { this.marks.splice(i, 1); continue; }
|
||||
|
|
@ -469,6 +499,7 @@
|
|||
ctx.globalAlpha = 1;
|
||||
ctx.fillStyle = col; ctx.beginPath(); ctx.arc((m.x + 0.5) * C, (m.y + 0.5) * C, 5, 0, TAU); ctx.fill();
|
||||
}
|
||||
if (labels.length) this._cursorLabels(ctx, labels);
|
||||
}
|
||||
|
||||
_rangeRing(ctx, cx, cy, r, col) {
|
||||
|
|
@ -589,6 +620,22 @@
|
|||
ctx.globalAlpha = 1; ctx.textAlign = 'start';
|
||||
}
|
||||
}
|
||||
|
||||
// partner name labels: screen space, kept inside the stage, flipped below the cell when there is no room above it
|
||||
_cursorLabels(ctx, labels) {
|
||||
ctx.setTransform(this.dpr, 0, 0, this.dpr, 0, 0);
|
||||
ctx.font = '600 11px system-ui, sans-serif'; ctx.textBaseline = 'middle'; ctx.textAlign = 'center';
|
||||
const half = C * this.scale / 2;
|
||||
for (const l of labels) {
|
||||
const p = this.cellToScreen(l.gx, l.gy), w = ctx.measureText(l.nm).width + 10;
|
||||
const x = clamp(p.x - w / 2, 2, Math.max(2, this.W - 2 - w));
|
||||
let y = p.y - half - 17; if (y < 2) y = p.y + half + 2;
|
||||
y = clamp(y, 2, Math.max(2, this.H - 17));
|
||||
ctx.fillStyle = l.col; ctx.fillRect(x, y, w, 15);
|
||||
ctx.fillStyle = '#04101a'; ctx.fillText(l.nm, x + w / 2, y + 7.5);
|
||||
}
|
||||
ctx.textAlign = 'start';
|
||||
}
|
||||
}
|
||||
|
||||
// Draw a tower icon into a small canvas (palette buttons, info panel)
|
||||
|
|
@ -606,4 +653,5 @@
|
|||
NW.drawGlyph = drawGlyph;
|
||||
NW.SLOT_COLORS = SLOT_COLORS;
|
||||
NW.CELL = C;
|
||||
NW.BOARD_MARGIN = MARGIN;
|
||||
})(typeof self !== 'undefined' ? self : this);
|
||||
|
|
|
|||
141
public/js/sim.js
141
public/js/sim.js
|
|
@ -91,8 +91,96 @@
|
|||
'..........................',
|
||||
],
|
||||
},
|
||||
canyon: {
|
||||
id: 'canyon', name: 'The Canyon', difficulty: 1,
|
||||
desc: 'Three ridges force a natural S-bend. Great for learning where to stack turrets.',
|
||||
rows: [
|
||||
'.......#.........#........',
|
||||
'.......#.........#........',
|
||||
'.......#.........#........',
|
||||
'.......#.........#........',
|
||||
'.......#.........#........',
|
||||
'.......#....#....#........',
|
||||
'.......#....#....#........',
|
||||
'S......#....#....#........',
|
||||
'.......#....#....#.......C',
|
||||
'.......#....#....#........',
|
||||
'.......#....#....#........',
|
||||
'............#.............',
|
||||
'............#.............',
|
||||
'............#.............',
|
||||
'............#.............',
|
||||
'............#.............',
|
||||
],
|
||||
},
|
||||
archipelago: {
|
||||
id: 'archipelago', name: 'Archipelago', difficulty: 2,
|
||||
desc: 'Islands of dead nodes everywhere and two gateways. Mind the gaps between them.',
|
||||
rows: [
|
||||
'..........................',
|
||||
'..........................',
|
||||
'S...##........##......##..',
|
||||
'....##........##......##..',
|
||||
'...................##.....',
|
||||
'.........##........##.....',
|
||||
'.........##...............',
|
||||
'..........................',
|
||||
'...............##........C',
|
||||
'.....##........##.........',
|
||||
'.....##...................',
|
||||
'..........................',
|
||||
'..........##.......##.....',
|
||||
'S.........##.......##.##..',
|
||||
'......................##..',
|
||||
'..........................',
|
||||
],
|
||||
},
|
||||
fortress: {
|
||||
id: 'fortress', name: 'Fortress', difficulty: 2,
|
||||
desc: 'The server sits inside a ring with three entrances. Wall off two, defend the third.',
|
||||
rows: [
|
||||
'..........................',
|
||||
'..........................',
|
||||
'..........................',
|
||||
'S.........................',
|
||||
'..........................',
|
||||
'..................###.###.',
|
||||
'..................#.....#.',
|
||||
'..................#.....#.',
|
||||
'.....................C..#.',
|
||||
'..................#.....#.',
|
||||
'..................#.....#.',
|
||||
'..................###.###.',
|
||||
'S.........................',
|
||||
'..........................',
|
||||
'..........................',
|
||||
'..........................',
|
||||
],
|
||||
},
|
||||
pinwheel: {
|
||||
id: 'pinwheel', name: 'Pinwheel', difficulty: 3,
|
||||
desc: 'Four gateways, one server in the middle, bars that twist every route.',
|
||||
rows: [
|
||||
'.............S............',
|
||||
'..........................',
|
||||
'..........................',
|
||||
'................#.........',
|
||||
'................#.........',
|
||||
'........#####...#.........',
|
||||
'................#.........',
|
||||
'................#........S',
|
||||
'S............C............',
|
||||
'.........#................',
|
||||
'.........#................',
|
||||
'.........#....#####.......',
|
||||
'.........#................',
|
||||
'.........#................',
|
||||
'..........................',
|
||||
'............S.............',
|
||||
],
|
||||
},
|
||||
};
|
||||
const MAP_ORDER = ['open', 'twin', 'hub'];
|
||||
const MAP_ORDER = ['open', 'canyon', 'twin', 'archipelago', 'fortress', 'hub', 'pinwheel'];
|
||||
|
||||
function parseMap(m) {
|
||||
const rows = m.rows.length, cols = m.rows[0].length;
|
||||
|
|
@ -113,7 +201,7 @@
|
|||
}
|
||||
|
||||
// ---------------------------------------------------------------- definitions
|
||||
const TOWER_ORDER = ['wall', 'filter', 'ids', 'mortar', 'throttle', 'arc'];
|
||||
const TOWER_ORDER = ['wall', 'filter', 'ids', 'mortar', 'throttle', 'arc', 'uplink'];
|
||||
const TARGET_MODES = ['first', 'last', 'strong', 'close'];
|
||||
const TOWERS = {
|
||||
wall: {
|
||||
|
|
@ -168,6 +256,16 @@
|
|||
{ cost: 120, dmg: 36, range: 4.2, rate: 1.4, chains: 4, chainRange: 2.2, falloff: 0.75 },
|
||||
],
|
||||
},
|
||||
uplink: {
|
||||
name: 'Orbital Uplink', key: '7', color: '#ffe27a', air: true, ground: true,
|
||||
desc: 'Endgame weapon. A piercing orbital beam that ignores armour, scorches everything in its line, blasts and slows the rest around the target, and reaches across most of the map. Very expensive to build and to upgrade.',
|
||||
levels: [
|
||||
{ cost: 450, dmg: 260, range: 11, rate: 0.45, width: 0.5, splash: 1.3, slowOnHit: 0.4, slowFor: 1.5 },
|
||||
{ cost: 500, dmg: 400, range: 12, rate: 0.5, width: 0.55, splash: 1.5, slowOnHit: 0.45, slowFor: 1.75 },
|
||||
{ cost: 800, dmg: 640, range: 13, rate: 0.55, width: 0.6, splash: 1.7, slowOnHit: 0.5, slowFor: 2.0 },
|
||||
{ cost: 1200, dmg: 1000, range: 14, rate: 0.6, width: 0.7, splash: 2.0, slowOnHit: 0.6, slowFor: 2.5 },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const ENEMY_ORDER = ['ping', 'worm', 'trojan', 'spam', 'ghost', 'rootkit'];
|
||||
|
|
@ -554,7 +652,7 @@
|
|||
x: s.x + 0.5, y: s.y + 0.5, cx: s.x, cy: s.y, tx: -1, ty: -1,
|
||||
hp, maxhp: hp, armor: def.armor, speed: def.speed,
|
||||
reward: Math.max(1, Math.round(def.reward * rewardScale(q.wave))),
|
||||
leak: def.leak, slow: 0, rem: 0, dead: false, wave: q.wave,
|
||||
leak: def.leak, slow: 0, slowT: 0, slowAmt: 0, rem: 0, dead: false, wave: q.wave,
|
||||
};
|
||||
m.rem = m.air
|
||||
? Math.hypot(b.core.x - s.x, b.core.y - s.y)
|
||||
|
|
@ -572,7 +670,9 @@
|
|||
}
|
||||
while (this.spawnQ.length && this.spawnQ[0].t <= this.time) this.spawnMonster(this.spawnQ.shift());
|
||||
|
||||
for (const m of this.monsters) m.slow = 0;
|
||||
for (const m of this.monsters) { // slow = lingering slow (Orbital Uplink) unless a Rate Limiter says more
|
||||
if (m.slowT > 0) { m.slow = m.slowAmt; m.slowT -= dt; } else m.slow = 0;
|
||||
}
|
||||
for (const t of this.towers) this.updateTower(t, dt);
|
||||
this.updateBullets(dt);
|
||||
for (const m of this.monsters) if (!m.dead) this.moveMonster(m, dt);
|
||||
|
|
@ -645,9 +745,9 @@
|
|||
this.emit({ e: 'leak', x: m.x, y: m.y, n: m.leak });
|
||||
}
|
||||
|
||||
damage(m, raw, src) {
|
||||
damage(m, raw, src, ignoreArmor) {
|
||||
if (m.dead) return;
|
||||
const d = Math.max(raw - m.armor, raw * 0.25);
|
||||
const d = ignoreArmor ? raw : Math.max(raw - m.armor, raw * 0.25);
|
||||
m.hp -= d;
|
||||
if (src) src.dealt += d;
|
||||
if (m.hp <= 0) {
|
||||
|
|
@ -727,6 +827,35 @@
|
|||
this.emit({ e: 'shot', k: 'mortar', x: cx, y: cy, a: Math.atan2(gy - cy, gx - cx) });
|
||||
break;
|
||||
}
|
||||
case 'uplink': {
|
||||
// A beam from the tower through the target out to full range: everything in the line takes full damage
|
||||
// (armour ignored), then everything near the target is blasted for half and everything hit is slowed for a moment.
|
||||
const ex = m.x - cx, ey = m.y - cy, el = Math.hypot(ex, ey) || 1, ux = ex / el, uy = ey / el;
|
||||
const hit = new Set();
|
||||
for (const o of this.monsters) {
|
||||
if (o.dead || (o.air ? !def.air : !def.ground)) continue;
|
||||
const ox = o.x - cx, oy = o.y - cy, along = ox * ux + oy * uy;
|
||||
if (along < 0 || along > st.range) continue;
|
||||
if (Math.abs(ox * uy - oy * ux) <= st.width) hit.add(o);
|
||||
}
|
||||
const r2 = st.splash * st.splash;
|
||||
const blast = [];
|
||||
for (const o of this.monsters) {
|
||||
if (o.dead || hit.has(o) || (o.air ? !def.air : !def.ground)) continue;
|
||||
const dx = o.x - m.x, dy = o.y - m.y;
|
||||
if (dx * dx + dy * dy <= r2) blast.push(o);
|
||||
}
|
||||
const slowFor = (o) => {
|
||||
const eff = Math.min(0.6, st.slowOnHit * (1 - (ENEMIES[o.kind].slowRes || 0)));
|
||||
if (eff >= o.slowAmt || o.slowT <= 0) o.slowAmt = eff;
|
||||
o.slowT = Math.max(o.slowT, st.slowFor);
|
||||
};
|
||||
for (const o of hit) { this.damage(o, st.dmg, t, true); slowFor(o); }
|
||||
for (const o of blast) { this.damage(o, st.dmg * 0.5, t, true); slowFor(o); }
|
||||
this.emit({ e: 'shot', k: 'uplink', x: cx, y: cy, tx: round2(m.x), ty: round2(m.y) });
|
||||
this.emit({ e: 'beam', x: round2(cx), y: round2(cy), tx: round2(cx + ux * st.range), ty: round2(cy + uy * st.range), w: st.width, bx: round2(m.x), by: round2(m.y), br: st.splash });
|
||||
break;
|
||||
}
|
||||
case 'arc': {
|
||||
const pts = [[cx, cy], [m.x, m.y]];
|
||||
const hit = new Set([m]);
|
||||
|
|
|
|||
18
public/sw.js
18
public/sw.js
|
|
@ -9,6 +9,18 @@ self.addEventListener('install', (e) => {
|
|||
self.addEventListener('activate', (e) => {
|
||||
e.waitUntil(caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))).then(() => self.clients.claim()));
|
||||
});
|
||||
// An error page from the proxy in front of the app (nginx answers 502/503/504 while the Node process restarts or is
|
||||
// down) is a "network failure" for our purposes: serve the cached copy instead of the proxy's error page.
|
||||
const GATEWAY_ERRORS = [502, 503, 504];
|
||||
|
||||
// The cached copy of this request; a navigation (also /?room=ABCD, which has no cache entry of its own) falls back to the
|
||||
// cached app shell. `res` is the proxy's error response, still better than nothing for a file that was never cached.
|
||||
function offline(req, res) {
|
||||
return caches.match(req)
|
||||
.then((r) => r || (req.mode === 'navigate' ? caches.match('index.html') : null))
|
||||
.then((r) => r || res || Response.error());
|
||||
}
|
||||
|
||||
self.addEventListener('fetch', (e) => {
|
||||
const req = e.request;
|
||||
if (req.method !== 'GET') return;
|
||||
|
|
@ -17,9 +29,11 @@ self.addEventListener('fetch', (e) => {
|
|||
e.respondWith(
|
||||
fetch(req)
|
||||
.then((res) => {
|
||||
if (res.ok && res.type === 'basic') { const copy = res.clone(); caches.open(CACHE).then((c) => c.put(req, copy)).catch(() => {}); }
|
||||
if (GATEWAY_ERRORS.includes(res.status)) return offline(req, res);
|
||||
// Only complete responses: a 206 (a range request for audio) is ok but is not the whole file.
|
||||
if (res.status === 200 && res.type === 'basic') { const copy = res.clone(); caches.open(CACHE).then((c) => c.put(req, copy)).catch(() => {}); }
|
||||
return res;
|
||||
})
|
||||
.catch(() => caches.match(req).then((r) => r || caches.match('index.html'))),
|
||||
.catch(() => offline(req)),
|
||||
);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue