Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Extendable configuration providers and TOML provider #267

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

ghorsington
Copy link
Contributor

@ghorsington ghorsington commented Jun 27, 2021

Extends configuration API to allow swappable configuration readers and writers.
This PR also generally updates the configuration API.

As this is a Draft PR, suggestions and ideas are welcome.

Description

This PR cleans up and extends BepInEx configuration API. The most important changes are

  • Adds swappable configuration providers
  • Removes obsoleted configuration API
  • Adds support for binding to compound data types (lists, data classes)
  • Implements TOML configuration provider as the new default

Motivation and Context

At the moment, BepInEx supports a subset of TOML/INI with which handling compound data types is not easy.
Additionally, there have been calls for supporting writing to different configuration formats (JSON, INI, msgpack) and stores (file, memory, SQL, web).
This PR attempts to add general support for new configuration formats and sources by introducing configuration providers.

Configuration providers

A configuration provider is a low-level abstraction over a configuration store. A configuration provider implements a basic CRU(D) API and thus can

  • load and save the configuration
  • read a configuration node by a path
  • write a configuration node to a path

A path is represented as a string[], which allows for nesting and arrays.
A configuration node contains minimal metadata to read/write a single non-compound configuration value. The layout of a node is

public class ConfigurationNode
{
    // Configuration value as a string
    public string Value { get; set; }
    // Optional comment of the node
    public string Comment { get; set; }
    // Type hint. This can be used by the writer to generate the correct output
    public Type ValueType { get; set; }
}

A single node must always contain a non-compound value (number, string, date). Compound data types are, in turn, represented as multiple nodes.

This PR will also add a proper TOML provider.

Configuration API cleanup

TODO: Plan out a new API and consolidate suggestions of other PRs.

TODOS:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant