| 214 | } |
| 215 | |
| 216 | bool ContextControlsConfig::Load(const std::string& path) |
| 217 | { |
| 218 | std::error_code ec; |
| 219 | if (!std::filesystem::exists(path, ec)) |
| 220 | return false; |
| 221 | |
| 222 | ParamFile cfg; |
| 223 | cfg.Parse(RString(path.c_str())); |
| 224 | |
| 225 | int version = 0; |
| 226 | if (auto* e = cfg.FindEntry("contextControlsVersion")) |
| 227 | version = (int)*e; |
| 228 | (void)version; |
| 229 | |
| 230 | for (InputProfile& profile : profiles) |
| 231 | profile.ClearAll(); |
| 232 | |
| 233 | UserActionDesc* descs = InputSubsystem::GetUserActionDesc(); |
| 234 | for (int c = 0; c < ContextCount; ++c) |
| 235 | { |
| 236 | InputContext ctx = static_cast<InputContext>(c); |
| 237 | InputProfile& profile = profiles[c]; |
| 238 | for (int a = 0; a < UAN; ++a) |
| 239 | { |
| 240 | const ParamEntry* entry = cfg.FindEntry(BindingName(ctx, descs[a])); |
| 241 | if (!entry) |
| 242 | continue; |
| 243 | |
| 244 | const ParamEntry* modEntry = cfg.FindEntry(ModifierName(ctx, descs[a])); |
| 245 | const ParamEntry* scaleEntry = cfg.FindEntry(ScaleName(ctx, descs[a])); |
| 246 | const int n = entry->GetSize(); |
| 247 | for (int i = 0; i < n; ++i) |
| 248 | { |
| 249 | InputCode code = InputCode::FromLegacy((int)(*entry)[i]); |
| 250 | if (!code.valid()) |
| 251 | continue; |
| 252 | |
| 253 | int modRaw = -1; |
| 254 | if (modEntry && i < modEntry->GetSize()) |
| 255 | modRaw = (int)(*modEntry)[i]; |
| 256 | InputCode modifier = modRaw >= 0 ? InputCode::FromLegacy(modRaw) : InputCode{}; |
| 257 | |
| 258 | float scale = 1.0f; |
| 259 | if (scaleEntry && i < scaleEntry->GetSize()) |
| 260 | scale = (float)(*scaleEntry)[i]; |
| 261 | |
| 262 | profile.Bind(static_cast<UserAction>(a), InputBinding(code, modifier, ActivationMode::OnHold, scale)); |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | return true; |
| 268 | } |
| 269 | |
| 270 | bool ContextControlsConfig::Save(const std::string& path) const |
| 271 | { |
nothing calls this directly
no test coverage detected