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

Account for duplicate keys in VDF to JSON transformation #7

Merged
merged 2 commits into from
Feb 14, 2017

Conversation

watbe
Copy link
Contributor

@watbe watbe commented Feb 14, 2017

Valve's VDF format is pretty freeform - duplicate keys are permissible. Unfortunately it is hard to distinguish between errors and intentional duplicate keys. For most VDFs, duplicate keys appear to be errors (certain keys are specified more than once with the same value). However, in items_game.txt duplicate keys appear to serve a purpose. This PR allows us to specify specific files where duplicate keys are allowed, and transform the VDFs to JSON accordingly. More details below.

While it would be best to have this behaviour (allow duplicate keys) by default for all conversions, I am conscious not to break any projects currently using these files. This is tricker with the fact that not all keys in all objects are consistently arrays, so code will need to be updated to support the fact that any key could have multiple values represented as an array, or a singular value represented without an array.

As a result, only items_game.json will be affected by this change for now, which is described below:

  • If duplicate keys are encountered, the values of the JSON hash values for that key are changed into arrays. This is similar to hash-map key collision resolution. Multiple values of that key are appended to the array on first-in basis.
  • Note that this may result in duplicate data as it is possible for Valve to specify duplicate keys in error.
  • Consumers of this data should take the first value of an array if they do not expect to be consuming multiple values for a particular key.

This PR also adds a command line arugment to update.rb. This allows someone to run the update script without extracting the VPK and only runs the VDF > JSON generation step. This requires that the VDF's already exist in the corresponding paths (they are checked into this repo).

To regenerate the JSON files, simply run ruby update.rb --skip-vpk.

- If duplicate keys are encountered, the values of the hash entries are
  changed into arrays.
- Note that this may result in duplicate data as it is possible for
  Valve to specify duplicate keys in error.
- Consumers of this data should take the first value of an array if
  they do not expect to be consuming an array for a particular key.

only allow duplicate keys if specified
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

2 participants