-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from TTRPG-Dev/qmalcolm--reogranize-modules
Refactor modules to make them more consistent and split out CLI
- Loading branch information
Showing
13 changed files
with
405 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
defmodule ExTTRPGDev.Characters.Character do | ||
alias __MODULE__ | ||
alias ExTTRPGDev.Characters.Metadata | ||
alias ExTTRPGDev.RuleSystems | ||
|
||
@moduledoc """ | ||
Definition of an individual character | ||
""" | ||
defstruct [:name, :ability_scores, :metadata] | ||
|
||
@doc """ | ||
Load a character from json representation | ||
""" | ||
def from_json!(character_json) when is_bitstring(character_json) do | ||
character_json | ||
|> Poison.decode!( | ||
as: %Character{ | ||
metadata: %Metadata{ | ||
rule_system: %RuleSystems.Metadata{} | ||
} | ||
} | ||
) | ||
end | ||
|
||
@doc """ | ||
Returns an auto generated character for the system | ||
## Examples | ||
iex> Character.gen_character(rule_system) | ||
%Character{} | ||
""" | ||
def gen_character!(%RuleSystems.RuleSystem{ | ||
abilities: %RuleSystems.Abilities{} = abilities, | ||
metadata: %RuleSystems.Metadata{} = rule_system_metadata | ||
}) do | ||
character_name = Faker.Person.name() | ||
|
||
%Character{ | ||
name: character_name, | ||
ability_scores: RuleSystems.Abilities.gen_scores(abilities), | ||
metadata: %ExTTRPGDev.Characters.Metadata{ | ||
slug: | ||
character_name | ||
|> String.downcase() | ||
|> String.replace(~r/[!#$%&()*+,.:;<=>?@\^_`'{|}~-]/, "") | ||
|> String.replace(" ", "_"), | ||
rule_system: rule_system_metadata | ||
} | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule ExTTRPGDev.Characters.Metadata do | ||
@moduledoc """ | ||
Metadata for an individual charater | ||
""" | ||
defstruct [:slug, :rule_system] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.