/// <summary>Load a matched asset.</summary> /// <param name="asset">Basic metadata about the asset being loaded.</param> public T Load <T>(IAssetInfo asset) { // get applicable patches for context IPatch[] patches = this.GetCurrentLoaders(asset).ToArray(); if (!patches.Any()) { throw new InvalidOperationException($"Can't load asset key '{asset.AssetName}' because no patches currently apply. This should never happen because it means validation failed."); } if (patches.Length > 1) { throw new InvalidOperationException($"Can't load asset key '{asset.AssetName}' because multiple patches apply ({string.Join(", ", from entry in patches orderby entry.LogName select entry.LogName)}). This should never happen because it means validation failed."); } // apply patch IPatch patch = patches.Single(); if (this.Monitor.IsVerbose) { this.Monitor.VerboseLog($"Patch \"{patch.LogName}\" loaded {asset.AssetName}."); } else { this.Monitor.Log($"{patch.ContentPack.Manifest.Name} loaded {asset.AssetName}.", LogLevel.Trace); } T data = patch.Load <T>(asset); foreach (IAssetValidator validator in this.AssetValidators) { if (!validator.TryValidate(asset, data, patch, out string error)) { this.Monitor.Log($"Can't apply patch {patch.LogName} to {asset.AssetName}: {error}.", LogLevel.Error); return(default);
/// <summary>Load a matched asset.</summary> /// <param name="asset">Basic metadata about the asset being loaded.</param> public T Load <T>(IAssetInfo asset) { IPatch patch = this.GetCurrentLoaders(asset).FirstOrDefault(); if (patch == null) { throw new InvalidOperationException($"Can't load asset key '{asset.AssetName}' because no patches currently apply. This should never happen."); } if (this.Verbose) { this.VerboseLog($"Patch \"{patch.LogName}\" loaded {asset.AssetName}."); } else { this.Monitor.Log($"{patch.ContentPack.Manifest.Name} loaded {asset.AssetName}.", LogLevel.Trace); } T data = patch.Load <T>(asset); patch.IsApplied = true; return(data); }