The Game Panel Design record
The Game Panel
ADR-0005 Accepted

Configuration is held Hold configuration in typed objects

Comparing
v1 to v2
Current
Read the document

Context

The engine's components need configuration, and so do modulesmodules. The The code that consumes a configuration needs to rely rely on its shape and on the types of its values.

Decision

Each I will hold each configuration is in an instance of a class unique to that configurationit, registered against a module a module and a name. . Its values are will be typed properties, and it may contain child objects, so so that the class enforces the shape and types of a the configuration are enforced by its class rather than by the code that reads it. A A configuration object is object will be found by its module and name, , or by its class, and a a component receives will receive the one it needs by its class.

Alternatives

Whether anything was weighed against typed objects is not recorded. Configuration held in arrays Arrays read by key is the are the obvious other option, , and gives would give no type safety, since nothing enforces the shape of an array or the types of its its values, but nothing nothing records it them being considered.

Consequences

Easier:

  • Code reading configuration works will work with typed values that static analysis can check, rather than looking keys up up keys and casting what it finds.
  • Because each configuration has a class of its own, a component can will be given able to receive its configuration by type.

Harder:

  • Every configuration needs will need a class.
  • Configuration stored in a file format has will have to be hydrated into its class, and fails will fail if it cannot be.

Constrained:

  • Components and modules modules will define their configuration as classes, registered against a a module and a name.

Sources

  • Issue #22, Engine - Config, and not edited since: configuration as instances of classes unique to each configuration, registered against a name and a module, and injected because each is a unique class. This is created.
  • PR #25, feat(config): Add config component, merged and squashed as 180794a: ConfigObject and ConfigCatalogue, with lookup by module and name or by class. This is decided.
  • Type safety as the reason for the decision: first written down on .
  • Issue #31, Engine - Config - TOML, revision of in its edit history: hydration from a file format that fails when a section cannot hydrate, taken from what followed rather than anticipated.

Source adr/0005-typed-configuration.md · commit 9444a99 · published