data displaying properly now
This commit is contained in:
@@ -17,17 +17,18 @@ defmodule CobblemonUi.CobblemonFS.PCStore do
|
||||
def parse(path) do
|
||||
with {:ok, data} <- File.read(path),
|
||||
{:ok, {_name, root}} <- NBT.decode(data) do
|
||||
boxes = Map.get(root, "boxes", %{})
|
||||
{:ok, normalize_boxes(boxes)}
|
||||
{:ok, normalize_boxes(root)}
|
||||
else
|
||||
{:error, :enoent} -> {:error, :not_found}
|
||||
{:error, reason} -> {:error, {:corrupt_data, reason}}
|
||||
end
|
||||
end
|
||||
|
||||
defp normalize_boxes(boxes) when is_map(boxes) do
|
||||
boxes
|
||||
|> Enum.filter(fn {key, _} -> String.starts_with?(key, "box") end)
|
||||
defp normalize_boxes(root) when is_map(root) do
|
||||
root
|
||||
|> Enum.filter(fn {key, val} ->
|
||||
String.match?(key, ~r/^Box\d+$/) and is_map(val) and map_size(val) > 1
|
||||
end)
|
||||
|> Enum.sort_by(fn {key, _} -> extract_index(key) end)
|
||||
|> Enum.map(fn {key, box_data} ->
|
||||
%{
|
||||
@@ -41,7 +42,7 @@ defmodule CobblemonUi.CobblemonFS.PCStore do
|
||||
|
||||
defp normalize_box_slots(box) when is_map(box) do
|
||||
box
|
||||
|> Enum.filter(fn {key, _} -> String.starts_with?(key, "slot") end)
|
||||
|> Enum.filter(fn {key, _} -> String.match?(key, ~r/^Slot\d+$/) end)
|
||||
|> Enum.sort_by(fn {key, _} -> extract_index(key) end)
|
||||
|> Enum.map(fn {_key, slot_data} -> Pokemon.normalize(slot_data) end)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user