diff --git a/lib/cli.ex b/lib/cli.ex index db398e5..d17123b 100644 --- a/lib/cli.ex +++ b/lib/cli.ex @@ -58,6 +58,18 @@ defmodule ExTTRPGDev.CLI do parser: :string ] ] + ], + character: [ + name: "character", + about: "Generate characters for system", + args: [ + system: [ + value_name: "SYSTEM", + help: "A supported system, e.g. dnd5e", + required: true, + parser: :string + ] + ] ] ] ], @@ -116,6 +128,16 @@ defmodule ExTTRPGDev.CLI do ] ] ] + ], + gen: [ + name: "gen", + about: "system agnostic generation helpers", + subcommands: [ + name: [ + name: "name", + about: "Generate a random name" + ] + ] ] ] ) @@ -134,6 +156,9 @@ defmodule ExTTRPGDev.CLI do {[:system | sub_commands], parse_result} -> handle_system_subcommands(sub_commands, parse_result) + {[:gen | sub_commands], _} -> + handle_generate_subcommands(sub_commands) + {unhandled, _parse_result} -> str_command = unhandled @@ -178,6 +203,14 @@ defmodule ExTTRPGDev.CLI do :stat_block -> RuleSystems.RuleSystem.gen_ability_scores_assigned(system) |> IO.inspect() + + :character -> + character = RuleSystems.RuleSystem.gen_character!(system) + IO.puts("-- Name: #{character.name}") + + Enum.each(character.ability_scores, fn {ability, scores} -> + IO.puts("#{ability}: #{Enum.sum(scores)}") + end) end end @@ -201,6 +234,13 @@ defmodule ExTTRPGDev.CLI do end end + def handle_generate_subcommands([command | _subcommands]) do + case command do + :name -> + IO.inspect(Faker.Person.name()) + end + end + def show_abilities(%RuleSystems.RuleSystem{abilities: %Abilities{specs: specs}}) do Enum.each(specs, fn %Abilities.Spec{name: name, abbreviation: abbr} -> IO.puts("(#{abbr}) #{name}") diff --git a/lib/rule_systems/characters.ex b/lib/rule_systems/characters.ex new file mode 100644 index 0000000..7cea6d3 --- /dev/null +++ b/lib/rule_systems/characters.ex @@ -0,0 +1,12 @@ +defmodule ExTTRPGDev.RuleSystems.Characters do + @moduledoc """ + This module handles the definition of rule system characters, and what they do + """ + + defmodule Character do + @moduledoc """ + Definition of an individual character + """ + defstruct [:name, :ability_scores, :rule_system] + end +end diff --git a/lib/rule_systems/rule_system.ex b/lib/rule_systems/rule_system.ex index c358001..84665eb 100644 --- a/lib/rule_systems/rule_system.ex +++ b/lib/rule_systems/rule_system.ex @@ -4,6 +4,7 @@ defmodule ExTTRPGDev.RuleSystems.RuleSystem do alias ExTTRPGDev.RuleSystems.Abilities alias ExTTRPGDev.RuleSystems.Skills alias ExTTRPGDev.RuleSystems.Languages + alias ExTTRPGDev.RuleSystems.Characters @moduledoc """ Module for handling a specific Rule System @@ -88,4 +89,22 @@ defmodule ExTTRPGDev.RuleSystems.RuleSystem do when is_bitstring(spec_name) do Abilities.get_spec_by_name(abilities, spec_name) end + + @doc """ + Returns an auto generated character for the system + + ## Examples + iex> ExTTRPGDev.RuleSystems.gen_character(rule_system) + %Characters.Character{} + """ + def gen_character!(%RuleSystem{ + abilities: %Abilities{} = abilities, + metadata: %Metadata{} = metadata + }) do + %Characters.Character{ + name: Faker.Person.name(), + ability_scores: Abilities.gen_scores(abilities), + rule_system: metadata + } + end end diff --git a/mix.exs b/mix.exs index 10b5af3..1c46f72 100644 --- a/mix.exs +++ b/mix.exs @@ -33,7 +33,8 @@ defmodule ExTTRPGDev.MixProject do {:optimus, "~> 0.5"}, {:ex_doc, "~> 0.35", only: :dev, runtime: false}, {:poison, "~> 6.0"}, - {:credo, "~> 1.7", only: [:dev, :test], runtime: false} + {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, + {:faker, "~> 0.18"} # {:dep_from_hexpm, "~> 0.3.0"}, # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} ] diff --git a/mix.lock b/mix.lock index 568f10a..501498c 100644 --- a/mix.lock +++ b/mix.lock @@ -3,6 +3,7 @@ "credo": {:hex, :credo, "1.7.10", "6e64fe59be8da5e30a1b96273b247b5cf1cc9e336b5fd66302a64b25749ad44d", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "71fbc9a6b8be21d993deca85bf151df023a3097b01e09a2809d460348561d8cd"}, "earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"}, "ex_doc": {:hex, :ex_doc, "0.35.1", "de804c590d3df2d9d5b8aec77d758b00c814b356119b3d4455e4b8a8687aecaf", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "2121c6402c8d44b05622677b761371a759143b958c6c19f6558ff64d0aed40df"}, + "faker": {:hex, :faker, "0.18.0", "943e479319a22ea4e8e39e8e076b81c02827d9302f3d32726c5bf82f430e6e14", [:mix], [], "hexpm", "bfbdd83958d78e2788e99ec9317c4816e651ad05e24cfd1196ce5db5b3e81797"}, "file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, "makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"}, diff --git a/test/rule_systems_test.exs b/test/rule_systems_test.exs index ba532be..9bff586 100644 --- a/test/rule_systems_test.exs +++ b/test/rule_systems_test.exs @@ -9,7 +9,8 @@ defmodule ExTTRPGDevTest.RuleSystems do system_path!: 1, load_system!: 1, save_system!: 1, - save_system!: 2 + save_system!: 2, + gen_character!: 1 ] def build_test_system do @@ -134,4 +135,19 @@ defmodule ExTTRPGDevTest.RuleSystems do bundled_system = RuleSystems.load_system!(bundled_system_slug) assert_raise RuntimeError, fn -> RuleSystems.save_system!(bundled_system) end end + + test "gen_character!/1" do + dnd_5e_srd = RuleSystems.load_system!("dnd_5e_srd") + generated_character = RuleSystems.RuleSystem.gen_character!(dnd_5e_srd) + + assert generated_character.name != nil + assert generated_character.rule_system == dnd_5e_srd.metadata + + # Assert that each ability spec is found within the generated character's ability_scores + dnd_5e_srd.abilities.specs + |> Enum.each(fn spec -> + score = Map.get(generated_character.ability_scores, spec.name) + assert score != nil, "Could not find ability #{spec.name} on generated character" + end) + end end