diff --git a/CHANGELOG.md b/CHANGELOG.md index dcfa649..909ed5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.1.1 + +Add `.formatter.exs` file to release for `import_deps` + ## 0.1.0 Pre-release, this is not a production ready release ! diff --git a/README.md b/README.md index 165d881..8d367d8 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ The package can be installed by adding `elvengard_network` to your list of depen ```elixir def deps do [ - {:elvengard_network, "~> 0.1.0"} + {:elvengard_network, "~> 0.1.1"} ] end ``` diff --git a/guides/introduction/getting_started.md b/guides/introduction/getting_started.md index 567de1a..8eaea15 100644 --- a/guides/introduction/getting_started.md +++ b/guides/introduction/getting_started.md @@ -21,7 +21,7 @@ To add ElvenGard.Network to this application, just add an entry to your mix.exs: ```elixir defp deps do [ - {:elvengard_network, "~> 0.1.0"} + {:elvengard_network, "~> 0.1.1"} ] end ``` diff --git a/lib/elven_gard/network/packet_serializer.ex b/lib/elven_gard/network/packet_serializer.ex index ec3ef22..78fd17b 100644 --- a/lib/elven_gard/network/packet_serializer.ex +++ b/lib/elven_gard/network/packet_serializer.ex @@ -221,17 +221,32 @@ defmodule ElvenGard.Network.PacketSerializer do defp def_serialize(%{id: id, fields: fields}) do fields_ast = Enum.map(fields, fn %{name: name, type: type, opts: opts} -> - quote location: :keep do - case {Map.fetch!(var!(packet), unquote(name)), opts[:default]} do - {nil, value} when not is_nil(value) -> value - {value, _} -> unquote(type).encode(value, unquote(opts)) - end + case Keyword.get(opts, :if) do + nil -> + quote location: :keep do + case {Map.fetch!(var!(packet), unquote(name)), opts[:default]} do + {nil, value} when not is_nil(value) -> value + {value, _} -> unquote(type).encode(value, unquote(opts)) + end + end + + condition -> + quote location: :keep do + if unquote(condition) in [nil, false] do + :"$drop" + else + case {Map.fetch!(var!(packet), unquote(name)), opts[:default]} do + {nil, value} when not is_nil(value) -> value + {value, _} -> unquote(type).encode(value, unquote(opts)) + end + end + end end end) quote location: :keep, generated: true do def serialize(%__MODULE__{} = var!(packet)) do - {unquote(id), unquote(fields_ast)} + {unquote(id), Enum.reject(unquote(fields_ast), &match?(:"$drop", &1))} end end end diff --git a/mix.exs b/mix.exs index 68b40b5..7c38762 100644 --- a/mix.exs +++ b/mix.exs @@ -2,7 +2,7 @@ defmodule ElvenGard.Network.MixProject do use Mix.Project @app_name "ElvenGard.Network" - @version "0.1.0" + @version "0.1.1" @github_link "https://github.com/ImNotAVirus/elvengard_network" def project do @@ -51,7 +51,7 @@ defmodule ElvenGard.Network.MixProject do maintainers: ["ImNotAVirus"], licenses: ["MIT"], links: %{"GitHub" => @github_link}, - files: ~w(lib CHANGELOG.md LICENSE.md mix.exs README.md) + files: ~w(lib CHANGELOG.md LICENSE.md mix.exs .formatter.exs README.md) ] end