redruin1 / factorio-draftsman

A complete, well-tested, and up-to-date module to manipulate Factorio blueprint strings. Compatible with mods.
MIT License
92 stars 17 forks source link

Blueprint with Programmable Speaker fail schema validation #72

Closed ca1f closed 1 year ago

ca1f commented 1 year ago

The following blueprint string causes draftman's blueprint string processing to fail:

0eNqNU+1u2zAMfBf+tovYa5rW2JsMg0A7rC1UX5DkbG7gdy9pJ0G6tU3/GNKJ4h1P5yO0ZqQQtcvQHEF
33iVofh0h6d6hESxPgaABnclCAQ6t7FImMmU3UMowF6Ddnv5CU83FzZsh+j6itdgaKlMgfKF41aKefxd
ALuusaVWybCblRttyZVN93amA4BNf9k4UcMNyd7+92xYw8bLabOq7LZPxmDl6o1oa8KB9lNpOx27UWfH
Z/tLgWceU1Y2RMGZtDMWpTAMZAytByiimVrKxASNm4YGfy/GJS2BLmWKS5iuNOiA/idJJBZ27AZpnNIn
EoJTjaNkOpffQbJjeZ1rX80rpqBPhS7NKPn0kctcuSjVbLPXvuYPBqcXuRR28GWUq1n3BeuNbNIYtZAU
shdf+jwreTGHw7gTPglP8b6iBS5eD8+0F8U5ZDGdIcndyeZH4idFjRKdHW0Y/un0qLfb4qh3BhdpSSth
LKcySxX+yU3+Y31uRqc6R+Z69ldgrKV60N1c/WAEHNmXhqR+r+91TvXt4qjePP+p5fgP/izkM

traceback:

  File "/lib/python3.11/site-packages/draftsman/prototypes/programmable_speaker.py", line 112, in __init__
    self.parameters = kwargs["parameters"]
    ^^^^^^^^^^^^^^^
  File "/lib/python3.11/site-packages/draftsman/prototypes/programmable_speaker.py", line 180, in parameters
    six.raise_from(DataFormatError(e), None)
  File "<string>", line 3, in raise_from
draftsman.error.DataFormatError: Key 'playback_volume' error:

it seems that factorio uses a single 1 to denote a 100% volume setting in a programmable speaker in the blueprint json string:

        "parameters": {
          "playback_volume": 1,
          "playback_globally": true,
          "allow_polyphony": true
        },

which in turn will be parsed by python's json implementation to a single int value and this fails the schema validation check in https://github.com/redruin1/factorio-draftsman/blob/7abe32f72f75ab6b5a18f81623762eebab85a363/draftsman/signatures.py#L244-L253

redruin1 commented 1 year ago

Fixed; this is now:

        { 
             Optional("playback_volume"): Use(float), 
             Optional("playback_globally"): bool, 
             Optional("allow_polyphony"): bool, 
         }

so when imported the value will be coerced to a float to keep things consistent. When I finish 2.0 hopefully schema will be replaced with something a little better. This will be in either version 1.0.5 or 2.0, whichever comes first.