From 8e6723efc32a3bc0435d2aed09e440db19c690e9 Mon Sep 17 00:00:00 2001 From: He4eT Date: Fri, 6 Jun 2025 23:20:08 +0200 Subject: [PATCH] game: extract effectHandlers --- game.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/game.js b/game.js index df0e916..efdf35b 100644 --- a/game.js +++ b/game.js @@ -357,15 +357,7 @@ function drawArena() { map(0, 0, 30, 15) } -function drawFX() { - effects - .map((effect) => ({ - ...effect, - from: arenaToScreen(effect.from ?? {}), - to: arenaToScreen(effect.to ?? {}), - })) - .forEach((effect) => - ({ +const effectHandlers = { laser: ({ from, to, frames }) => { const color = frames.shift() line(from.x, from.y, to.x, to.y, color) @@ -404,7 +396,17 @@ function drawFX() { line(x, y, x, y - dy * w, color) }) }, - })[effect.type](effect), + } + +function drawFX() { + effects + .map((effect) => ({ + ...effect, + from: arenaToScreen(effect.from ?? {}), + to: arenaToScreen(effect.to ?? {}), + })) + .forEach((effect) => + effectHandlers[effect.type](effect), ) effects = effects.filter(({ frames }) => frames.length > 0)