/
memoryspeak
/
UlamCodeWeb
Обзор
Документация
Войти
/
memoryspeak
/
UlamCodeWeb
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
js/elements/RandomHint.js
99 строк
3 KB
memoryspeak
refactor function parameters
17 фев 2026, 18:30
17 фев 2026, 18:30
d5167b6
Код
Авторство
О чём код?
import Images from "./Images.js"; export default class RandomHint { BORDER_RADIUS_CELL_SIZE_RATIO = 0.1; LINE_WIDTH_CELL_SIZE_RATIO = 0.02; BORDER_COLOR = "white"; FILL_COLOR = "rgba(60, 60, 60, 0.9)"; LABEL_HEIGHT_CELL_SIZE_RATIO = 1; LABEL_LEFT_CELL_SIZE_RATIO = 0.25; LABEL_BOTTOM_CELL_SIZE_RATIO = 0.25; constructor(app) { this.app = app; this.layer = app.layer; this.input = app.input; this.map = app.map; this.logoImg = new Image(); this.logoImg.src = Images.randomHintBase64; } update(correction) { if (this.app.modal.isActive) return; if (this.input.mouse.isDown && this.isMouseInButton()) this.onClick(); } isMouseInButton() { return ( this.input.mouse.x > this.LABEL_LEFT_CELL_SIZE_RATIO * this.layer.cellSize && this.input.mouse.x < (this.LABEL_LEFT_CELL_SIZE_RATIO + 1) * this.layer.cellSize && this.input.mouse.y > this.layer.h - (this.LABEL_BOTTOM_CELL_SIZE_RATIO + this.LABEL_HEIGHT_CELL_SIZE_RATIO) * this.layer.cellSize && this.input.mouse.y < this.layer.h - this.LABEL_BOTTOM_CELL_SIZE_RATIO * this.layer.cellSize ); } draw() { this.drawBasicRect(); this.drawImage(); } drawBasicRect() { this.layer.context.beginPath(); this.layer.context.roundRect( this.LABEL_LEFT_CELL_SIZE_RATIO * this.layer.cellSize, this.layer.h - (this.LABEL_BOTTOM_CELL_SIZE_RATIO + this.LABEL_HEIGHT_CELL_SIZE_RATIO) * this.layer.cellSize, this.LABEL_HEIGHT_CELL_SIZE_RATIO * this.layer.cellSize, this.LABEL_HEIGHT_CELL_SIZE_RATIO * this.layer.cellSize, this.layer.cellSize * this.BORDER_RADIUS_CELL_SIZE_RATIO, ); this.layer.context.strokeStyle = this.BORDER_COLOR; this.layer.context.lineWidth = this.layer.cellSize * this.LINE_WIDTH_CELL_SIZE_RATIO; this.layer.context.fillStyle = this.FILL_COLOR; this.layer.context.fill(); this.layer.context.stroke(); } drawImage() { const centerX = 0.75 * this.layer.cellSize; const centerY = this.layer.h - 0.75 * this.layer.cellSize; const imgSize = 0.75 * this.layer.cellSize; if (this.logoImg.complete) { this.layer.context.drawImage( this.logoImg, centerX - imgSize / 2, centerY - imgSize / 2, imgSize, imgSize, ); } } onClick() { if (this.isAnyCellCanHelper()) return; this.map.startHelper(); } isAnyCellCanHelper() { for (let i = 0; i < this.map.cells.length; i++) { const cell = this.map.cells[i]; if (cell.helper) return true; } return false; } }