Example #1
0
void FilePrefsDriver::set(const Preferences& p) {
    _current = p.copy();

    StringMap<Json> sound;
    sound["volume"]     = Json::number(p.volume);
    sound["speech"]     = Json::boolean(p.speech_on);
    sound["idle music"] = Json::boolean(p.play_idle_music);
    sound["game music"] = Json::boolean(p.play_music_in_game);

    StringMap<Json> keys;
    for (auto i : range<size_t>(KEY_COUNT)) {
        keys[kKeyNames[i]] = Json::number(p.keys[i]);
    }

    StringMap<Json> all;
    all["sound"] = Json::object(sound);
    all["keys"]  = Json::object(keys);

    String   path(format("{0}/config.json", dirs().root));
    ScopedFd fd(open(path, O_CREAT | O_TRUNC | O_WRONLY, 0644));
    String   pretty(pretty_print(Json::object(all)));
    write(fd, utf8::encode(pretty));
}
Example #2
0
void NullPrefsDriver::set(const Preferences& prefs) { _saved = prefs.copy(); }
Example #3
0
NullPrefsDriver::NullPrefsDriver(Preferences defaults) : _saved(defaults.copy()) {}