protected void RegisterMapping(ResourceMappingChecker checker, ResourceMappingMapper mapper, ResourceMappingMode mappingMode, ResourceGameMode replacementGameMode = ResourceGameMode.All, string pathToWhitelist = null) { // turn off replacement if not supported by current mode if (!IsCurrentGameMode(replacementGameMode)) { mappingMode &= ~ResourceMappingMode.Replacement; } if (mappingMode == ResourceMappingMode.None) { return; } var mapperId = GetMapperId(mapper); var mapperEntries = _checkers.GetOrInit(checker); var entry = mapperEntries.FirstOrDefault(e => e.MapperId == mapperId); if (entry == null) { mapperEntries.Add(new MapperEntry(mapperId, mappingMode)); } else { entry.Mode |= mappingMode; } if (_checkerModes.ContainsKey(checker)) { _checkerModes[checker] |= mappingMode; } else { _checkerModes[checker] = mappingMode; } if (!pathToWhitelist.IsNullOrEmpty()) { WhiteListPaths.Add(pathToWhitelist); } if (!HasReplacementMappingsForCurrentGameMode && (mappingMode & ResourceMappingMode.Replacement) == ResourceMappingMode.Replacement && (replacementGameMode & _currentModeFlag) == _currentModeFlag) { HasReplacementMappingsForCurrentGameMode = true; } ResetCaches(); }
private int GetMapperId(ResourceMappingMapper mapper) { foreach (var entry in _mappers) { if (entry.Value == mapper) { return(entry.Key); } } var result = _nextMapperId++; _mappers[result] = mapper; return(result); }