source: binary-improvements2/MapRendering/src/ModApi.cs@ 406

Last change on this file since 406 was 406, checked in by alloc, 21 months ago

Only run web server if game is running as server

File size: 768 bytes
Line 
1using JetBrains.Annotations;
2using Webserver;
3using Webserver.UrlHandlers;
4
5namespace MapRendering {
6 [UsedImplicitly]
7 public class ModApi : IModApi {
8 public void InitMod (Mod _modInstance) {
9 if (ConnectionManager.Instance.IsServer) {
10 ModEvents.GameShutdown.RegisterHandler (GameShutdown);
11 ModEvents.CalcChunkColorsDone.RegisterHandler (CalcChunkColorsDone);
12 }
13
14 Web.ServerInitialized += _web => {
15 _web.RegisterPathHandler ("/map/", new StaticHandler (
16 $"{GameIO.GetSaveGameDir ()}/map",
17 MapRenderer.GetTileCache (),
18 false,
19 "web.map")
20 );
21 };
22 }
23
24 private void GameShutdown () {
25 MapRenderer.Shutdown ();
26 }
27
28 private void CalcChunkColorsDone (Chunk _chunk) {
29 MapRenderer.RenderSingleChunk (_chunk);
30 }
31 }
32}
Note: See TracBrowser for help on using the repository browser.