vdf icon indicating copy to clipboard operation
vdf copied to clipboard

Handling for #base and #include

Open rossengeorgiev opened this issue 8 years ago • 3 comments

Apparently the VDF format supports definitions for merging files.

  • #base will merge KVs from the specified file with the ones from the current
  • #include will append

I don't see how that could be implemented in the module reliably. It should be fairly simple to implement at application level for the specific use case. ~~That leaves allowing # symbol to be used as unquoted key or value, which is currently not supported~~.

rossengeorgiev avatar Apr 07 '16 07:04 rossengeorgiev

I hadn't seen that you had already created this issue, but I implemented something similar in my fork. I am dealing with theater files for Insurgency, which are KeyValues files that leverage #base extensively. I am also a very new Python programmer, so I am nearly certain that my merge function is inefficient, but it does produce correct output as far as the theater is concerned. Take a peek at my fork, and the theater.py file specifically. I don't know if merging all the theater specific things I will need (ordered list overrides, "include" directive within key types, distance-based lists and vector data types) will be useful to the wider project, but I'd be glad to help port over the useful stuff to the mainline code.

jaredballou avatar Aug 04 '16 13:08 jaredballou

Hi @jaredballou, the problem is that this module is supposed to (de)serialize to/from vdf/kv1. When we add #include and #base, how do you specify the location of the included files? Then it has to deal with encoding. What if the files are loaded from strings? It seem much more simpler to keep it as it is and let the application add that functionality for its' case, like you did.

One thing I think I could do is provide a method to merge VDFDicts.

rossengeorgiev avatar Aug 04 '16 14:08 rossengeorgiev

Yes, that'd be good. The way I do it is with wrapping the vdf functions in the theater class, and then I send the filename to the class, rather than a file handle. But seeing that these directives (and "[conditional]" statements) are part of the KeyValues standard, it does seem like it should be included. I still don't like how it works in my fork, probably because I am a very new Python coder, but if you wanted to work together to draw up a plan, I'd be happy to help.

jaredballou avatar Aug 24 '16 19:08 jaredballou