mpf

Making Lights Config

Configuring lights in Mission Pinball Framework is a bit of effort. You need a config block for each light, and there are lots and lots of them. Rather than type it all in, I wanted to take some existing config files and add a bunch of single lines to them, and then have a magical script turn that gibberish into a valid config file. I also want to be able to renumber their outputs easily, so if I move them physically, I don't have a wiring, or coding nightmare - another magical script needed, one that understands Open Pinball Project numbering.

Here's the input file:

And the output file:

Here's what the first script does:

# This script processes a YAML file and applies the following modifications:
# 1. Ensures YAML file structure requirements are met.
# 2. Preserves comments.
# 3. Removes trailing whitespace.
# 4. Converts tabs to spaces.
# 5. Identifies blocks starting with "  light_", followed by text and ending with a colon (":"). A comment may follow. Such lines may follow each other without any intervening lines.
# 6. Ensures each block contains the required lines, in the following order, indented by 4 spaces:
#    - type:
#    - subtype:
#    - default_on_color:
#    - tags:
#    - number:
#    Existing lines are preserved and reordered if needed.
# 7. Fills in missing values for the above lines with default values if they are empty:
#    - type: grb
#    - subtype: led
#    - default_on_color: green
#    - tags: group
#    - number: 0-0-0
# 8. Ensures each block is separated by ONLY one blank line from the preceding YAML block or comment. This may require the deletion of lines, or the addition of one blank line in the case where there is no separation.
# 9. If a comment line contains "# tags: " followed by arbitrary text, this should replace the tags: line in this, and subsequent blocks. The comment itself remains unchanged in the output.

 


The second script that does the renumbering has more simple rules:

# This script processes a YAML file and modifies lines that match the pattern:
#     number: N1-N2-N3
#
# - N1 is a number that is monitored for changes.
# - N2 is always set to 0.
# - N3 increments sequentially when N1 remains the same.
# - When N1 changes, N3 resets to 0.
# - The script preserves indentation and all other lines as they are.


They will no doubt need a tidy up down the track, but I have a valid config for 99 lights and mpf is happy to run.