basics being displayed

This commit is contained in:
2026-03-16 12:44:06 -06:00
parent ef64c5cd0d
commit c252ef0e11
21 changed files with 1283 additions and 43 deletions

View File

@@ -0,0 +1,30 @@
defmodule CobblemonUi.CobblemonFS.PartyStore do
@moduledoc """
Parses a player's party storage `.dat` file.
Party layout:
Root -> party -> slot0..slot5
"""
alias CobblemonUi.CobblemonFS.{NBT, Pokemon}
@party_slots 6
@doc """
Reads and parses a party `.dat` file at the given path.
Returns `{:ok, [pokemon | nil]}` or `{:error, reason}`.
"""
@spec parse(String.t()) :: {:ok, list(map() | nil)} | {:error, term()}
def parse(path) do
with {:ok, data} <- File.read(path),
{:ok, {_name, root}} <- NBT.decode(data) do
party = Map.get(root, "party", %{})
slots = for i <- 0..(@party_slots - 1), do: Pokemon.normalize(Map.get(party, "slot#{i}"))
{:ok, slots}
else
{:error, :enoent} -> {:error, :not_found}
{:error, reason} -> {:error, {:corrupt_data, reason}}
end
end
end