From 7a36d23393518d4ca45657ae321028307ce64c31 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Mon, 20 Jul 2026 10:01:26 +0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=20=D1=81=D0=BF=D0=BE=D1=81=D0=BE=D0=B1=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87=D0=B8=20=D1=82=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D1=82=D1=83=D1=80=20=D0=B2=20=D1=84=D1=83=D0=BD=D0=BA?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=81=D0=BF=D1=80=D0=B0=D0=B9=D1=82=D0=BE=D0=B2,=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=B3=20=D1=81=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81?= =?UTF-8?q?=D1=82=D0=B2=D0=B8=D0=B5=D0=BC=20=D0=B0=D1=80=D0=B3=D1=83=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view.js | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/view.js b/src/view.js index b1a5efd..8ce1416 100644 --- a/src/view.js +++ b/src/view.js @@ -9,9 +9,10 @@ import { Game } from './game'; /** * Создает визуальное отображение мяча с помощью Pixi.js * @param {Ball} ball экземпляр класса мяч - * @param {unknown} texture текстура мяча + * @param {object} textures объект с текстурами для визуального отображения */ -function createBallView(ball, texture) { +function createBallView(ball, textures) { + const texture = textures['/sprites/fire_ball_1.png']; const ballSprite = new Sprite(texture); ballSprite.anchor.set(0.5); ballSprite.width = ball.radius * 2; @@ -23,9 +24,10 @@ function createBallView(ball, texture) { /** * Создает визуальное отображение ракетки с помощью Pixi.js * @param {Paddle} paddle экземпляр класса ракетка - * @param {unknown} texture текстура ракетки + * @param {object} textures объект с текстурами для визуального отображения */ -function createPaddleView(paddle, texture) { +function createPaddleView(paddle, textures) { + const texture = textures['/sprites/paddle.png']; const paddleSprite = new NineSliceSprite({ texture, leftWidth: 150, rightWidth: 150, topHeight: 0, bottomHeight: 0 }); paddleSprite.width = paddle.width; paddleSprite.height = paddle.height; @@ -37,10 +39,16 @@ function createPaddleView(paddle, texture) { * Создает визуальное отображение кирпича с помощью Pixi.js * @param {Brick} brick экземпляр класса кирпич * @returns {Graphics} графическое отображение кирпича - * @param {unknown} textures текстуры блоков + * @param {object} textures объект с текстурами для визуального отображения */ function createBrickView(brick, textures) { - const brickSprite = new Sprite(textures[brick.type - 1]); + const bricksTextures = [ + textures['/sprites/block_1.png'], + textures['/sprites/block_2.png'], + textures['/sprites/block_3.png'], + ]; + + const brickSprite = new Sprite(bricksTextures[brick.type - 1]); brickSprite.width = brick.width; brickSprite.height = brick.height; @@ -101,22 +109,16 @@ export function createGameView(game, container, textures) { const balls = new Map(); for (const ball of game.balls) { - const ballView = createBallView(ball, textures['/sprites/fire_ball_1.png']); + const ballView = createBallView(ball, textures); container.addChild(ballView); balls.set(ball, ballView); } - const paddle = createPaddleView(game.paddle, textures['/sprites/paddle.png']); + const paddle = createPaddleView(game.paddle, textures); container.addChild(paddle); - const bricksTextures = [ - textures['/sprites/block_1.png'], - textures['/sprites/block_2.png'], - textures['/sprites/block_3.png'], - ]; - const bricks = game.bricks.map((brick) => { - const brickView = createBrickView(brick, bricksTextures); + const brickView = createBrickView(brick, textures); container.addChild(brickView); return brickView; }); @@ -158,7 +160,7 @@ export function managePerkViewsLifetime(views, game, container, textures) { for (const ball of game.balls) { if (!views.balls.has(ball)) { - const ballView = createBallView(ball, textures['/sprites/fire_ball_1.png']); + const ballView = createBallView(ball, textures); container.addChild(ballView); views.balls.set(ball, ballView); } @@ -234,13 +236,8 @@ export function rebuildBrickViews(views, game, container, textures) { brickView.destroy(); } - const bricksTextures = [ - textures['/sprites/brick_1.png'], - textures['/sprites/brick_2.png'], - textures['/sprites/brick_3.png'], - ]; views.bricks = game.bricks.map((brick) => { - const brickView = createBrickView(brick); + const brickView = createBrickView(brick, textures); container.addChild(brickView); return brickView; });