Expand description

dfraw_json_parser provides a way to turn raw files from Dwarf Fortress into JSON. It’s currently useful for getting some basic information from from a limited set of raw types:

  • creatures
  • plants
  • inorganics (rocks, ores, etc)

How It Works

It functions using a regular expression to break apart the tokens and then checks the key in the token against a long list of ones it knows about. Any matches are utilized to build its own representation of the raw before a final step where it dumps it to JSON and returns a JSON string.

Tauri Support

This library was built to provide raw parsing for another project, Overseer’s Reference Manual, which creates a tauri app that lets the user look at the raws on their machine in a searchable and filterable manner. The “tauri” feature flag enables functions which will emit parsing progress back to the tauri window.

Glossary of Terms

Raw

A raw is a definition used by Dwarf Fortress to create creatures, things and objects in the world. They can be used to also define how things interact. They are composed of a variety of tokens inside a raw file, starting with an identifier token of [#type#:#identifier#]. Raws can also select and modify other raws using a [SELECT:#identifier#] token.

Raw File

A raw file is a single text file (with .txt extension) which has the first line as the raw file identifier, and then defines the type of raw file using the [OBJECT:#type#] token. The file can contain any number of raws of that type.

Raw File Module, Raw Module

Since Dwarf Fortress 50, raws are organized into directories. (Previously they were in a flat structure.) This was done to facilitate the steam workshop.

Raw Module Location, Module Location

Raw file module folders are located in 3 locations that this library recognizes:

  • $df_game_dir/data/vanilla: the vanilla raws are here
  • $df_game_dir/data/installed_mods: the workshop mods which have been used in generating a world are here. They are considered installed because they are in use by at least one world. (Note: these are never removed even if you delete all worlds which use them.)
  • $df_game_dir/mods: the workshop mods are stored here to be available when creating a world

Info Text File

In each raw module, there is an info.txt file which contains information about that module, like author, version, earliest compatible version (for updating in existing saves), and information for the steam workshop if it is a mod downloaded from the steam workshop.

Functions

parse_announcements_txt takes a path to a announcements.txt file, parses it, and returns a JSON string
It parses the announcements.txt file and writes the result to a file as JSON.
Parse all raw files within the game directory to JSON.
Parse all the game raws and saves the result to a JSON file.
Parse all info.txt within the modules found in the game directory to JSON.
Parse all info.txt within the modules found in the game directory and saves a JSON file.
Parse all info.txt files within the module location to JSON.
Parse an info.txt file from a raw module to JSON.
Parse all raws within the module location to JSON.
Parse all the raw modules within a raw module location, and writes the parsed JSON string to a file.
Parse a raw module to JSON.
Parse a single raw module directory, and writes the parsed JSON string to a file.
Parse a single raw file to JSON.
Parse a single raw file and writes the parsed raw array to a JSON file.
It takes a JSON string of announcements, converts it to a vector of announcements, then writes it to a txt file