-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapServiceCollectionExtensions.cs
More file actions
58 lines (52 loc) · 2.89 KB
/
Copy pathMapServiceCollectionExtensions.cs
File metadata and controls
58 lines (52 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using RustPlusBot.Abstractions.Map;
using RustPlusBot.Features.Map.Assets;
using RustPlusBot.Features.Map.Composing;
using RustPlusBot.Features.Map.Hosting;
using RustPlusBot.Features.Map.Posting;
using RustPlusBot.Features.Map.Rendering;
using RustPlusBot.Features.Map.RustMaps;
namespace RustPlusBot.Features.Map;
/// <summary>DI registration for the map-render feature.</summary>
public static class MapServiceCollectionExtensions
{
/// <summary>
/// Registers the renderer, base-map source chain, composer, pipeline bundle, and hosted service.
/// When a RustMaps API key is configured, also registers the credit-safe generation coordinator/driver
/// and the hosted service that drives generation and publishes <see cref="InfoMapReadyEvent"/> so the
/// reconciled #info map message (in Features.Workspace) shows the RustMaps render.
/// </summary>
/// <param name="services">The service collection to add to.</param>
/// <param name="configuration">The host configuration (reads Map:RustMaps:ApiKey).</param>
/// <returns>The same service collection, for chaining.</returns>
public static IServiceCollection AddMap(this IServiceCollection services, IConfiguration configuration)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configuration);
services.AddRustMapsAssets();
services.AddSingleton<MonumentIconSource>();
services.AddSingleton<MapRenderer>();
// RustMaps is NOT a base-map source (the #map render draws its own layers on the Rust+ tile).
// The client drives the #info static-map surface: credit-safe generation, no posting here.
var rustMapsKey = configuration["Map:RustMaps:ApiKey"];
if (!string.IsNullOrWhiteSpace(rustMapsKey))
{
services.AddRustMapsClientV4(o => o.ApiKey = rustMapsKey);
services.AddSingleton<RustMapsMapCoordinator>();
// IRustMapsMapCoordinator and IInfoMapReadModel resolve to the SAME singleton instance, so the
// driver's writes are visible to the Workspace renderer's reads.
services.AddSingleton<IRustMapsMapCoordinator>(sp => sp.GetRequiredService<RustMapsMapCoordinator>());
services.AddSingleton<IInfoMapReadModel>(sp => sp.GetRequiredService<RustMapsMapCoordinator>());
services.AddSingleton<RustMapsGenerationDriver>();
services.AddHostedService<InfoMapHostedService>();
}
services.AddSingleton<IBaseMapSource, RustPlusBaseMapSource>();
services.AddSingleton<BaseMapCache>();
services.AddSingleton<MapComposer>();
services.AddSingleton<IMapChannelPoster, DiscordMapChannelPoster>();
services.AddSingleton<MapPipeline>();
services.AddHostedService<MapHostedService>();
return services;
}
}