diff --git a/lib/viral_spiral/canon.ex b/lib/viral_spiral/canon.ex index c3a5e76..62bb388 100644 --- a/lib/viral_spiral/canon.ex +++ b/lib/viral_spiral/canon.ex @@ -11,54 +11,11 @@ defmodule ViralSpiral.Canon do # @card_data "card.ods" # @encyclopedia "encyclopedia.ods" - @true_affinity_opts type: :affinity, veracity: true - @false_affinity_opts type: :affinity, veracity: false - @true_bias_opts type: :bias, veracity: true - @false_bias_opts type: :bias, veracity: false - @true_topical_opts type: :topical, veracity: true - @false_topical_opts type: :topical, veracity: false - @false_conflated_opts type: :conflated, veracity: false - defdelegate load_cards, to: Deck defdelegate create_store(cards), to: Deck - defdelegate create_sets(cards), to: Deck - - def draw_true_affinity_card(deck, tgb, target) do - opts = @true_affinity_opts ++ [tgb: tgb, target: target] - Deck.draw_card(deck, opts) - end - - def draw_false_affinity_card(deck, tgb, target) do - opts = @false_affinity_opts ++ [tgb: tgb, target: target] - Deck.draw_card(deck, opts) - end - - def draw_true_bias_card(deck, tgb, target) do - opts = @true_bias_opts ++ [tgb: tgb, target: target] - Deck.draw_card(deck, opts) - end - - def draw_false_bias_card(deck, tgb, target) do - opts = @false_bias_opts ++ [tgb: tgb, target: target] - Deck.draw_card(deck, opts) - end - - def true_topical_card(deck, tgb) do - opts = @true_topical_opts ++ [tgb: tgb] - Deck.draw_card(deck, opts) - end - - def false_topical_card(deck, tgb) do - opts = @false_topical_opts ++ [tgb: tgb] - Deck.draw_card(deck, opts) - end - - def false_conflated_card(deck, tgb) do - opts = @false_conflated_opts ++ [tgb: tgb] - Deck.draw_card(deck, opts) - end + defdelegate create_sets(cards, opts), to: Deck def encyclopedia() do end diff --git a/lib/viral_spiral/canon/deck.ex b/lib/viral_spiral/canon/deck.ex index 86a6cd3..c6f4186 100644 --- a/lib/viral_spiral/canon/deck.ex +++ b/lib/viral_spiral/canon/deck.ex @@ -2,7 +2,7 @@ defmodule ViralSpiral.Canon.Deck do @moduledoc """ Loads data from .csv files. - Viral Spiral writers use Google Sheet to organize the text content for the game. + Viral Spiral writers use Google Sheet to organize the text content for the game. The current sheet is [here](https://docs.google.com/spreadsheets/d/1070fP6LOjCTfLl7SoQuGA4FxNJ3XLWbzZj35eABizgk/edit?usp=sharing) Each sheet within the sheet is exported as .csv files and stored in the `priv/canon/` directory. This module encodes the conventions used by the writers in the file to generate structured data structures from the csv file. It also converts the structured data into datastructures optimized for the game's requirements.
@@ -15,15 +15,27 @@ defmodule ViralSpiral.Canon.Deck do Store is a Map of all cards. Keys in this Map are unique ids for every card and the values are cards (`ViralSpiral.Canon.Card.Affinity`, `ViralSpiral.Canon.Card.Bias`, `ViralSpiral.Canon.Card.Topical` and `ViralSpiral.Canon.Card.Conflated`). - Sets is a Map of cards. Keys of this Map are a tuple of the form `{type, veracity, target}`. Value of this Map is `MapSet` of cards. - + Sets is a Map of cards. Keys of this Map are a tuple of the form `{type, veracity, target}`. Value of this Map is `MapSet` of cards. For instance, for a room where the active affinities are :cat and :sock; and the active communities are :red and :yellow; the Sets would have the following keys : + [ + {:conflated, false}, + {:topical, false}, + {:topical, true}, + {:affinity, false, :cat}, + {:affinity, false, :sock}, + {:affinity, true, :cat}, + {:affinity, true, :sock}, + {:bias, false, :red}, + {:bias, false, :yellow}, + {:bias, true, :red}, + {:bias, true, :yellow} + ] ## Example Usage ```elixir cards = Deck.load_cards() store = Deck.create_store(cards) - sets = Deck.create_sets(store) + sets = Deck.create_sets(cards) card_id = Deck.draw_card(deck, type: :affinity, veracity: true, tgb: 0, target: :skub) card_id = Deck.draw_card(deck, type: :bias, veracity: true, tgb: 0, target: :red) @@ -83,6 +95,7 @@ defmodule ViralSpiral.Canon.Deck do conflated_image: 41 } @set_opts_default [affinities: [:cat, :sock], biases: [:red, :yellow]] + @card_master_sheet "all_cards.csv" def load_cards() do parse_file() @@ -129,7 +142,7 @@ defmodule ViralSpiral.Canon.Deck do end defp parse_file() do - File.stream!(Path.join([File.cwd!(), "priv", "canon", "all_cards.csv"])) + File.stream!(Path.join([File.cwd!(), "priv", "canon", @card_master_sheet])) |> CSV.decode() end @@ -496,4 +509,35 @@ defmodule ViralSpiral.Canon.Deck do key end end + + @doc """ + Determines what type of card to draw. + + Returns a tuple that should be a valid key of a Store. + + [ + {:conflated, false}, + {:topical, false}, + {:topical, true}, + {:affinity, false, :cat}, + {:affinity, false, :sock}, + {:affinity, true, :cat}, + {:affinity, true, :sock}, + {:bias, false, :red}, + {:bias, false, :yellow}, + {:bias, true, :red}, + {:bias, true, :yellow} + ] + + """ + def draw_type(opts \\ []) do + tgb = 4 + + bias_p = :rand.uniform() + fake_p = :rand.uniform() + draw_affinity = :rand.uniform() < 0.5 + draw_topical = not draw_affinity + draw_true = :rand.uniform() < 1 - 1 / 10 + {bias_p, fake_p, draw_affinity, draw_topical, draw_true} + end end