From 9e39d800a98b9cc27d3dd06544349706809f42d2 Mon Sep 17 00:00:00 2001 From: dennyabrain Date: Wed, 14 Aug 2024 17:48:40 +0530 Subject: [PATCH] chore: make configuration idiomatic --- config/config.exs | 7 +++++++ lib/viral_spiral/game/room_config.ex | 15 +++++++++------ test/support/fixtures.ex | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/config/config.exs b/config/config.exs index 20b2333..3157f5c 100644 --- a/config/config.exs +++ b/config/config.exs @@ -6,6 +6,7 @@ # General application configuration import Config +alias ViralSpiral.Game.RoomConfig config :viral_spiral, ecto_repos: [ViralSpiral.Repo], @@ -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" diff --git a/lib/viral_spiral/game/room_config.ex b/lib/viral_spiral/game/room_config.ex index b10ff7c..27d3627 100644 --- a/lib/viral_spiral/game/room_config.ex +++ b/lib/viral_spiral/game/room_config.ex @@ -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 diff --git a/test/support/fixtures.ex b/test/support/fixtures.ex index 5d6ea9f..90f2988 100644 --- a/test/support/fixtures.ex +++ b/test/support/fixtures.ex @@ -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"),