Skip to content

Commit

Permalink
feat: add encyclopedia and link cards to their encyclopedia entries
Browse files Browse the repository at this point in the history
  • Loading branch information
dennyabrain committed Sep 3, 2024
1 parent a4f6e52 commit 4227c27
Show file tree
Hide file tree
Showing 32 changed files with 884 additions and 125 deletions.
4 changes: 2 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

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

config :viral_spiral, RoomConfig,
config :viral_spiral, EngineConfig,
affinities: [:cat, :sock, :skub, :houseboat, :highfive],
communities: [:red, :yellow, :blue],
chaos_counter: 10,
Expand Down
8 changes: 8 additions & 0 deletions lib/viral_spiral/affinity.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule ViralSpiral.Affinity do
defstruct target: nil

@type target :: :cat | :sock | :highfive | :houseboat | :skub
@type t :: %__MODULE__{
target: target()
}
end
8 changes: 8 additions & 0 deletions lib/viral_spiral/bias.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule ViralSpiral.Bias do
defstruct target: nil

@type target :: :red | :yellow | :blue
@type t :: %__MODULE__{
target: target()
}
end
22 changes: 0 additions & 22 deletions lib/viral_spiral/canon.ex

This file was deleted.

57 changes: 57 additions & 0 deletions lib/viral_spiral/canon/article.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
defmodule ViralSpiral.Canon.Article do
alias ViralSpiral.Canon.Article

defstruct id: nil,
card_id: "",
headline: "",
type: nil,
content: "",
author: "",
veracity: nil

# @type article_type :: :blog | :news | :official
@type t :: %__MODULE__{
id: UXID.uxid_string(),
card_id: String.t(),
headline: String.t() | any(),
type: String.t() | any(),
content: String.t() | any(),
author: String.t() | any(),
veracity: boolean()
}

# @article_types [:blog, :news, :official]

@spec new(String.t()) :: Article.t()
def new(headline) do
%Article{
id: UXID.generate!(prefix: "article", size: :small),
card_id: "card_" <> Integer.to_string(:erlang.phash2(headline))
}
end

@spec set_headline(Article.t(), String.t() | any()) :: Article.t()
def set_headline(%Article{} = article, headline) do
%{article | headline: headline}
end

@spec set_type(Article.t(), String.t() | any()) :: Article.t()
def set_type(%Article{} = article, type) do
%{article | type: type}
end

@spec set_content(Article.t(), String.t() | any()) :: Article.t()
def set_content(%Article{} = article, content) do
%{article | content: content}
end

@spec set_author(Article.t(), String.t() | any()) :: Article.t()
def set_author(%Article{} = article, author) do
%{article | author: author}
end

@spec set_veracity(Article.t(), boolean()) :: Article.t()
def set_veracity(%Article{} = article, veracity) do
%{article | veracity: veracity}
end
end
3 changes: 2 additions & 1 deletion lib/viral_spiral/canon/card/affinity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ defmodule ViralSpiral.Canon.Card.Affinity do
veracity: nil,
polarity: nil,
headline: nil,
image: nil
image: nil,
article_id: nil
end

# defmodule ViralSpiral.Canon.Card.Affinity.Cat do
Expand Down
3 changes: 2 additions & 1 deletion lib/viral_spiral/canon/card/bias.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ defmodule ViralSpiral.Canon.Card.Bias do
veracity: nil,
polarity: :neutral,
headline: nil,
image: nil
image: nil,
article_id: nil
end
6 changes: 5 additions & 1 deletion lib/viral_spiral/canon/card/conflated.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
defmodule ViralSpiral.Canon.Card.Conflated do
defstruct id: nil,
tgb: nil,
type: :conflated,
veracity: false,
polarity: :neutral,
headline: nil,
image: nil
image: nil,
article_id: nil
end
3 changes: 2 additions & 1 deletion lib/viral_spiral/canon/card/topical.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ defmodule ViralSpiral.Canon.Card.Topical do
veracity: nil,
polarity: :neutral,
headline: nil,
image: nil
image: nil,
article_id: nil
end
72 changes: 72 additions & 0 deletions lib/viral_spiral/canon/card_draw_spec.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
defmodule ViralSpiral.Canon.CardDrawSpec do
@moduledoc """
Specify requirements for the kind of card to draw.
This struct is passed to `ViralSpiral.Canon.Deck.draw_type()`
A common way to create a struct is by passing a current room's config
# Example struct
requirements = %{
tgb: 4,
total_tgb: 10,
biases: [:red, :blue],
affinities: [:cat, :sock],
current_player: %{
identity: :blue
}
}
"""
alias ViralSpiral.Game.State
alias ViralSpiral.Affinity
alias ViralSpiral.Bias
alias ViralSpiral.Game.Player
alias ViralSpiral.Canon.CardDrawSpec

defstruct tgb: 0,
total_tgb: Application.compile_env(:viral_spiral, EngineConfig)[:chaos_counter],
biases: [],
affinities: [],
current_player: nil

@type t :: %__MODULE__{
tgb: integer(),
total_tgb: integer(),
biases: list(Bias.target()),
affinities: list(Affinity.target()),
current_player: %{
identity: Bias.target()
}
}

@spec set_biases(CardDrawSpec.t(), list(Bias.target())) :: CardDrawSpec.t()
def set_biases(%CardDrawSpec{} = spec, biases) do
%{spec | biases: biases}
end

@spec set_affinities(CardDrawSpec.t(), list(Affinity.target())) :: CardDrawSpec.t()
def set_affinities(%CardDrawSpec{} = spec, affinities) do
%{spec | affinities: affinities}
end

@spec set_current_player(CardDrawSpec.t(), Player.t()) :: CardDrawSpec.t()
def set_current_player(%CardDrawSpec{} = spec, %Player{} = player) do
%{spec | current_player: adapt_player(player)}
end

defp adapt_player(%Player{} = player) do
%{identity: Player.identity(player)}
end

defp new(%State{} = state) do
%CardDrawSpec{
tgb: state.room.chaos_countdown,
# todo
biases: state.room_config.biases,
# todo
affinities: state.room_config.affinities
# todo
# current_player: player_store[state.turn.current]
}
end
end
Loading

0 comments on commit 4227c27

Please sign in to comment.