Skip to content

Official API

Basilius Sauter edited this page Feb 7, 2021 · 1 revision

This is a list of official APIs (such as hooks, events) that are present in the core.

Console commands

Events

Game loop

h/lotgd/core/default-scene

Hook for intercepting cases where a user does not have a viewpoint. Can be used to provide an entry point to the Game for characters.

Context data

  • character: LotGD\Core\Models\Character. The character requiring a default scene (instance of
  • scene: ?LotGD\Core\Models\Scene. The desired default scene to create a viewpoint from.

h/lotgd/core/navigate-to/{target}

Hook for navigating to a certain scene. target is no-template if the Scene does not have a SceneTemplate, or the return value of the corresponding SceneTemplates' SceneTemplate::getNavigationEvent() method.

Context data

  • referrer: LotGD\Core\Models\Scene, the scene the character comes from.
  • viewpoint: LotGD\Core\Models\Viewpoint, the scene the character comes from.
  • scene: LotGD\Core\Models\Scene, the scene the character comes from.
  • parameters: array, parameters from the action causing this scene change.
  • redirect: str, Scene ID to redirect to.

h/lotgd/core/scene-renderer/templateValues

Hook to provide additional values to a scene description for twig formatting.

Context data

  • templateValues: ["Character": LotGD\Core\Models\Character, "Scene": LotGD\Core\Models\Scene.

h/lotgd/core/scene-renderer/securityPolicy

Hook to change what's allowed in a scene description to access. If you add models to the templateValue hook, you must allow accessible methods and properties in here, too. Write tests when in doubt!

Context data

  • tags: array, list of twig tags allowed (default: if), see here.
  • filters: array, list of twig filters allowed (default: lower, upper, escape), see here. Do not remove escape from this list.
  • functions: array, list of twig functions allowed (default: range), see here.
  • methods: array, associative array of class: [method, ...] that are allowed to access. Default:
[
  LotGD\Core\Models\Character => [
    "getDisplayName", 
    "getLevel", 
    "isAlive", 
    "getHealth", 
    "getMaxHealth", 
    "getProperty"
  ],
  LotGD\Core\Models\Scene => [
    "getProperty"
  ] 
]
  • properties: array, associative array of property: fields that are allowed to access.

Character

h/lotgd/core/getCharacterAttack

Hook to change the character's base attack value. Use it to add in attack values from weapons, for example. Buff values are not calculated in yet.

Context data

  • character: LotGD\Core\Models\Character
  • value: int, current attack value.

h/lotgd/core/getCharacterDefense

Hook to change the character's base defense value. Use it to add in defense values from armors, for example. Buff values are not calculated in yet.

Context data

  • character: LotGD\Core\Models\Character
  • value: int, current attack value.

h/lotgd/core/characterStats/populate

Hook to populate Character stats with additional values to display (experience, wealth ...)

Context data

  • character: LotGD\Core\Models\Character
  • stats: LotGD\Core\Models\CharacterStats

Console commands

h/lotgd/core/cli/module-config-list/{vendor}/{package}

Gets raised by daenerys module:config:list and can be used by modules to provide a list of settings to alter the behaviour of the module.

Context data

  • module: LotGD\Core\Models\Module. Can be used to quickly set/get properties.
  • io: SymfonyStyle. Can be sued to manipulate console output.
  • settings: [[str, str, str], ...], a list of rows in the format of [setting, value, description]. Used to generate a table in the command.

h/lotgd/core/cli/module-config-set/{vendor}/{package}

Gets raised by daenerys module:config:set and can be used by modules to accept a setting and a value for configuration.

Context data

  • module: LoTGD\Core\Models\Module. Can be used to quickly set/get properties.
  • io: SymfonyStyle. Can be sued to manipulate console output.
  • setting: str, the name of a setting (should be listed in daenerys module:config:list)
  • value: str, the corresponding value (string). Conversion necessary.
  • return: int, a return value. By default its 1 (Symfony\Component\Console\Command\Command::FAILURE). Must be set to 0 if the command should be successful (Symfony\Component\Console\Command\Command::SUCCESS)
  • reason: str, the reason for failing. Change to whatever to report on errors (eg, if the value is not what you accept). Gets formatted as an error, and only displayed if return is 1.

h/lotgd/core/cli/module-config-reset/{vendor}/{package}

Gets raised by daenerys module:config:reset and can be used by modules reset a setting

Context data

  • module: LotGD\Core\Models\Module. Can be used to quickly set/get properties.
  • io: SymfonyStyle. Can be sued to manipulate console output.
  • setting: str, the name of a setting (should be listed in daenerys module:config:list)
  • return: int, a return value. By default its 1 (Symfony\Component\Console\Command\Command::FAILURE). Must be set to 0 if the command should be successful (Symfony\Component\Console\Command\Command::SUCCESS)
  • reason: str, the reason for failing. Change to whatever to report on errors (eg, if the value is not what you accept). Gets formatted as an error, and only displayed if return is 1.