Fix trainer mobile map and entrance hazard limits

This commit is contained in:
nyan404 committed 2026-11-22 17:34:19 +03:00
1 parent eb04ce3e48
commit ba25b64190
10 files changed
+208 -39

No files matched your search

+14 -2
View File
@@ -52,7 +52,19 @@ export function generateField(input = DEFAULTS, random = Math.random) {
[candidates[i], candidates[j]] = [candidates[j], candidates[i]];
}
const count = Math.min(Math.max(5, options.growth + options.season + 2 * (options.height - 1)), candidates.length);
const hazards = new Set(candidates.slice(0, count));
// The safe entrance and x2 y1 already cap x1 y1 at 2 and x1 y2 at 3.
// Cap x1 y3 at 4 during placement, skipping only a fifth hazard in its neighborhood.
const leftThirdNeighbors = neighbors(2 * COLS);
const hazards = new Set();
let leftThirdHazards = 0;
for (const id of candidates) {
if (hazards.size === count) break;
if (leftThirdNeighbors.includes(id)) {
if (leftThirdHazards === 4) continue;
leftThirdHazards++;
}
hazards.add(id);
}
const values = Array.from({length: ROWS * COLS}, (_,id)=>neighbors(id).filter(n => hazards.has(n)).length);
return { start: START, exit, base, reserved, hazards, values };
}
@@ -143,7 +155,7 @@ export class Training {
id, entrance: id === START, exit: id === this.#field.exit, transition: this.#transition(id), base: this.#field.base.includes(id),
opened: this.#opened.has(id), marked: this.#marks.has(id), rating: this.#ratings.get(id) ?? null,
available: !ended && this.#available(id),
value: this.#opened.has(id) || ended ? this.#field.values[id] : null,
value: id === START || this.#opened.has(id) || ended ? this.#field.values[id] : null,
...(ended ? {hazard: this.#field.hazards.has(id), wrong: this.#marks.has(id) && !this.#field.hazards.has(id)} : {}),
})),
};
+9 -2
View File
@@ -71,6 +71,8 @@ dd { margin: 0; text-align: right; font-weight: bold; }
.cell-grid .wrong button { background: var(--paper); color: var(--danger); }
.cell-coord { position: absolute; left: 4px; top: 2px; font-size: 10px; font-weight: normal; color: var(--light); background: #17120dbb; padding: 0 2px; line-height: 1.4; }
.cell-value { font-size: clamp(14px, 1.5vw, 24px); }
.entrance .cell-value { font-size: clamp(.8125rem, 1.2vw, 1rem); line-height: 1.25; white-space: nowrap; }
.scene-grid .entrance .cell-value { position: absolute; right: 2px; bottom: 2px; z-index: 1; padding: 0 2px; border-radius: 2px; background: var(--map); }
.cell-rating, .rating-key { background: var(--active); color: var(--ink); padding: 0 3px; border-radius: 2px; font-weight: bold; }
.cell-rating { position: absolute; bottom: 1px; right: 1px; font-size: .6875rem; line-height: 1.15; text-shadow: none; }
.character-sprite { position: absolute; width: 10%; height: 16.6667%; left: 0; top: 83.3333%; pointer-events: none; display: flex; align-items: center; justify-content: center; }
@@ -93,6 +95,7 @@ input { accent-color: var(--map); }
.map-panel .fineprint, #panel-dialog:has(#map-body) .fineprint { color: var(--paper); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.panel-heading h2 { min-width: 0; }
.phone-map-title { display: none; }
#map-toggle { color: inherit; background: none; border: 0; padding: 0 4px; text-align: left; font: inherit; }
#map-expand { padding: 4px 8px; font-size: var(--small); }
.map-grid { display: grid; gap: 2px; margin: 12px 0; }
@@ -169,8 +172,7 @@ select { min-height: 44px; padding: 8px; width: 100%; }
.character .stats > div { border: 0; padding: 2px 0; }
.character .stats:first-of-type > div:last-child, .character .stats:last-of-type > div:nth-child(n+3) { display: none; }
.location { order: 1; padding: 0; }
.messages-panel { order: 3; }
.map-panel, .history-panel { display: none; }
.messages-panel, .map-panel { order: 3; }
.cell-coord { font-size: 8px; left: 1px; top: 1px; padding: 0 1px; }
.cell-value { font-size: 14px; }
.scene-grid .opened .cell-coord { display: none; }
@@ -180,6 +182,11 @@ select { min-height: 44px; padding: 8px; width: 100%; }
dialog { padding: 16px; }
footer { padding: 16px 12px; }
}
@media (max-width: 700px), (max-width: 1100px) and (max-height: 500px) and (pointer: coarse) {
#map-title { scroll-margin-block-start: 12px; }
.phone-map-title { display: inline; }
#map-toggle, #map-expand { display: none; }
}
@media (pointer: coarse) { .action-buttons button, .mobile-tools button, #map-mark, #map-levels button, .listen-controls button, .listen-controls .check { min-height: 48px; } }
@media (prefers-reduced-motion: reduce) { button { transition: none; } }
@media (forced-colors: active) { .cell-grid .selected button, .cell-grid .current button { outline: 2px solid Highlight; outline-offset: -3px; } }
+20 -9
View File
@@ -3,7 +3,7 @@ import {playSound, stopSound} from './audio.js';
const $ = id => document.getElementById(id);
const compact = matchMedia('(max-width: 700px), (pointer: coarse)');
const mobile = matchMedia('(max-width: 700px)');
const phoneMap = matchMedia('(max-width: 700px), (max-width: 1100px) and (max-height: 500px) and (pointer: coarse)');
const sounds = ['Звуков нет', 'Едва различимый шорох', 'Тихий шорох', 'Приглушённый шорох', 'Громкий шорох'];
let game, selected = START, hints = new Set(), hintTimers = new Map();
let messages = [];
@@ -37,13 +37,13 @@ function recordMessage(message) {
renderMessage(message);
}
function describe(cell, view, showNotes = true, isMap = false) {
if (cell.entrance) return 'вход';
if (cell.exit) return 'выход';
const rating = showNotes && cell.rating !== null ? `, ваша оценка ${cell.rating}` : '';
if (cell.wrong) return `ошибочная отметка, безопасно${rating}`;
if (cell.hazard) return `опасная клетка${rating}`;
if (cell.opened || ended(view)) {
if (cell.entrance || cell.opened || ended(view)) {
const fact = simple() || ended(view) ? `, ${levelText(cell.value).slice(0, -1).toLowerCase()}` : '';
if (cell.entrance) return `вход${fact}`;
return `${cell.opened ? 'проверено' : 'безопасная клетка'}${fact}${rating}${!isMap && cell.available ? ', можно прыгнуть' : ''}`;
}
if (cell.marked && showNotes) return `ваш флажок опасности${rating}`;
@@ -51,7 +51,8 @@ function describe(cell, view, showNotes = true, isMap = false) {
return `клетка не проверена${rating}${isMap ? '' : cell.available ? ', рядом с персонажем' : ', не рядом с персонажем'}`;
}
function cellValue(cell, view, showMarks) {
if (cell.transition) return cell.entrance ? '↥' : '↗';
if (cell.entrance) return simple() || ended(view) ? `↥ ${cell.value}` : '↥';
if (cell.exit) return '↗';
if (cell.wrong) return '≠';
if (cell.hazard) return '×';
if (cell.marked && showMarks) return '⚑';
@@ -283,20 +284,27 @@ function openPanel(kind, opener) {
$('panel-dialog-title').textContent = kind === 'map' ? 'Минное поле' : 'История действий';
$('panel-dialog-content').append(panelBody); showDialog($('panel-dialog'), opener);
}
function syncMapVisibility() {
$('map-body').hidden = !phoneMap.matches && $('map-toggle').getAttribute('aria-expanded') === 'false';
}
$('panel-dialog').addEventListener('close', () => {
if (panelBody) {
panelOrigin.append(panelBody);
if (panelBody.id === 'map-body') panelBody.hidden = $('map-toggle').getAttribute('aria-expanded') === 'false';
if (panelBody.id === 'map-body') syncMapVisibility();
panelBody = null; panelOrigin = null;
}
panelReturn?.focus(); panelReturn = null;
});
$('map-open').addEventListener('click', event => openPanel('map',event.currentTarget));
$('map-open').addEventListener('click', event => {
if (!phoneMap.matches) { openPanel('map',event.currentTarget); return; }
$('map-title').focus({preventScroll:true});
$('map-title').scrollIntoView({block:'start'});
});
$('map-expand').addEventListener('click', event => openPanel('map',event.currentTarget));
$('history-open').addEventListener('click', event => openPanel('history',event.currentTarget));
$('map-toggle').addEventListener('click', () => {
const open = $('map-toggle').getAttribute('aria-expanded') !== 'true';
$('map-toggle').setAttribute('aria-expanded',String(open)); $('map-body').hidden = !open;
$('map-toggle').setAttribute('aria-expanded',String(open)); syncMapVisibility();
$('map-toggle').querySelector('span').textContent = open ? '−' : '+';
});
$('help-open').addEventListener('click', event => showDialog($('help-dialog'),event.currentTarget));
@@ -313,7 +321,7 @@ $('new-game').addEventListener('click', event => confirmAction('Начать з
$('clear-marks').addEventListener('click', event => confirmAction('Очистить отметки?', 'Исчезнут только ваши флажки и оценки. Проверенные клетки и история останутся, а игру можно будет продолжить.', 'Очистить отметки', () => { game.clearMarks(); $('status').textContent = 'Флажки и оценки убраны. Можно продолжать.'; render(); }, event.currentTarget));
$('simple-mode').addEventListener('change', () => {
stopSound(); clearHints();
$('status').textContent = simple() ? 'В упрощённом режиме уровни видны на проверенных клетках.' : 'В звуковом режиме оцените клетку по шорохам.';
$('status').textContent = simple() ? 'В упрощённом режиме уровни видны на входе и на проверенных клетках.' : 'В звуковом режиме оцените клетку по шорохам.';
$('messages').replaceChildren(); messages.forEach(renderMessage);
$('history').replaceChildren(); renderedHistory = 0;
render();
@@ -333,7 +341,10 @@ $('jump').addEventListener('click', () => act('jump'));
$('mark').addEventListener('click', () => act('mark'));
$('map-mark').addEventListener('click', () => act('mark'));
compact.addEventListener('change', render);
mobile.addEventListener('change', () => { if ($('panel-dialog').open) $('panel-dialog').close(); });
phoneMap.addEventListener('change', () => {
if ($('panel-dialog').open) $('panel-dialog').close();
syncMapVisibility();
});
for (const img of document.images) {
img.addEventListener('error', () => { img.hidden = true; });
if (img.complete && !img.naturalWidth) img.hidden = true;