source: TFP-WebServer/MapRendering/src/ModApi.cs@ 503

Last change on this file since 503 was 503, checked in by alloc, 3 days ago

Compatibility fixes for 2.0

File size: 1.4 KB
Line 
1using JetBrains.Annotations;
2using Webserver;
3using Webserver.UrlHandlers;
4
5namespace MapRendering {
6 [UsedImplicitly]
7 public class ModApi : IModApi {
8 private const string mapTilesBaseUrl = "/map/";
9
10 public void InitMod (Mod _modInstance) {
11 ModEvents.GameStartDone.RegisterHandler (GameStartDone);
12
13 Web.ServerInitialized += _web => {
14 if (!MapRenderer.Enabled) {
15 return;
16 }
17
18 _web.RegisterPathHandler (mapTilesBaseUrl, new StaticHandler (
19 $"{GameIO.GetSaveGameDir ()}/map",
20 MapRenderer.GetTileCache (),
21 false,
22 "web.map")
23 );
24
25 _web.OpenApiHelpers.RegisterCustomSpec (GetType ().Assembly, "MapTileHandler", mapTilesBaseUrl);
26 };
27 }
28
29 private ModEvents.EModEventResult GameStartDone (ref ModEvents.SGameStartDoneData _data) {
30 if (!MapRenderer.Enabled) {
31 return ModEvents.EModEventResult.Continue;
32 }
33
34 ModEvents.GameShutdown.RegisterHandler (GameShutdown);
35 ModEvents.CalcChunkColorsDone.RegisterHandler (CalcChunkColorsDone);
36
37 return ModEvents.EModEventResult.Continue;
38 }
39
40 private ModEvents.EModEventResult GameShutdown (ref ModEvents.SGameShutdownData _data) {
41 MapRenderer.Shutdown ();
42
43 return ModEvents.EModEventResult.Continue;
44 }
45
46 private ModEvents.EModEventResult CalcChunkColorsDone (ref ModEvents.SCalcChunkColorsDoneData _data) {
47 MapRenderer.RenderSingleChunk (_data.Chunk);
48
49 return ModEvents.EModEventResult.Continue;
50 }
51 }
52}
Note: See TracBrowser for help on using the repository browser.