2 unstable releases
0.2.0 | Feb 17, 2021 |
---|---|
0.1.0 | Feb 13, 2021 |
#22 in #dwarf-fortress
16KB
318 lines
dfconfig-rs
A config/init file parser for Dwarf Fortress.
What?
A pure Rust implementation of DF's config file format parser, trying to be true to game's internal one. See the documentation for more info.
Why?
I need a DF config parser/manipulator for one of my other projects. Also, boredom.
How?
This library is hosted on crates.io, so using it in your project is as simple as:
[dependencies]
dfconfig = "0.1"
Contributing
PRs are welcome.
lib.rs
:
dfconfig is a lib for parsing and manipulating Dwarf Fortress' init.txt
and d_init.txt
config files (and possibly many others using the same format).
This lib's functionality has been specifically tailored to behave similar as DF internal parser, which implies:
Config::get
returns the last occurrence value, if config specifies the key more than once.- Whitespaces are not allowed at the start of lines, any line not starting with
[
character is treated as a comment.
Other notable functionality is that the parser preserves all of the parsed string content, including blank lines and comments.
Examples
use std::fs::{read_to_string, write};
use dfconfig::Config;
// Parse existing config
let path = r"/path/to/df/data/init/init.txt";
let mut conf = Config::read_str(read_to_string(path)?);
// Read some value
let sound = conf.get("SOUND");
// Modify and save the config
conf.set("VOLUME", "128");
write(path, conf.print())?;
Dependencies
~2.2–3MB
~55K SLoC