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