buttplugio / buttplug

Rust Implementation of the Buttplug Sex Toy Control Protocol
https://buttplug.io
Other
895 stars 65 forks source link

Break buttplug device config into directory tree with smaller files #616

Closed qdot closed 8 months ago

qdot commented 8 months ago

Right now, the Buttplug Device Config system consists of 2 monolithic files:

Both of these files consist of a single, large tree of either protocols and their various communication configurations and device definitions, or user configurations (which are defined under the same tree type and schema as the core).

The solution was going to be moving to sqlite, but that is turning out to be way more of a beast to implement than I planned on. Distributing updates of the DB to the user will be very difficult, it won't be easy to pack into the library, it makes WASM compilation extremely difficult, etc... It also still gives us a single file to write to and possibly overwrite, which is our whole problem in the first place. We also don't have THAT many keys/identifiers/foreign relations, and data replication here barely costs kilobytes, so an RDBMS is ending up being overkill.

Therefore, I'd like to break both of these files up into a tree of directories/files, for separate reasons.

Things I'd like to fix

User Device Config File

The user device config file is the most important part of this. Right now, if the user makes hand edits to the device config file, Intiface Central will stomp on it when it saves other user data, because I haven't built in all of the proper reserialization yet. Not to mention, it'd be nice if we could just change as little as possible within files when writing out data, as most of our keys are static anyways.

I'd like to break this out so that keys are directories, and the leaf data is files. This directory tree would look something like:

- user_config
  - lovense
    - comms
      - websocket.json
      - serial.json
    - configs
      - [identifier name, see potential issues below for how this might go badly]
        - [device address, somehow sanitized for directory naming]
          - user_config.json

This would allow us to save only the files we need to change when making GUI edits to anything, which will still allow hand editing while we wait on me to actually build the UI out for full configuration.

For user_config.json, I'd like to be able to store the device limits in that file. I'm tempted to maybe just store the device configuration as a whole and use that as our source of truth for a device with the (protocol, identifier, address) tuple match.

Core Device Config

As far as we're concerned, the core device config file is ours to do with what we want. We can stomp it at any time, and do not expect users to change it.

There are still problems with it though. The file itself is getting huge, and it's hard to reason about things quickly within it. It's also difficult to build parsers (lots of nodes 'til we hit leaves in the graph, all of which have to be defined), and the json schema for it is quite complicated.

We could take a similar approach to the user device config, with a directory tree that looks something like this:

- protocols
  - aneros
    - comms 
      - btle.json
    - configs
      - default.json
      - configs.json  [See potential issues for why there isn't an identifier directory here like in user config]
  - nintendo-joycon
    - comms
      - hid.json 
  - etc

Potential Issues

qdot commented 8 months ago

@blackspherefollower pinging you for thoughts.

qdot commented 8 months ago

Ok, having had a day to mull this over: Still on board with my ideas about user config, base device config I think we can punt on for a while longer. We can start with the file/directory tree for user config, and work from there. The user config and internal representations within the system are really all we're worried about anyways, dividing up the base config was more of a "it might be easier in the long run" but I'm not really convinced that yak needs immediate shaving.

qdot commented 8 months ago

My notes from trying to come up with a design for this.

Device Config Outline

Goals

Device Configurations

Types of Device Configurations

Where things are saved

Buttplug Interface Changes Needed

qdot commented 8 months ago

Actually, nah. Didn't need any of this. Just rebuilding the configs to actually consider ease to serialization and user configurability.