Account for duplicate keys in VDF to JSON transformation#7
Merged
Conversation
- 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
jcoene
approved these changes
Feb 14, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.txtduplicate 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.jsonwill be affected by this change for now, which is described below: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.