Skip to content

Commit

Permalink
chore: make configuration idiomatic
Browse files Browse the repository at this point in the history
  • Loading branch information
dennyabrain committed Aug 14, 2024
1 parent 7d4815e commit 9e39d80
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 7 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# General application configuration
import Config
alias ViralSpiral.Game.RoomConfig

config :viral_spiral,
ecto_repos: [ViralSpiral.Repo],
Expand Down Expand Up @@ -61,6 +62,12 @@ config :logger, :console,
# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason

config :viral_spiral, RoomConfig,
affinities: [:cat, :sock, :skub, :houseboat, :highfive],
communities: [:red, :yellow, :blue],
chaos_counter: 10,
volatility: :medium

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"
15 changes: 9 additions & 6 deletions lib/viral_spiral/game/room_config.ex
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
defmodule ViralSpiral.Game.RoomConfig do
defstruct affinities: [:cat, :sock],
communities: [:red, :yellow, :blue],
chaos_counter: 10,
volatility: :medium
alias ViralSpiral.Game.RoomConfig

defstruct affinities: Application.compile_env(:viral_spiral, RoomConfig)[:affinities],
communities: Application.compile_env(:viral_spiral, RoomConfig)[:communities],
chaos_counter: Application.compile_env(:viral_spiral, RoomConfig)[:chaos_counter],
volatility: Application.compile_env(:viral_spiral, RoomConfig)[:volatility]
end

defmodule ViralSpiral.Game.RoomConfig.Guards do
@affinities [:cat, :sock, :highfive, :houseboat, :skub]
@communities [:red, :yellow, :blue]
alias ViralSpiral.Game.RoomConfig
@affinities Application.compile_env(:viral_spiral, RoomConfig)[:affinities]
@communities Application.compile_env(:viral_spiral, RoomConfig)[:communities]

defguard is_affinity(value) when value in @affinities

Expand Down
2 changes: 1 addition & 1 deletion test/support/fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule Fixtures do
alias ViralSpiral.Game.State

def initialized_game() do
room_config = %RoomConfig{}
room_config = %RoomConfig{} |> IO.inspect()

player_list = [
Player.new(room_config) |> Player.set_name("adhiraj"),
Expand Down

0 comments on commit 9e39d80

Please sign in to comment.