| 268 | } |
| 269 | |
| 270 | bool ContextControlsConfig::Save(const std::string& path) const |
| 271 | { |
| 272 | std::error_code ec; |
| 273 | std::filesystem::path p(path); |
| 274 | if (p.has_parent_path()) |
| 275 | std::filesystem::create_directories(p.parent_path(), ec); |
| 276 | |
| 277 | ParamFile cfg; |
| 278 | cfg.Add("contextControlsVersion", kContextControlsVersion); |
| 279 | |
| 280 | UserActionDesc* descs = InputSubsystem::GetUserActionDesc(); |
| 281 | for (int c = 0; c < ContextCount; ++c) |
| 282 | { |
| 283 | InputContext ctx = static_cast<InputContext>(c); |
| 284 | const InputProfile& profile = profiles[c]; |
| 285 | for (int a = 0; a < UAN; ++a) |
| 286 | { |
| 287 | const auto& entries = profile.GetBindingEntries(static_cast<UserAction>(a)); |
| 288 | if (entries.empty()) |
| 289 | continue; |
| 290 | |
| 291 | ParamEntry* codes = cfg.AddArray(BindingName(ctx, descs[a])); |
| 292 | codes->Clear(); |
| 293 | ParamEntry* mods = cfg.AddArray(ModifierName(ctx, descs[a])); |
| 294 | mods->Clear(); |
| 295 | ParamEntry* scales = cfg.AddArray(ScaleName(ctx, descs[a])); |
| 296 | scales->Clear(); |
| 297 | |
| 298 | for (const InputBinding& binding : entries) |
| 299 | { |
| 300 | codes->AddValue(binding.code.toLegacy()); |
| 301 | mods->AddValue(binding.modifier.valid() ? binding.modifier.toLegacy() : -1); |
| 302 | scales->AddValue(binding.scale); |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | cfg.Save(RString(path.c_str())); |
| 308 | return std::filesystem::exists(path, ec); |
| 309 | } |
| 310 | } // namespace Poseidon |
nothing calls this directly
no test coverage detected