resmond 0.9.9

Library for reading Valve's KeyValues/QC files, used in Source and GoldSrc


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Resmond

This library reads (but does not write) KeyValues files from the Source and GoldSrc engines. This format is also known as .qc or .res.

Rationale

KeyValues is a really nice format in a lot of ways (it's very flexible, for one.) I also wanted some practice writing parsers and thought implementing TrackerScheme.res into a UI toolkit could be interesting. To date, Resmond is the solidest parsing and data management I've ever written.

Example

test.res:

// a few root keys -- note that these mean nothing to the parser, and are included for demonstration
// only
$version    1
$author     "midnaw <[email protected]>"

/* C-style comments are also supported, by the way! */

test
{
    // integrals
    "sixty"     60
    "ten"       10
    // a decimal
    "six"       7.56756756
    // even a string
    "string"    "hello, wurst"
    // you can even nest blocks
    "subblock"
    {
        // the dollar sign before $lookAtMe doesn't mean anything special
        $lookAtMe       true    [$X360]     // $X360 here is a condition
        $lookAtMe       no      [$PC]       // no == false == off, just as yes == true == on
        $lookAtMe       "seven"             // this will be chosen if neither X360 nor PC are set
        lookAtMe        yes                 // lookAtMe and $lookAtMe are separate variables
    }
}

app.d:

import std.file;
import std.stdio;

import resmond.keyvalue;
import resmond.parser;

void main() {
    // parse ./test.res as a keyvalues file
    KeyValuePair[] doc = ResParser.parseDoc(readText("./test.res"));
    // some variables
    doc.get("$version"); // => Variant(1)
    doc.get("$author");  // => Variant("midnaw <[email protected]>")
    doc.get("test.subblock.$lookAtMe", buildEnv("X360", true));  // => Variant(true)
    doc.get("test.subblock.$lookAtMe", buildEnv("PC", true));    // => Variant(false)
    doc.get("test.subblock.$lookAtMe", buildEnv("X360", false)); // => Variant("seven")
    doc.get("test.subblock.lookAtMe"); // => Variant(true)
    // if you need a variable in a specific type, instead of a variant, you can use
    // getConv!T or getCoerce!T
    doc.getConv!string("$author"); // => "midnaw <[email protected]>"
    doc.getConv!long("$version"); // => 1 <long>
    doc.getCoerce!uint("$version"); // => 1 <uint>
    // and that's about all :)
}

License

This software is released under the terms of the Boost Software License, version 1.0. For details, see LICENSE.

Authors:
Dependencies:
none
Versions:
1.0.0 2025-Feb-01
0.9.9 2025-Feb-01
~main 2025-Feb-01
Show all 3 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 0 downloads total

Score:
0.0
Short URL:
resmond.dub.pm