Skip to content
openmw-config
api

Setting types

SettingValue, FileSetting, DirectorySetting, GameSettingType, GenericSetting, EncodingSetting, EncodingType, TrailingComment and GameSettingMeta.

Each kind of line has its own type. The configuration hands them out by reference; you rarely build one yourself, but every type has a public constructor for when you do.

A constructor’s comment argument is the text written above the line when it is saved: whole comment lines, # and newline included, or empty. The constructor takes it and leaves the string empty.

SettingValue#

enum SettingValue

One entry of the configuration: a line, or for TrailingComment the lines that end a file. settings_matching hands these out. Non-exhaustive, so a match needs a _ arm. Clone, Debug.

VariantLineHolds
ContentFilecontent=FileSetting
Groundcovergroundcover=FileSetting
BethArchivefallback-archive=FileSetting
DataDirectorydata=, and the directories loading addsDirectorySetting
SubConfigurationconfig=DirectorySetting
Resources, UserData, DataLocalresources=, user-data=, data-local=DirectorySetting
Encodingencoding=EncodingSetting
GameSettingfallback=GameSettingType
Replacereplace=GenericSetting
GenericAny other key=valueGenericSetting
TrailingCommentComment and blank lines after a file’s last settingTrailingComment
Item
meta(&self) -> &GameSettingMetaIts source file and comment
DisplayIts line as it would be saved, comment included

FileSetting#

struct FileSetting

A file name from content=, groundcover= or fallback-archive=. Names are not resolved: OpenMW looks them up in its data directories. Clone, Debug.

Item
new(value: &str, source_config: &Path, comment: &mut String) -> FileSettingAttributed to source_config, an openmw.cfg path
value(&self) -> &StringThe name as written
value_str(&self) -> &strThe same, as &str
meta(&self) -> &GameSettingMetaIts source file and comment
DisplayThe name alone, without key or comment
PartialEq with FileSetting, str, &str, &StringCompares the name only, not where it came from

DirectorySetting#

struct DirectorySetting { pub meta: GameSettingMeta, .. }

A path from data=, config=, resources=, user-data= or data-local=, kept both as written and resolved. Clone, Debug.

Item
new<S: Into<String>>(value: S, source_config: PathBuf, comment: &mut String) -> DirectorySettingResolves value as a line in source_config: a relative path is anchored to the directory of source_config when it ends in openmw.cfg, and to source_config itself otherwise
parsed(&self) -> &PathThe resolved path: quotes removed, tokens replaced, separators normalized, anchored to its file’s directory
original(&self) -> &StringThe value as written, quotes and tokens included
original_str(&self) -> &strThe same, as &str
metaIts source file and comment, as a public field
Displayoriginal() and a newline

Use parsed() with the file system and original() when writing a config back.

GameSettingType#

enum GameSettingType { Color(..), String(..), Float(..), Int(..) }

A fallback=Key,Value line, typed by its value’s text. The first rule that fits wins:

VariantValue
ColorThree comma-separated whole numbers, each 0 to 255: 117,141,164
FloatContains a . and parses as a number: 1.5, .5
IntA whole number: -7
StringAnything else: 1e5, 256,0,0, hello, world

The variants hold types the crate does not export, so match on the variant or ask kind_name() to learn the kind, and use the methods for the rest. The enum is non-exhaustive. Clone, Debug, Eq.

Item
key(&self) -> &StringThe text before the first comma
key_str(&self) -> &strThe same, as &str
value(&self) -> Cow<'_, str>The text after the first comma, exactly as written: 1.50 stays 1.50
value_str(&self) -> &strThe same, borrowed
kind_name(&self) -> &'static str"Color", "String", "Float" or "Int"
int_value(&self) -> Option<i64>The number of an Int, None for the other kinds
float_value(&self) -> Option<f64>The number of a Float
color_value(&self) -> Option<(u8, u8, u8)>The red, green and blue of a Color
meta(&self) -> &GameSettingMetaIts source file and comment
DisplayThe whole line, comment included: fallback=Key,Value
PartialEqSame variant and same key; the value is ignored
PartialEq<&str>The key equals the string
TryFrom<(String, PathBuf, &mut String)>Parses Key,Value, attributed to the path. Fails with InvalidGameSetting without a comma

GenericSetting#

struct GenericSetting

A line whose key the crate does not recognize, kept so a round trip does not lose it. Clone, Debug.

Item
new(key: &str, value: &str, source_config: &Path, comment: &mut String) -> GenericSettingAttributed to source_config
key(&self) -> &strThe key
value(&self) -> &strThe value, as written
meta(&self) -> &GameSettingMetaIts source file and comment
DisplayThe comment and key=value

EncodingSetting#

struct EncodingSetting

An encoding= line. Clone, Debug.

Item
TryFrom<(String, P, &mut String)> where P: AsRef<Path>Parses win1250, win1251 or win1252, exactly, attributed to the path. Fails with BadEncoding otherwise
value(&self) -> EncodingTypeThe encoding
meta(&self) -> &GameSettingMetaIts source file and comment
PartialEqSame encoding
DisplayThe comment and encoding=<name>

EncodingType#

enum EncodingType { WIN1250, WIN1251, WIN1252 }

The code page OpenMW decodes plugin text with: WIN1250 Central European, WIN1251 Cyrillic, WIN1252 Western European and the default. Display gives the config spelling, win1252. Clone, Copy, Debug, Eq. Non-exhaustive.

TrailingComment#

struct TrailingComment

The comment and blank lines after a file’s last setting, kept so saving writes them back at the end of the file. meta() gives the file, and the lines as its comment; Display writes them. Clone, Debug.

GameSettingMeta#

struct GameSettingMeta

Where a setting came from. Clone, Debug, Eq.

MethodReturns
source_config(&self) -> &PathThe openmw.cfg the setting is attributed to; empty for entries loading added
comment(&self) -> &strThe comment lines above it, blank lines included

Every setting type has it: meta() on SettingValue, FileSetting, GameSettingType, GenericSetting, EncodingSetting and TrailingComment, and the public meta field on DirectorySetting.