DevJoy.Character behaviour (DevJoy v2.0.0)

View Source

A 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.DataModule

Base 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
end

All 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.

t()

The type representing the character structure.

Field types

animation()

@type animation() :: atom()

The type representing the character's animation type. Often combined with sprie.

data()

@type data() :: Keyword.t()

The type representing the additional data fields that can be retrieved for a character.

expression()

@type expression() :: atom()

The type representing the character's expression. Often combined with a sprie.

full_name()

@type full_name() :: String.t()

The type representing the character's full name.

id()

@type id() :: atom()

The type representing the unique identifier of the character.

info()

@type info() :: String.t()

The type representing the additional character's information like a role or a title.

portrait()

@type portrait() :: Path.t()

The type representing the character's portrait image.

position()

@type position() :: :center | :left | :right

The type representing the character's position.

sprite()

@type sprite() :: Path.t()

The type representing the character's sprite image.

Main

%DevJoy.Character{}

(struct)

The character structure contains the following keys

  • animation - the animation type of the character
  • data - a keyword list of additional character data
  • expression - the expression type of the character
  • full_name - the full name of the character
  • id - the unique identifier of the character
  • info - the additional information of the character
  • portrait - the portrait image of the character
  • sprite - the sprite image of the character

base_fields()

@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.

get_character_data(id)

(optional)
@callback get_character_data(id()) :: data()

Returns the data of a character by its id.

get_character_fields(id)

(optional)
@callback get_character_fields(id()) :: base_fields()

Returns the base fields of a character by its id.

t()

@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.