DevJoy.Character behaviour (DevJoy v2.0.0)
View SourceA character visually represented in the character's nameplate. This module provides a data structure and callbacks to retrieve character information. The logic for retrieving character data is split between a base module and a data module.
Configuration
Both modules are configurable using the application's configuration:
config :dev_joy, DevJoy.Character,
base_module: MyApp.BaseModule,
data_module: MyApp.DataModuleBase module usage
The base module is responsible for providing the data
to visually represent character.
The full name and portrait provide the minimum data to visually represent the character.
defmodule MyApp.BaseModule do
def get_character_fields(:john_doe) do
[full_name: "John Doe", portrait: "path/to/portrait.jpg"]
end
endAll fields are optional. If you don't specify a value for a full name,
it will be generated automatically by humanising the value of the id field.
For example with :john_doe id John Doe would be generated as a full name.
Data module usage
The data module is responsible for providing additional character data.
Such data is usually not visible in the game, but can influence it.
This is especially useful in combination with condition
and additional game state data stored in a database or other type of storage.
defmodule MyApp.DataModule do
def get_character_data(:john_doe) do
[level: :senior]
end
end
Summary
Field types
The type representing the character's animation type. Often combined with sprie.
The type representing the additional data fields that can be retrieved for a character.
The type representing the character's expression. Often combined with a sprie.
The type representing the character's full name.
The type representing the unique identifier of the character.
The type representing the additional character's information like a role or a title.
The type representing the character's portrait image.
The type representing the character's position.
The type representing the character's sprite image.
Main
The character structure contains the following keys
The type representing the base fields that can be retrieved for a character.
Returns the data of a character by its id.
Returns the base fields of a character by its id.
Field types
@type animation() :: atom()
The type representing the character's animation type. Often combined with sprie.
@type data() :: Keyword.t()
The type representing the additional data fields that can be retrieved for a character.
@type expression() :: atom()
The type representing the character's expression. Often combined with a sprie.
@type full_name() :: String.t()
The type representing the character's full name.
@type id() :: atom()
The type representing the unique identifier of the character.
@type info() :: String.t()
The type representing the additional character's information like a role or a title.
@type portrait() :: Path.t()
The type representing the character's portrait image.
@type position() :: :center | :left | :right
The type representing the character's position.
@type sprite() :: Path.t()
The type representing the character's sprite image.
Main
The character structure contains the following keys
animation- the animation type of the characterdata- a keyword list of additional character dataexpression- the expression type of the characterfull_name- the full name of the characterid- the unique identifier of the characterinfo- the additional information of the characterportrait- the portrait image of the charactersprite- the sprite image of the character
@type base_fields() :: [ animation: animation() | nil, expression: expression() | nil, full_name: full_name(), info: info() | nil, portrait: portrait() | nil, sprite: sprite() | nil ]
The type representing the base fields that can be retrieved for a character.
Returns the data of a character by its id.
@callback get_character_fields(id()) :: base_fields()
Returns the base fields of a character by its id.
@type t() :: %DevJoy.Character{ animation: animation() | nil, data: data(), expression: expression() | nil, full_name: full_name(), id: id(), info: info() | nil, portrait: portrait() | nil, position: position(), sprite: sprite() | nil }
The type representing the character structure.