game: extract effectHandlers

This commit is contained in:
He4eT 2025-06-06 23:20:08 +02:00
commit 8e6723efc3

22
game.js
View file

@ -357,15 +357,7 @@ function drawArena() {
map(0, 0, 30, 15) map(0, 0, 30, 15)
} }
function drawFX() { const effectHandlers = {
effects
.map((effect) => ({
...effect,
from: arenaToScreen(effect.from ?? {}),
to: arenaToScreen(effect.to ?? {}),
}))
.forEach((effect) =>
({
laser: ({ from, to, frames }) => { laser: ({ from, to, frames }) => {
const color = frames.shift() const color = frames.shift()
line(from.x, from.y, to.x, to.y, color) line(from.x, from.y, to.x, to.y, color)
@ -404,7 +396,17 @@ function drawFX() {
line(x, y, x, y - dy * w, color) 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) effects = effects.filter(({ frames }) => frames.length > 0)