Skip to content

Commit 8d6a2f9

Browse files
committed
refactor: cleanup obstacle mapping
1 parent 2880bea commit 8d6a2f9

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

apps/bot_manager/lib/game_socket_handler.ex

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ defmodule BotManager.GameSocketHandler do
149149
obstacles =
150150
state.game_state.obstacles
151151
|> Enum.map(fn {obstacle_id, obstacle} ->
152-
{obstacle_id,
153-
Map.take(Map.from_struct(obstacle), [
152+
obstacle = obstacle
153+
|> Map.from_struct()
154+
|> Map.take([
154155
:id,
155156
:shape,
156157
:position,
@@ -161,27 +162,16 @@ defmodule BotManager.GameSocketHandler do
161162
:direction,
162163
:is_moving,
163164
:name
164-
])}
165-
end)
166-
|> Enum.map(fn {obstacle_id, obstacle} ->
167-
{obstacle_id, Map.put(obstacle, :position, %{x: obstacle.position.x, y: obstacle.position.y})}
168-
end)
169-
|> Enum.map(fn {obstacle_id, obstacle} ->
170-
{obstacle_id,
171-
Map.put(
172-
obstacle,
173-
:vertices,
174-
Enum.map(obstacle.vertices.positions, fn position -> %{x: position.x, y: position.y} end)
175-
)}
176-
end)
177-
|> Enum.map(fn {obstacle_id, obstacle} ->
178-
{obstacle_id, Map.put(obstacle, :direction, %{x: obstacle.direction.x, y: obstacle.direction.y})}
179-
end)
180-
|> Enum.map(fn {obstacle_id, obstacle} ->
181-
{obstacle_id, Map.put(obstacle, :shape, get_shape(obstacle.shape))}
182-
end)
183-
|> Enum.map(fn {obstacle_id, obstacle} ->
184-
{obstacle_id, Map.put(obstacle, :category, get_category(obstacle.category))}
165+
])
166+
167+
obstacle = obstacle
168+
|> Map.put(:position, %{x: obstacle.position.x, y: obstacle.position.y})
169+
|> Map.put(:vertices, Enum.map(obstacle.vertices.positions, fn position -> %{x: position.x, y: position.y} end))
170+
|> Map.put(:direction, %{x: obstacle.direction.x, y: obstacle.direction.y})
171+
|> Map.put(:shape, get_shape(obstacle.shape))
172+
|> Map.put(:category, get_category(obstacle.category))
173+
174+
{obstacle_id, obstacle}
185175
end)
186176
|> Map.new()
187177

0 commit comments

Comments
 (0)